我正在开发一个具有测试覆盖率的 Rails 3.2 应用程序,但由于某种原因,我的一些测试失败了。相同的规格适用于另一种型号。
Spec 与 Rspec、FactoryGirl、Shouda-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中,并且正确通过,没有问题。
这些是控制器文件:
- http://pastebin.com/C40Bti0m(规格不合格)
- http://pastebin.com/AHnn3Nh0(工作规范)
谁能建议我如何解决这个问题?