2

I want to testing my controller posts and when I running Rspec test, shell show me an error

 Failure/Error: Unable to find matching line from backtrace
 NoMethodError:
   undefined method `env' for nil:NilClass
 # /home/weare138/.rvm/gems/ruby-2.1.5/gems/devise-3.4.1/lib/devise/test_helpers.rb:24:in `setup_controller_for_warden'

this is my spec/requests/posts_spec.rb

require 'rails_helper'

describe "Posts" do
  describe "GET /posts" do
    it "works! (now write some real specs)" do
      user = FactoryGirl.create(:user, role: 'admin')
      sign_in user
    end
  end
end

UPD

rails_helper

ENV["RAILS_ENV"] ||= 'test'
require 'spec_helper'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
ActiveRecord::Migration.maintain_test_schema!

RSpec.configure do |config|
  config.fixture_path = "#{::Rails.root}/spec/fixtures"
  config.include Devise::TestHelpers, :type => :request
  config.use_transactional_fixtures = true
  config.infer_spec_type_from_file_location!
end

how fix?

vveare138
  • 347
  • 2
  • 8
  • 20

2 Answers2

1

Although the question is quite old, but here's the solution for request specs. Try using:

config.include Devise::Test::IntegrationHelpers, type: :request

instead of

config.include Devise::Test::ControllerHelpers, type: :request

zinovyev
  • 2,084
  • 1
  • 22
  • 32
0

It's an issue with Devise::TestHlepers, as it can be seen from stacktrace.

Duplicate of this question (also check related questions too).

Community
  • 1
  • 1
rastasheep
  • 10,416
  • 3
  • 27
  • 37