@controller равен нулю при тестировании delete: уничтожить с помощью musta - PullRequest
1 голос
/ 23 июля 2010

Код ниже:

  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 ]

2 голосов
/ 28 января 2011

Вы не множественное имя для теста, но контроллером является ParticipationsController:

/ test / functions / Particip_controller_test.rb

Измените имя и имя класса на:

ParticipationsControllerTest

Participations_controller_test.rb

1 голос
/ 23 июля 2010

Вы должны обернуть 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
0 голосов
/ 29 января 2012

Контроллер существует? В моем случае контроллер не существовал, затем рельсы не загрузили контроллер и выкинули ошибку, которую вы получили.

...