Binding pry not being called in test environment
Asked Answered
H

2

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
Hoban answered 11/2, 2015 at 0:17 Comment(0)
M
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.

Manche answered 4/6, 2015 at 9:47 Comment(1)
It works (adding it to test_helper.rb). This answer should be marked as good.Counterproductive
D
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
Drusilla answered 14/7, 2022 at 4:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.