Here is part of my rspec code in spec/controllers/movies_controller_spec.rb:
it 'should call a controller method to receive the click on
"Find With Same Director", and grab the id of the subject' do
Movie.stub('find_similar_movies')
controller.should_receive('similar_movies').
with(hash_including :id => '3')
visit movie_path('3')
click_link('Find Movies With Same Director')
end
and I always get the error:
Failure/Error: click_link('Find Movies With Same Director')
Capybara::ElementNotFound:
Unable to find link "Find Movies With Same Director"
Here is part of my view in app/views/movies/show.html.haml:
%h2 Details about #{@movie.title}
%ul#details
%li
Rating:
= @movie.rating
%li
Director:
= @movie.director
%li
Released on:
= @movie.release_date.strftime("%B %d, %Y")
%h3 Description:
%p#description= @movie.description
= link_to 'Edit', edit_movie_path(@movie)
= button_to 'Delete', movie_path(@movie), :method => :delete, :confirm => 'Are you sure?'
= link_to 'Back to movie list', movies_path
= link_to 'Find Movies With Same Director', similar_movies_path(@movie)
I also run the cucumber with the same step: visit the same page, and click the link, it passed. But in the rspec, I failed the test.