代码之家  ›  专栏  ›  技术社区  ›  rtacconi

@测试删除时控制器为零:用Shoulda销毁

  •  1
  • rtacconi  · 技术社区  · 14 年前

    代码如下:

      context "should destroy participation" do
        setup do
          @p = Factory.create :participation
          delete :destroy, :id => @p.id.to_param
        end
    
        should_redirect_to(:controller => 'configuration', :action => 'edit')   
      end
    

    RuntimeError: @controller is nil: make sure you set it in your test's setup method.
        /test/functional/participation_controller_test.rb:30:in `__bind_1279893888_614853'
        /Applications/RubyMine 2.0.2.app/rb/testing/patch/testunit/test/unit/ui/testrunnermediator.rb:36:in `run_suite'
        /Applications/RubyMine 2.0.2.app/rb/testing/patch/testunit/test/unit/ui/teamcity/testrunner.rb:215:in `start_mediator'
        /Applications/RubyMine 2.0.2.app/rb/testing/patch/testunit/test/unit/ui/teamcity/testrunner.rb:191:in `start'
    
    3 回复  |  直到 14 年前
        1
  •  1
  •   Marcel Jackwerth    14 年前

    你得包起来 should_redirect_to 现在,它是在ruby加载类时执行的。

    context "should destroy participation" do
      setup do
        @p = Factory.create :participation
      end
    
      should "redirect ...." do
        delete :destroy, :id => @p.id.to_param
        should_redirect_to(:controller => 'configuration', :action => 'edit')
      end 
    end
    
        2
  •  2
  •   linuxonrails    13 年前

    /测试/功能/参与\控制器\测试.rb

    将类名和文件名更改为:

    参与控制测试

        3
  •  0
  •   Victor Pudeyev    12 年前

    控制器是否存在?在我的例子中,控制器不存在,然后rails没有加载任何控制器,并向我抛出您得到的错误。