4

Aslak Hellesoyによる補助輪の投稿で、彼は、より最近のバージョンのキュウリからweb_steps.rbとpaths.rbを削除したと述べています。

web_steps.rbの代わりにCapybaraAPIを使用することは理解できますが、特定のページにいることをどのようにテストしますか?

これは私がpaths.rbでそれを行っていた方法です:

#admin_authentication.feature    
Then  I should be on the admin home page

# paths.rb
when /the admin home page/
  admin_root_path

# 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

二次的な質問として、これを行うべきでしょうか?

4

2 に答える 2

13

私は単にこれが好きです、それがあなたのために働くかどうか見てください:

assert page.current_path == admin_root_path
于 2013-03-08T13:10:56.653 に答える
8

通常、Cucumberステップでページパスをテストするべきではありません。きゅうりのシナリオは、ユーザーの視点から作成することを目的としています。ユーザーは通常、ページのコンテンツにのみ関心があるため、テストでは特定のURLやコントローラーではなくページのコンテンツを確認する必要があります。

次のように、開発者の観点からシナリオを作成する代わりに、次のようにします。

Scenario: Administrator should be on the admin home page
  When I log in as an administrator
  Then I should be on the admin home page

次のように、ユーザーの観点から記述します。

Scenario: Administrator should have super-user tools
  When I log in as an administrator
  Then I should see the disable-abusive-user button
于 2013-03-09T17:03:35.350 に答える