【发布时间】:2013-12-28 23:59:45
【问题描述】:
这是我在 spec/controllers/movies_controller_spec.rb 中的 rspec 代码的一部分:
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
我总是得到错误:
Failure/Error: click_link('Find Movies With Same Director')
Capybara::ElementNotFound:
Unable to find link "Find Movies With Same Director"
这是我在 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)
我也用相同的步骤运行黄瓜:访问相同的页面,然后单击链接,它通过了。但是在 rspec 中,我没有通过测试。
【问题讨论】:
标签: ruby-on-rails ruby rspec