0

我正在开发一个具有测试覆盖率的 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中,并且正确通过,没有问题。

这些是控制器文件:

谁能建议我如何解决这个问题?

4

1 回答 1

0

好吧,看起来新地方不是出于某种原因创建的(我的猜测是,它没有通过验证)。

尝试调试您的测试。我喜欢使用pry。只需添加到您的 gemfile gem '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 回答