Я пытаюсь использовать rspec для проверки фильтра, который есть в моем ApplicationController.
В spec / controllers / application_controller_spec.rb
у меня есть:
require 'spec_helper'
describe ApplicationController do
it 'removes the flash after xhr requests' do
controller.stub!(:ajaxaction).and_return(flash[:notice]='FLASHNOTICE')
controller.stub!(:regularaction).and_return()
xhr :get, :ajaxaction
flash[:notice].should == 'FLASHNOTICE'
get :regularaction
flash[:notice].should be_nil
end
end
Мое намерение состояло в том, чтобы тест имитировал действие ajax, которое устанавливает флэш-память, а затем проверял при следующем запросе, что флэш-память была очищена.
Я получаю сообщение об ошибке маршрутизации:
Failure/Error: xhr :get, :ajaxaction
ActionController::RoutingError:
No route matches {:controller=>"application", :action=>"ajaxaction"}
Однако я ожидаю, что есть несколько вещей не так с тем, как я пытаюсь это проверить.
Для справки, фильтр называется в ApplicationController
как:
after_filter :no_xhr_flashes
def no_xhr_flashes
flash.discard if request.xhr?
end
Как я могу создать фиктивные методы на ApplicationController
, чтобы протестировать широкий фильтр приложения?