0

Rails 3.2 アプリケーションをテスト カバレッジで開発していますが、何らかの理由でテストの一部が失敗しています。別のモデルでも同じ仕様が機能します。

Spec は Rspec、FactoryGirl、Shoulda-Matchers で実行されます。

これは失敗した仕様です: http://pastebin.com/8VWCAv79

エラーは次のとおりです。

Failures:

  1) PlacesController POST create when user is logged in with valid params redirects to the created place
     Failure/Error: response.should redirect_to(Place.last)
       Expected response to be a <:redirect>, but was <200>
     # ./spec/controllers/places_controller_spec.rb:109:in `block (5 levels) in <top (required)>'

  2) PlacesController POST create when user is logged in with valid params assigns a newly created place as @place
     Failure/Error: assigns(:place).should be_persisted
       expected persisted? to return true, got false
     # ./spec/controllers/places_controller_spec.rb:104:in `block (5 levels) in <top (required)>'

  3) PlacesController POST create when user is logged in with valid params creates a new Place
     Failure/Error: expect {
       count should have been changed by 1, but was changed by 0
     # ./spec/controllers/places_controller_spec.rb:96:in `block (5 levels) in <top (required)>'

Finished in 4.63 seconds
21 examples, 3 failures

Failed examples:

rspec ./spec/controllers/places_controller_spec.rb:107 # PlacesController POST create when user is logged in with valid params redirects to the created place
rspec ./spec/controllers/places_controller_spec.rb:101 # PlacesController POST create when user is logged in with valid params assigns a newly created place as @place
rspec ./spec/controllers/places_controller_spec.rb:95 # PlacesController POST create when user is logged in with valid params creates a new Place

まったく同じ仕様が別のファイルhttp://pastebin.com/r8HtAwSRに存在し、問題なく正しく通過しています。

コントローラ ファイルは次のとおりです。

誰でもこの問題を解決する方法を教えてもらえますか?

4

1 に答える 1

0

なんらかの理由で新しい場所が作成されていないようです (私の推測では、検証に合格していません)。

テストをデバッグしてみてください。私はpryを使うのが好きです。gemfilegem 'pry'に追加して bundle を実行するだけで、実行時にブレークポイントを設定できます。

たとえば、これを試してください:

it "redirects to the created place" do
  post :create, {:place => valid_attributes}
  binding.pry
  response.should redirect_to(Place.last)
end

「binding.pry」を挿入した時点で実行が停止し、端末の最後の場所を確認できます。

于 2013-05-22T20:36:36.170 に答える