views:

20

answers:

1

The code below:

  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

Gives me the error below, any idea why?

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'
A: 

You have to wrap should_redirect_to into a function, right now it is executed when the class is loaded by 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
Marcel J.
I tried but I still get the same error
rtacconi