2015-06-11 147 views
0

鑑於我正在嘗試編寫一個簡單的rspec測試,同時使用設計我似乎保持NoMethodError:未定義的方法sign_in我有以下設置,但似乎無法繞過此。我也碰到過另一個類似的問題,這Rails, Devise, Rspec: Undefined method 'sign_in',我一定我已經config.infer_spec_type_from_file_location!啓用如圖我摘錄了我的軌道幫手NoMethodError undefined method sign_in rspec devise

規格助手

RSpec.configure do |config| 

    config.expect_with :rspec do |expectations| 

    expectations.include_chain_clauses_in_custom_matcher_descriptions = true 
    end 

    # rspec-mocks config goes here. You can use an alternate test double 
    # library (such as bogus or mocha) by changing the `mock_with` option here. 
    config.mock_with :rspec do |mocks| 
    # Prevents you from mocking or stubbing a method that does not exist on 
    # a real object. This is generally recommended, and will default to 
    # `true` in RSpec 4. 
    mocks.verify_partial_doubles = true 
    end 
end 

軌幫手

ENV['RAILS_ENV'] ||= 'test' 
require 'spec_helper' 
require File.expand_path('../../config/environment', __FILE__) 
require 'rspec/rails' 
# 
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f } 

# Checks for pending migrations before tests are run. 
# If you are not using ActiveRecord, you can remove this line. 
ActiveRecord::Migration.maintain_test_schema! 

RSpec.configure do |config| 
    config.fixture_path = "#{::Rails.root}/spec/fixtures" 
    config.use_transactional_fixtures = false 
    config.infer_spec_type_from_file_location! 
end 

support/devise

RSpec.configure do |config| 
    config.include Devise::TestHelpers, :type => :controllers 
end 

controller_spec

describe UsersController do 
    before :each do 
    @user = FactoryGirl.create(:user, :admin) 
    sign_in @user 
    end 

    context "HTML" do 

    describe "GET index" do 
     it "assigns all users as @users" do 
     user = @user 
     get :index, {} 
     assigns(:user).should eq([user]) 
     end 
    end 
    end 


end 

我不斷不斷收到:

測試在10:15 AM開始......

NoMethodError: undefined method `sign_in' for

/home/trcdev/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-4.2.1/lib/action_dispatch/testing/assertions/routing.rb:171:in method_missing' ./spec/controllers/users_controller_spec.rb:4:in block (2 levels) in '

回答

0

你沒有顯示,所以我猜測它不在那裏。您需要在您的controller_spec中登錄require "rails_helper"

相關問題