7

I'm currently writing specs for my Rails controller. I can't seem to get any puts statement or binding.pry, or binding.remote_pry working.

I am able to get the remote pry working in the development environment.

group :development, :test do
  gem 'rspec-rails', '~> 3.0'
  gem 'capybara'
  gem 'factory_girl_rails'
  gem 'daemons'
  gem 'pry-rails'
  gem 'pry-remote'
  gem 'binding_of_caller'
end

2 Answers 2

9

It seems that you need to require 'pry' somewhere in your test environment before invoking it. Your spec_helper.rb, test_helper.rb or similar is probably a good place.

Sign up to request clarification or add additional context in comments.

1 Comment

It works (adding it to test_helper.rb). This answer should be marked as good.
0

All credit to @Dan, here's where I placed require 'pry' (note that the first 9 lines are what comes with a fresh install of rspec):

# specs/rails_helper.rb
# This file is copied to spec/ when you run 'rails generate rspec:install'
require 'spec_helper'
ENV['RAILS_ENV'] ||= 'test'
require_relative '../config/environment'
# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'rspec/rails'
# Add additional requires below this line. Rails is not loaded until this point!
 
require 'pry' # <----- HERE

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.