控制器规范未按预期递增计数

时间:2015-04-21 13:05:31

标签: ruby-on-rails rspec

我正在尝试使用复选框更新索引视图。逻辑按预期工作但我的控制器规格失败,我不明白为什么。我想知道我的语法是否有问题。增量正在使用我的功能测试,但不适用于控制器规范。测试的相关部分如下:

 describe "PUT complete" do 
    it "it archives a diagnostic info report" do 
      diagnostic = FG.create(:diagnostic_info)
      puts DiagnosticInfo.all.size
      expect {
       put :complete, :diagnostic_ids => [diagnostic.id]
       }.to change(DiagnosticInfo.all, :size).by(-1)
      response.should redirect_to(admin_diagnostics_path)
    end
  end

我收到的失败测试是:

  1) Admin::DiagnosticsController PUT complete it archives a diagnostic info report
     Failure/Error: put :complete, :diagnostic_ids => [diagnostic.ids]
     NoMethodError:
       undefined method `ids' for #<DiagnosticInfo:0x0000000827c678>
     # ./spec/controllers/admin/diagnostics_controller_spec.rb:53:in `block (4 levels) in <top (required)>'
     # ./spec/controllers/admin/diagnostics_controller_spec.rb:52:in `block (3 levels) in <top (required)>'
     # -e:1:in `<main>'

1 个答案:

答案 0 :(得分:0)

我将测试修改为以下内容,因此能够使测试工作。

  describe "PUT complete" do 
    it "it archives a diagnostic info report" do 
      diagnostic = FG.create(:diagnostic_info)
      expect {
      put :complete, :diagnostic_ids => [diagnostic.id]
       }.to change(DiagnosticInfo.all, :count).by(-1)
      response.should redirect_to(admin_diagnostics_path)
    end
  end