module Shoulda::Matchers::ActionController

def assign_to(variable)

it { should assign_to(:user).with(@user) }
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.
:nodoc:
def assign_to(variable)
  AssignToMatcher.new(variable)
end

def filter_param(key)

it { should filter_param(:password) }

Example:

Ensures that filter_parameter_logging is set for the specified key.
:nodoc:
def filter_param(key)
  FilterParamMatcher.new(key)
end

def permit(*attributes)

def permit(*attributes)
  attributes_and_context = attributes + [self]
  StrongParametersMatcher.new(*attributes_and_context)
end

def redirect_to(url_or_description, &block)

it { should redirect_to(users_path) }
it { should redirect_to('http://somewhere.com') }

Example:

Ensures a controller redirected to the given url.
:nodoc:
def redirect_to(url_or_description, &block)
  RedirectToMatcher.new(url_or_description, self, &block)
end

def render_template(options = {}, message = nil)

it { should render_template(:partial => false) }
assert that no partials were rendered

it { should render_template(:partial => '_customer', :count => 2) }
assert that the "_customer" partial was rendered twice

it { should render_template(:partial => '_customer') }
assert that the "_customer" partial was rendered

it { should render_template(:show) }

Example:

Ensures a controller rendered the given template.
:nodoc:
def render_template(options = {}, message = nil)
  RenderTemplateMatcher.new(options, message, self)
end

def render_with_layout(expected_layout = nil)

it { should_not render_with_layout }
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(expected_layout = nil)
  RenderWithLayoutMatcher.new(expected_layout).in_context(self)
end

def respond_with(status)

it { should respond_with(501) }
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(/json/) }
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)

to(:action => :show, :id => 1, :user_id => 1) }
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(:get, '/posts/1/edit').to(:action => :edit, :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_not set_session(:user_id) }
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_not set_the_flash }
it { should set_the_flash.to(/logged in/i).now }
it { should set_the_flash[:alert].to('Password does not match') }
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