NoMethodError undefined method sign_in rspec devise

892 Views Asked by At

Given that I am trying to write a simple rspec test whilst using devise I seem to keep NoMethodError: undefined method sign_in I have the following setup but cannot seem to get around this. I did come across another similar question to this Rails, Devise, Rspec: Undefined method 'sign_in' and I a certain I have config.infer_spec_type_from_file_location! enabled as shown in my snippet for my rails helper

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

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

I constantly keep getting:

Testing started at 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 '

1

There are 1 best solutions below

0
On BEST ANSWER

You're not showing it, so I'm guessing that it's not there. You need to require "rails_helper" in your controller_spec.