简体   繁体   English

Stange Rspec测试失败

[英]Stange Rspec test failing

I'm developing a Rails 3.2 application, with test coverage, but for some reason some of my test are failing. 我正在开发一个涵盖测试范围的Rails 3.2应用程序,但是由于某些原因,我的某些测试失败了。 The same spec works for another model. 相同规格适用于其他模型。

Spec are run with Rspec, FactoryGirl, Shoulda-Matchers. Spec与Rspec,FactoryGirl和Shoulda-Matchers一起运行。

This is the failing spec: http://pastebin.com/8VWCAv79 这是失败的规格: http : //pastebin.com/8VWCAv79

The errors are: 错误是:

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

The quite same spec are present in another file, http://pastebin.com/r8HtAwSR , and are correctly passing, without problem. 另一个文件http://pastebin.com/r8HtAwSR中存在相同的规范,并且可以正确传递,没有问题。

These are the controller files: 这些是控制器文件:

Can anyone suggest me how to solve this problem? 谁能建议我如何解决这个问题?

Well it looks like the new place isn't created for some reason (my guess is, it doesn't pass validations). 好吧,似乎由于某种原因未创建新地点(我想是,它没有通过验证)。

Try to debug your tests. 尝试调试您的测试。 I like using pry . 我喜欢用 Just add to your gemfile gem 'pry' , run bundle and then you can set breakpoints in the execution. 只需将添加到您的gemfile gem'pry gem 'pry' ,运行bundle,然后您可以在执行中设置断点。

For example try this: 例如,尝试以下操作:

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

The execution will stop at the point, where you insert 'binding.pry' and you can check what is the last place in your terminal. 执行将在您插入“ binding.pry”的位置停止,您可以检查终端中的最后一个位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM