0

Edx.org の SaaS の HW4 で作業しています。シナリオ 2 と 3 で cucumber の実行に問題があります。Web アプリケーションを試してみると、これら 2 つのシナリオで問題なく動作します。しかし、キュウリを実行すると、次の出力が得られます。

Scenario: find movie with same director                       #        features/search_movies_director.feature:22
Deprecated: please use #source_tags instead.
Given I am on the details page for "Star Wars"              # features/step_definitions/web_steps.rb:44
When I follow "Find Movies With Same Director"              # features/step_definitions/web_steps.rb:56
Then I should be on the Similar Movies page for "Star Wars" # features/step_definitions/web_steps.rb:230
  No route matches {:action=>"director", :controller=>"movies"} (ActionController::RoutingError)
  ./features/support/paths.rb:20:in `path_to'
  ./features/step_definitions/web_steps.rb:233:in `/^(?:|I )should be on (.+)$/'
  features/search_movies_director.feature:25:in `Then I should be on the Similar Movies page for "Star Wars"'
And I should see "THX-1138"                                 # features/step_definitions/web_steps.rb:105
But I should not see "Blade Runner"                         # features/step_definitions/web_steps.rb:123

Scenario: can't find similar movies if we don't know director (sad path) # features/search_movies_director.feature:29
Deprecated: please use #source_tags instead.
Given I am on the details page for "Alien"                             # features/step_definitions/web_steps.rb:44
Then I should not see "Ridley Scott"                                   # features/step_definitions/web_steps.rb:123
When I follow "Find Movies With Same Director"                         # features/step_definitions/web_steps.rb:56
Then I should be on the home page                                      # features/step_definitions/web_steps.rb:230
  expected: "/movies"
       got: "/movies/3/director" (using ==) (RSpec::Expectations::ExpectationNotMetError)
  ./features/step_definitions/web_steps.rb:233:in `/^(?:|I )should be on (.+)$/'
  features/search_movies_director.feature:33:in `Then I should be on the home page'
And I should see "'Alien' has no director info"                        # features/step_definitions/web_steps.rb:105

どちらの場合も、このシナリオを手動で実行すると、動作は正しくなります。何が問題ですか?

ありがとう

「rake routes」を実行すると、次のようになります。

director_movie GET    /movies/:id/director(.:format) {:action=>"director", :controller=>"movies"}
    movies GET    /movies(.:format)              {:action=>"index", :controller=>"movies"}
           POST   /movies(.:format)              {:action=>"create", :controller=>"movies"}
 new_movie GET    /movies/new(.:format)          {:action=>"new", :controller=>"movies"}
edit_movie GET    /movies/:id/edit(.:format)     {:action=>"edit", :controller=>"movies"}
     movie GET    /movies/:id(.:format)          {:action=>"show", :controller=>"movies"}
           PUT    /movies/:id(.:format)          {:action=>"update", :controller=>"movies"}
           DELETE /movies/:id(.:format)          {:action=>"destroy", :controller=>"movies"}

ここで、「director_movie GET /movies/:id/director(.:format) {:action=>"director", :controller=>"movies"}」というルートが見えるので、なぜ最初のシナリオ失敗。

2 つ目では、"/movies" を期待し、"/movies/3/director" を取得しました。コントローラーのコードは次のとおりです。

def director
 mov = Movie.find(params[:id])
 dir = mov.director
 if (dir == nil)
   flash[:notice] = "'#{mov.title}' has no director info"
   redirect_to movies_path
 else
   @movies = Movie.find_all_by_director(dir)
 end
end

しかし、同じ手順を手動でシミュレートすると、フラッシュ メッセージが表示され、"/movies" にリダイレクトされます...なぜ cucumber は同じにならないのですか?

私の英語でごめんなさい...そしてありがとう!

4

1 に答える 1

1

問題は、ディレクターも空になる可能性があることを確認していないことです。その場合、ホームページへのリダイレクトは行われず、シナリオは失敗します。この状況を修正するには、nil または empty をチェックする必要があります。

 if (dir.nil? || dir.empty?)
   flash[:notice] = "'#{mov.title}' has no director info"
   redirect_to movies_path
 else
   @movies = Movie.find_all_by_director(dir)
 end
于 2013-02-16T14:33:55.367 に答える