0

我有这样一个功能的场景

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

通过这一步然后我应该在主页上我应该做什么?谢谢

4

1 回答 1

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 和字符串开头之间的空格无关紧要。)

于 2012-08-26T02:02:50.670 回答