Как протестировать озабоченность контроллера в Rails 4
Каков наилучший способ справиться с тестированием проблем при использовании в контроллерах Rails 4? Скажи, у меня есть тривиальная проблемаCitations
.
module Citations
extend ActiveSupport::Concern
def citations ; end
end
Ожидаемое поведение при тестировании заключается в том, что любой контроллер, который включает в себя эту проблемуcitations
конечная точка.
class ConversationController < ActionController::Base
include Citations
end
Просто.
ConversationController.new.respond_to? :yelling #=> true
Но как правильно проверить это беспокойство в изоляции?
class CitationConcernController < ActionController::Base
include Citations
end
describe CitationConcernController, type: :controller do
it 'should add the citations endpoint' do
get :citations
expect(response).to be_successful
end
end
К сожалению, это не удается.
CitationConcernController
should add the citations endpoint (FAILED - 1)
Failures:
1) CitationConcernController should add the citations endpoint
Failure/Error: get :citations
ActionController::UrlGenerationError:
No route matches {:controller=>"citation_concern", :action=>"citations"}
# ./controller_concern_spec.rb:14:in `block (2 levels) in <top (required)>'
Это надуманный пример. В моем приложении я получаю другую ошибку.
RuntimeError:
@routes is nil: make sure you set it in your test's setup method.