我有一个类似这样的功能的场景
Scenario: can't find similar movies if we don't know director (sad path)
Given I am on the details page for "Alien"
Then I should not see "Ridley Scott"
When I follow "Find Movies With Same Director"
Then I should be on the home page
Then I should see "'Alien' has no director info"
我有'查找具有相同导演的电影'的控制器操作,名为find_by_same_director,并且还有一个具有相同名称的视图模板,但是当电影没有导演时类似的电影应该采用主页,我这样在控制器动作中做.. ..
def find_by_same_director
m = Movie.find params[:id]
@similar_movies = m.similar_movies
if @similar_movies.count == 0
flash[:notice] = "#{m.title} has no director info"
render :index
end
end
在paths.rb中,path_to方法有“主页”的情况,因此
when /^the home\s?page$/
movies_path
要通过步骤然后我应该在主页上我该怎么办?感谢
答案 0 :(得分:0)
就个人而言,我会在主页路径RE中删除'^'和'$',因为它们没有锚定在那里。
“然后我应该在主页上”应该在web_steps.rb中找到并找到那里的步骤。特别是步骤:
Then /^(?:|I )should be on (.+)$/ do |page_name|
current_path = URI.parse(current_url).path
if current_path.respond_to? :should
current_path.should == path_to(page_name)
else
assert_equal path_to(page_name), current_path
end
end
此外,您必须小心字符串中或后面的空格。 (Given / When / Then和字符串开头之间的空格无关紧要。)