I am trying to test login functionality on my site using RSpec, Capybara and Factory Girl. I always get the following error in the terminal, but cannot find any solution. When I use save_and_open_page, I get a blank page. Hope someone knows what happened. Thank!
Here test output
Failure/Error: expect(page).to have_text("Login successful.")
Capybara::ElementNotFound:
Unable to find xpath "/html"
# ./spec/features/navigation_spec.rb:49:in `block (2 levels) in <top (required)>'
Here is my file sometest_spec.rbwith the corresponding lines:
require 'spec_helper'
include Warden::Test::Helpers
describe "User login" do
it "log in normal user" do
Warden.test_mode!
user = create(:normal_user)
user.confirmed_at = Time.now
user.save
login_as(user, scope: :user)
expect(page).to have_text("Login successful.")
logout(:user)
Warden.test_reset!
end
end
Here is my factory_girl.rbfile
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
end
And file factories.rb
FactoryGirl.define do
factory :normal_user, class: User do
firstname "John"
lastname "Doe"
email "test@user.com"
password "thepassword"
admin false
end
end
Linus source
share