Rails 2.3.8 (тестирование с Mocha)
В моем файле rout.rb:
map.root (: controller => 'application',: action => 'render_404_not_found')
В моих функциональных тестах я хочу убедиться, что запрос на '/' будет обработан должным образом:
@controller.stubs(:render_404_not_found).returns(666)
%w( HEAD GET POST PUT DELETE ).each do |method|
@request = ActionController::TestRequest.new
@request.env['REQUEST_URI'] = uri
@request.path = uri
process(uri, nil, nil, nil, method)
assert_response(666,
"Request for '#{method} #{uri}'" +
'should have 404ed (or 666ed)')
end
Я понимаю, что заглушка 'return' неверна, но у меня нетеще не пришло:
test_bogus_uri_path(EdgeConditionsTest):
ActionController::RoutingError: /usr/lib/ruby/gems/1.8/gems/ \
actionpack-2.3.8/lib /action_controller/routing/route_set.rb:420: \
in `generate': No route matches {:controller=>"application", :action=>"/"}
Итак, как мне проверить, что этот маршрут работает и вызывает # render_404_not_found?
Спасибо!
Окончательное решение на основе превосходных предложений @ noodl:
uri = '/'
%w( HEAD GET POST PUT DELETE ).each do |method|
assert_routing({
:method => method.downcase,
:path => uri
},
{
:controller => 'application',
:action => 'render_404_not_found'
},
{},
{},
"'#{method} #{uri}': " +
'Root route #failed')
end
#
# Now, ensure that our function is actually getting called..
#
%w( HEAD GET POST PUT DELETE ).each do |method|
send(method.downcase.to_sym, uri)
assert_response(404,
"Request for '#{method} #{uri}'" +
'should have 404ed')
assert_template('404.html')
end