module Shoulda::ActionController::Matchers
def assign_to(variable)
it { should assign_to(:user).with_kind_of(User) }
it { should_not assign_to(:user) }
it { should assign_to(:user) }
Example:
* with - The value that should be assigned.
being checked.
* with_kind_of - The expected class of the instance variable
Options:
Ensures that the controller assigned to the named instance variable.
def assign_to(variable) AssignToMatcher.new(variable) end
def filter_param(key)
Example:
Ensures that filter_parameter_logging is set for the specified key.
def filter_param(key) FilterParamMatcher.new(key) end
def render_with_layout(layout = nil)
it { should render_with_layout(:special) }
it { should render_with_layout }
Example:
Ensures that the controller rendered with the given layout.
def render_with_layout(layout = nil) RenderWithLayout.new(layout) end
def respond_with(status)
it { should respond_with(:error) }
it { should respond_with(:missing) }
it { should respond_with(:redirect) }
it { should respond_with(:success) }
Example:
See ActionController::StatusCodes for a full list.
or its symbolic equivalent :success, :redirect, :missing, :error.
You can pass an explicit status number like 200, 301, 404, 500
Ensures a controller responded with expected 'response' status code.
def respond_with(status) RespondWithMatcher.new(status) end
def respond_with_content_type(content_type)
it { should respond_with_content_type('application/rss+xml') }
it { should respond_with_content_type(:text) }
it { should respond_with_content_type(:yaml) }
it { should respond_with_content_type(:atom) }
it { should respond_with_content_type(:csv) }
it { should respond_with_content_type(:xml) }
Example:
or a regular expression such as /rss/
or its symbolic equivalent :rss
You can pass an explicit content type such as 'application/rss+xml'
Ensures a controller responded with expected 'response' content type.
def respond_with_content_type(content_type) RespondWithContentTypeMatcher.new(content_type) end
def route(method, path)
it { should route(:get, "/users/1/posts/1").
to(:action => :destroy, :id => 1) }
it { should route(:delete, "/posts/1").
it { should route(:put, "/posts/1").to(:action => :update, :id => 1) }
it { should route(:edit, "/posts/1").to(:action => :show, :id => 1) }
it { should route(:get, "/posts/1").to(:action => :show, :id => 1) }
it { should route(:post, "/posts").to(:action => :create) }
it { should route(:get, "/posts/new").to(:action => :new) }
to(:controller => :posts, :action => :index) }
it { should route(:get, "/posts").
Examples:
+to_param+ is called on the +options+ given.
example group.
If you don't specify a controller, it will use the controller from the
Ensures that requesting +path+ using +method+ routes to +options+.
def route(method, path) RouteMatcher.new(method, path, self) end
def set_session(key)
it { should set_session(:user_id).to(@user.id) }
it { should set_session(:message) }
Example:
Ensures that a session key was set to the expected value.
def set_session(key) SetSessionMatcher.new(key) end
def set_the_flash
it { should set_the_flash.to(/created/i) }
it { should set_the_flash.to("Thank you for placing this order.") }
it { should set_the_flash }
Example:
Regexp, or nil (indicating that the flash should not be set).
Ensures that the flash contains the given value. Can be a String, a
def set_the_flash SetTheFlashMatcher.new end