I am following Railstutorial (chapter 9) The test for" delete links " is passed for first time but from the next time it starts giving some kind of errors like:
Failures:
1) User pages index delete links as an admin user
Failure/Error: sign_in admin
Capybara::ElementNotFound:
Unable to find field "Email"
# ./spec/support/utilities.rb:20:in `sign_in'
# ./spec/requests/user_pages_spec.rb:38:in `block (5 levels) in <top (required)>'
2) User pages index delete links as an admin user
Failure/Error: sign_in admin
Capybara::ElementNotFound:
Unable to find field "Email"
# ./spec/support/utilities.rb:20:in `sign_in'
# ./spec/requests/user_pages_spec.rb:38:in `block (5 levels) in <top (required)>'
3) User pages index delete links as an admin user should be able to delete another user
Failure/Error: sign_in admin
Capybara::ElementNotFound:
Unable to find field "Email"
# ./spec/support/utilities.rb:20:in `sign_in'
# ./spec/requests/user_pages_spec.rb:38:in `block (5 levels) in <top (required)>'
Finished in 0.81336 seconds
4 examples, 3 failures
Failed examples:
rspec ./spec/requests/user_pages_spec.rb:48 # User pages index delete links as an admin user
rspec ./spec/requests/user_pages_spec.rb:42 # User pages index delete links as an admin user
rspec ./spec/requests/user_pages_spec.rb:43 # User pages index delete links as an admin user should be able to delete another user
Randomized with seed 11884
Here is the content of utilities.rb file
include ApplicationHelper
def full_title(page_title)
base_title = "Welcome to Family & Friends"
if page_title.empty?
base_title
else
" #{base_title} | #{page_title} "
end
end
def sign_in(user, options={})
if options[:no_capybara]
# Sign in when not using Capybara.
remember_token = User.new_remember_token
cookies[:remember_token] = remember_token
user.update_attribute(:remember_token, User.encrypt(remember_token))
else
visit signin_path
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_button "Sign in"
end
end
Part of user_pages_spec.rb file where the error is indicating
describe "delete links" do
it { should_not have_link('delete') }
describe "as an admin user" do
let(:admin) { FactoryGirl.create(:admin) }
before do
sign_in admin
visit users_path
end
it { should have_link('delete', href: user_path(User.first)) }
it "should be able to delete another user" do
expect do
click_link('delete', match: :first)
end.to change(User, :count).by(-1)
end
it { should_not have_link('delete', href: user_path(admin)) }
end
end
end
sessions_helper.rb file where definition of sign_in is present
module SessionsHelper
def sign_in(user)
remember_token = User.new_remember_token
cookies.permanent[:remember_token] = remember_token
user.update_attribute(:remember_token, User.encrypt(remember_token))
self.current_user = user
end
def signed_in?
!current_user.nil?
end
def current_user=(user)
@current_user = user
end
def current_user
remember_token = User.encrypt(cookies[:remember_token])
@current_user ||= User.find_by(remember_token: remember_token)
end
def current_user?(user)
user == current_user
end
def sign_out
self.current_user = nil
cookies.delete(:remember_token)
end
def redirect_back_or(default)
redirect_to(session[:return_to] || default)
session.delete(:return_to)
end
def store_location
session[:return_to] = request.url if request.get?
end
end
I have even tried with fill_in "email_id" as suggested in similar posts but not worked in this case
thanks!!
Here is the Content of new.html.erb which html is rendering for signin
<% provide(:title, "Sign in") %>
<h2>Sign in</h2>
<div class="row">
<div class="span6 offset3">
<%= form_for(:session, url: sessions_path) do |f| %>
<%= f.label :email %>
<%= f.text_field :email %>
<%= f.label :password %>
<%= f.password_field :password %>
<%= f.submit "Sign in", class: "btn btn-large btn-primary" %>
<% end %>
<p>New user? <%= link_to "Sign up now!", signup_path %></p>
</div>
</div>