Module: Rspec::Rails23::Matchers::Controllers
- Defined in:
- lib/rspec/rails23/matchers/controllers/redirect_to.rb,
lib/rspec/rails23/matchers/controllers/render_template.rb
Defined Under Namespace
Classes: RedirectTo, RenderTemplate
Instance Method Summary collapse
-
#redirect_to(opts) ⇒ Object
:call-seq: response.should redirect_to(url) response.should redirect_to(:action => action_name) response.should redirect_to(:controller => controller_name, :action => action_name) response.should_not redirect_to(url) response.should_not redirect_to(:action => action_name) response.should_not redirect_to(:controller => controller_name, :action => action_name).
-
#render_template(path) ⇒ Object
:call-seq: response.should render_template(template) response.should_not render_template(template).
Instance Method Details
#redirect_to(opts) ⇒ Object
:call-seq:
response.should redirect_to(url)
response.should redirect_to(:action => action_name)
response.should redirect_to(:controller => controller_name, :action => action_name)
response.should_not redirect_to(url)
response.should_not redirect_to(:action => action_name)
response.should_not redirect_to(:controller => controller_name, :action => action_name)
Passes if the response is a redirect to the url, action or controller/action. Useful in controller specs (integration or isolation mode).
Examples
response.should redirect_to("path/to/action")
response.should redirect_to("http://test.host/path/to/action")
response.should redirect_to(:action => 'list')
108 109 110 |
# File 'lib/rspec/rails23/matchers/controllers/redirect_to.rb', line 108 def redirect_to(opts) RedirectTo.new(request, opts) end |
#render_template(path) ⇒ Object
:call-seq:
response.should render_template(template)
response.should_not render_template(template)
For use in controller code examples (integration or isolation mode).
Passes if the specified template (view file) is rendered by the response. This file can be any view file, including a partial. However if it is a partial it must be rendered directly i.e. you can’t detect that a partial has been rendered as part of a view using render_template. For that you should use a message expectation (mock) instead:
controller.should_receive(:render).with(:partial => 'path/to/partial')
template
can include the controller path. It can also include an optional extension, which you only need to use when there is ambiguity.
Note that partials must be spelled with the preceding underscore.
Examples
response.should render_template('list')
response.should render_template('same_controller/list')
response.should render_template('other_controller/list')
# with extensions
response.should render_template('list.rjs')
response.should render_template('list.haml')
response.should render_template('same_controller/list.rjs')
response.should render_template('other_controller/list.rjs')
# partials
response.should render_template('_a_partial')
response.should render_template('same_controller/_a_partial')
response.should render_template('other_controller/_a_partial')
109 110 111 |
# File 'lib/rspec/rails23/matchers/controllers/render_template.rb', line 109 def render_template(path) RenderTemplate.new(path.to_s, @controller) end |