Reputation: 1956
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!!
Upvotes: 0
Views: 2225
Reputation: 1177
fill_in 'Password, with: user.password
not like that. You should use this line,
fill_in 'Password', with: user.password
Upvotes: 0
Reputation: 6808
More than likely, your login is failing for one reason or another.
Change your test to look like this:
it "should show me my first name" do
save_and_open_page
should have_selector('p', text: user.first_name)
end
That will open your browser and show you the page as the test browser currently sees it. (You may need to add the launchy
gem to your Gemfile.)
There are a few other diagnostics that would help, for instance, adding a test or a puts
that checks what page you landed on, such as:
it "redirects to the home page after log in" do
current_path.should == root_path
end
Upvotes: 2