2015-09-13 3 views
1

Я поставил код в спецификации/поддержка/request_helpers.rbнеинициализированные постоянные запросы (NameError)

module Requests 
    module JsonHelpers 
    def json 
     @json ||= JSON.parse(response.body) 
    end 
    end 
end 

Затем я добавил строку конфигурации спецификации/rails_helper.rb, чтобы получить доступ к этому коду из моей спецификации ,

ENV['RAILS_ENV'] ||= 'test' 
require File.expand_path('../../config/environment', __FILE__) 

abort("The Rails environment is running in production mode!") if Rails.env.production? 
require 'spec_helper' 
require 'rspec/rails' 

ActiveRecord::Migration.maintain_test_schema! 

RSpec.configure do |config| 

    config.fixture_path = "#{::Rails.root}/spec/fixtures" 
    config.use_transactional_fixtures = true 
    config.infer_spec_type_from_file_location! 

    config.include Requests::JsonHelpers, :type => :controller 
end 

Так что, когда я запускаю мои спецификации от спецификации/контроллера/tasks_controller_spec.rb я получаю следующее сообщение об ошибке.

/spec/rails_helper.rb:16:in `block in <top (required)>': uninitialized constant Requests (NameError) 

Как это решить?

У меня есть require 'rails_helper' наверху.

ответ

5

Вы уже ввели require свою папку поддержки? Добавить в свой spec_helper.rb:

ENV['RAILS_ENV'] ||= 'test' 
require File.expand_path('../../config/environment', __FILE__) 

abort("The Rails environment is running in production mode!") if Rails.env.production? 
require 'spec_helper' 
require 'rspec/rails' 

# with many helpers 
Dir[File.dirname(__FILE__) + "/support/*.rb"].each {|f| require f } 
# or only one 
# require 'support/request_helpers' 

ActiveRecord::Migration.maintain_test_schema! 

RSpec.configure do |config| 
# some code here 

About spec/support

+0

Спасибо, ЗЕЛЕНЫЙ;) –

Смежные вопросы