Module: Shoulda::Matchers::ActionController
- Included in:
- ActionController::TestCase, ActionController::TestCase
- Defined in:
- lib/shoulda/matchers/action_controller.rb,
lib/shoulda/matchers/action_controller/route_matcher.rb,
lib/shoulda/matchers/action_controller/set_session_matcher.rb,
lib/shoulda/matchers/action_controller/redirect_to_matcher.rb,
lib/shoulda/matchers/action_controller/respond_with_matcher.rb,
lib/shoulda/matchers/action_controller/filter_param_matcher.rb,
lib/shoulda/matchers/action_controller/set_the_flash_matcher.rb,
lib/shoulda/matchers/action_controller/render_template_matcher.rb,
lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb
Overview
:nodoc:
Defined Under Namespace
Classes: FilterParamMatcher, RedirectToMatcher, RenderTemplateMatcher, RenderWithLayoutMatcher, RespondWithMatcher, RouteMatcher, SetSessionMatcher, SetTheFlashMatcher
Instance Method Summary (collapse)
-
- (Object) filter_param(key)
Ensures that filter_parameter_logging is set for the specified key.
-
- (Object) redirect_to(url_or_description, &block)
Ensures a controller redirected to the given url.
-
- (Object) render_template(options = {}, message = nil)
Ensures a controller rendered the given template.
-
- (Object) render_with_layout(expected_layout = nil)
Ensures that the controller rendered with the given layout.
-
- (Object) respond_with(status)
Ensures a controller responded with expected 'response' status code.
-
- (Object) route(method, path)
Ensures that requesting path using method routes to options.
-
- (Object) set_session(key)
Ensures that a session key was set to the expected value.
-
- (Object) set_the_flash
Ensures that the flash contains the given value.
Instance Method Details
- (Object) filter_param(key)
Ensures that filter_parameter_logging is set for the specified key.
Example:
it { should filter_param(:password) }
9 10 11 |
# File 'lib/shoulda/matchers/action_controller/filter_param_matcher.rb', line 9 def filter_param(key) FilterParamMatcher.new(key) end |
- (Object) redirect_to(url_or_description, &block)
Ensures a controller redirected to the given url.
Example:
it { should redirect_to('http://somewhere.com') }
it { should redirect_to(users_path) }
10 11 12 |
# File 'lib/shoulda/matchers/action_controller/redirect_to_matcher.rb', line 10 def redirect_to(url_or_description, &block) RedirectToMatcher.new(url_or_description, self, &block) end |
- (Object) render_template(options = {}, message = nil)
Ensures a controller rendered the given template.
Example:
it { should render_template(:show) }
assert that the "_customer" partial was rendered
it { should render_template(:partial => '_customer') }
assert that the "_customer" partial was rendered twice
it { should render_template(:partial => '_customer', :count => 2) }
assert that no partials were rendered
it { should render_template(:partial => false) }
18 19 20 |
# File 'lib/shoulda/matchers/action_controller/render_template_matcher.rb', line 18 def render_template( = {}, = nil) RenderTemplateMatcher.new(, , self) end |
- (Object) render_with_layout(expected_layout = nil)
Ensures that the controller rendered with the given layout.
Example:
it { should render_with_layout }
it { should render_with_layout(:special) }
it { should_not render_with_layout }
12 13 14 |
# File 'lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb', line 12 def render_with_layout(expected_layout = nil) RenderWithLayoutMatcher.new(expected_layout).in_context(self) end |
- (Object) respond_with(status)
Ensures a controller responded with expected 'response' status code.
You can pass an explicit status number like 200, 301, 404, 500 or its symbolic equivalent :success, :redirect, :missing, :error. See ActionController::StatusCodes for a full list.
Example:
it { should respond_with(:success) }
it { should respond_with(:redirect) }
it { should respond_with(:missing) }
it { should respond_with(:error) }
it { should respond_with(501) }
18 19 20 |
# File 'lib/shoulda/matchers/action_controller/respond_with_matcher.rb', line 18 def respond_with(status) RespondWithMatcher.new(status) end |
- (Object) route(method, path)
Ensures that requesting path using method routes to options.
If you don't specify a controller, it will use the controller from the example group.
to_param is called on the options given.
Examples:
it { should route(:get, '/posts').
to(:controller => :posts, :action => :index) }
it { should route(:get, '/posts/new').to(:action => :new) }
it { should route(:post, '/posts').to(:action => :create) }
it { should route(:get, '/posts/1').to(:action => :show, :id => 1) }
it { should route(:get, '/posts/1/edit').to(:action => :edit, :id => 1) }
it { should route(:put, '/posts/1').to(:action => :update, :id => 1) }
it { should route(:delete, '/posts/1').
to(:action => :destroy, :id => 1) }
it { should route(:get, '/users/1/posts/1').
to(:action => :show, :id => 1, :user_id => 1) }
25 26 27 |
# File 'lib/shoulda/matchers/action_controller/route_matcher.rb', line 25 def route(method, path) RouteMatcher.new(method, path, self) end |
- (Object) set_session(key)
Ensures that a session key was set to the expected value.
Example:
it { should set_session(:message) }
it { should set_session(:user_id).to(@user.id) }
it { should_not set_session(:user_id) }
12 13 14 |
# File 'lib/shoulda/matchers/action_controller/set_session_matcher.rb', line 12 def set_session(key) SetSessionMatcher.new(key) end |
- (Object) set_the_flash
Ensures that the flash contains the given value. Can be a String, a Regexp, or nil (indicating that the flash should not be set).
Example:
it { should set_the_flash }
it { should set_the_flash.to('Thank you for placing this order.') }
it { should set_the_flash.to(/created/i) }
it { should set_the_flash[:alert].to('Password does not match') }
it { should set_the_flash.to(/logged in/i).now }
it { should_not set_the_flash }
16 17 18 |
# File 'lib/shoulda/matchers/action_controller/set_the_flash_matcher.rb', line 16 def set_the_flash SetTheFlashMatcher.new end |