I have a very simple RSpec Capybara have_selector() that doesn’t seem to be working and I can’t figure out why… but probably something simple.
Here’s the RSpec request test:
describe 'with valid information'
let(:user) { FactoryGirl.create(:user) }
before do
fill_in 'Email', with: user.email
fill_in 'Password, with: user.password
click_button 'Login'
end
it { should have_selector('p', text: user.first_name) }
...
end
In the new.html.erb for the session, I just have something like this:
<% if logged_in? %>
<p><%= current_user.first_name %></p>
<% else %>
<%= form_for(:session, url: sessions_path) do |f| %>
...
<% end %>
The login form session#new works perfectly in the browser. I can login just fine and am able to view the first name in a p tag. The problem seems to be the capybara part, because the other it test checking for the h1 tag on the page (which is present regardless of being logged in) works fine.
Does anyone know what the problem could be?
Thanks in advance for any help!!
More than likely, your login is failing for one reason or another.
Change your test to look like this:
That will open your browser and show you the page as the test browser currently sees it. (You may need to add the
launchygem to your Gemfile.)There are a few other diagnostics that would help, for instance, adding a test or a
putsthat checks what page you landed on, such as: