2012-08-24 32 views
0

我有一個特點,像這樣的重定向黃瓜HOWTO以下

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

就我個人而言,我會在主頁路徑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之間的空格和字符串的開頭無關緊要。)