I upgraded rspec from version 2 to 3. After that I faced that problem:
Failures:
1) AlbumsController GET #edit
Failure/Error: sign_in_and_switch_schema @user
NoMethodError:
undefined method `env' for nil:NilClass
# ./spec/support/auth_helpers.rb:10:in `sign_in_and_switch_schema'
# ./spec/controllers/albums_controller_spec.rb:12:in `block (2 levels) in <top (required)>'
spec_helper.rb contains:
RSpec.configure do |config|
# most omitted
config.include Warden::Test::Helpers
config.include Devise::TestHelpers, type: :controller
end
albums_controller_spec.rb:
describe AlbumsController do
let(:album) { create(:album) }
before(:all) do
@user = create :user
end
before(:each) do
sign_in_and_switch_schema @user
end
after(:all) do
destroy_users_schema @user
destroy_user @user
end
# describe's part omitted
end
auth_helpers.rb part on which error occurred :
def sign_in_and_switch_schema(user)
# binding.pry
@request.env["devise.mapping"] = Devise.mappings[:user] # <- error line
sign_in :user, user
Apartment::Tenant.switch(user.username)
end
I was looking for another simmilar Q&A but found nothing helped. Let me know if I should include something more. Thanks in advance.
binding.pry
to the auth_helpers.rb. It shows clearly that@request
isnil
. I have no clue what else I can do with it but I can check if you tell me. – Allina