Module: Riot::ActionController::ContextMacros
- Defined in:
- lib/riot/action_controller/context_macros.rb
Instance Method Summary collapse
-
#asserts_controller ⇒ Object
Creates a shortcut assertion that is to be used with the assertion macros for ActionController.
-
#controlling(controller_name) ⇒ Object
Sets up a context (and possibly child contexts) for testing a controller.
Instance Method Details
#asserts_controller ⇒ Object
Creates a shortcut assertion that is to be used with the assertion macros for ActionController.
context "the FoosController" do
controlling :foos
setup { get :index }
asserts_controller.response_status(:found)
asserts_controller.redirected_to { new_foo_path }
end
Works the same as if you wrote the following assertions:
asserts("controller") { controller }.response_status(:found)
asserts("controller") { controller }.redirected_to { new_foo_path }
39 40 41 |
# File 'lib/riot/action_controller/context_macros.rb', line 39 def asserts_controller asserts("controller") { controller } end |
#controlling(controller_name) ⇒ Object
Sets up a context (and possibly child contexts) for testing a controller. Right now, it just takes a symbol. Should change to allow you to pass in the class directly. You should put this at or near the top of your context definition.
context "the FooBarsController" do
controlling :foo_bars
setup { get :index }
end
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/riot/action_controller/context_macros.rb', line 13 def controlling(controller_name) controller_class = "#{controller_name.to_s.camelize}Controller".constantize setup do controller_class.instance_eval { include ::ActionController::TestCase::RaiseActionExceptions } @request = ::ActionController::TestRequest.new @response = ::ActionController::TestResponse.new @controller = controller_class.new @controller.params = {} @controller.request = @request end end |