NoMethodError未定义方法sign_in rspec devise

时间:2015-06-11 14:15:58

标签: ruby-on-rails rspec devise

鉴于我正在尝试使用设计编写一个简单的rspec测试,我似乎保留了NoMethodError:未定义的方法sign_in我有以下设置,但似乎无法解决这个问题。我确实遇到了另一个与Rails, Devise, Rspec: Undefined method 'sign_in'类似的问题,我确定已启用config.infer_spec_type_from_file_location!,如我的铁路助手代码段所示

Spec Helper

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

rails helper

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

支持/设计

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开始......

  

NoMethodError:

的未定义方法`sign_in'      

     

/home/trcdev/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-4.2.1/lib/action_dispatch/testing/assertions/routing.rb:171:in   '{/ p>中method_missing' ./spec/controllers/users_controller_spec.rb:4:in 阻止(2级)

1 个答案:

答案 0 :(得分:1)

你没有展示它,所以我猜它不在那里。您需要require "rails_helper"中的controller_spec