- rails (5.1.4)
- rspec-rails (3.7.2)
- capybara (2.16.1)
- devise (4.3.0)
I'm trying to create a RSpec Rails 3.7 System spec as in https://relishapp.com/rspec/rspec-rails/v/3-7/docs/system-specs/system-spec .
Additionally I want to apply the Devise authorization. I followed the instruction https://github.com/plataformatec/devise/wiki/How-To:-Test-with-Capybara
But I guess it's kind of a defective implementation. I don't get the current_user
method (which is nil
).
Here my simple spec:
require 'rails_helper'
RSpec.describe "testing system", type: :system do
it "tests the spec" do
admin = create(:admin) # user-admin
login_as(admin, :scope => :admin)
visit root_path
click_link 'Home'
save_and_open_page
end
end
Since the code on my site depends heavily on the current_user
value, I don't get a properly formed saved page (it looks like a user did not log in).
What should I do? Should I try to simply manually (somehow?) assign a value to current_user
? Or maybe the https://github.com/plataformatec/devise/wiki/How-To:-Test-with-Capybara strategy is mainly defective and should be substituted to something more full-fledged technology?
I already tried to make
current_user = admin
in my code - but with no result.