代码之家  ›  专栏  ›  技术社区  ›  Sherwyn Goh

测试环境中未调用绑定撬

  •  7
  • Sherwyn Goh  · 技术社区  · 10 年前

    我目前正在为我的Rails控制器编写规范。我似乎无法获得任何put语句、binding.prike或binding.remote_pry。

    我能够在开发环境中使用远程撬。

    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 回复  |  直到 10 年前
        1
  •  9
  •   Dan    9 年前

    看来你需要 require 'pry' 在调用测试环境之前 spec_helper.rb , test_helper.rb 或类似的可能是一个好地方。

        2
  •  0
  •   stevec Zxeenu    2 年前

    所有贷方至 @Dan ,这是我放的地方 require 'pry' (注意,前9行是新安装的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
    
    推荐文章