module Spec::Rails::Matchers
def have_rjs(*args, &block)
wrapper for assert_select_rjs
response.should have_rjs(*args, &block)
:call-seq:
def have_rjs(*args, &block) AssertSelect.new(:assert_select_rjs, self, *args, &block) end
def have_tag(*args, &block)
person_address_tag.should have_tag("input#person_address")
# in a helper spec (person_address_tag is a method in the helper)
response.should have_tag("div", "some text")
# in a controller spec
== Examples
of helper methods.
helper specs, for example, to set expectations on the results
css selectors to set expectation on Strings. Use this in
wrapper for assert_select with additional support for using
string.should have_tag(*args, &block)
response.should have_tag(*args, &block)
:call-seq:
def have_tag(*args, &block) AssertSelect.new(:assert_select, self, *args, &block) end
def have_text(text)
== Examples
when you want to match the whole string or whole body
Use this instead of response.should have_tag()
else it uses response_or_text
If response_or_text has a #body, then that is used as to match against
and a Regexp using =~.
Accepts a String or a Regexp, matching a String using ==
response.should_not have_text(expected)
response.should have_text(expected)
:call-seq:
def have_text(text) HaveText.new(text) end
def include_text(text)
== Examples
this text appears.
when you either don't know or don't care where on the page
Use this instead of response.should have_text()
Accepts a String, matching using include?
response.should_not include_text(expected)
response.should include_text(expected)
:call-seq:
def include_text(text) IncludeText.new(text) end
def redirect_to(opts)
response.should redirect_to("http://test.host/path/to/action")
response.should redirect_to("path/to/action")
== Examples
Useful in controller specs (integration or isolation mode).
Passes if the response is a redirect to the url, action or controller/action.
response.should_not redirect_to(:controller => controller_name, :action => action_name)
response.should_not redirect_to(:action => action_name)
response.should_not redirect_to(url)
response.should redirect_to(:controller => controller_name, :action => action_name)
response.should redirect_to(:action => action_name)
response.should redirect_to(url)
:call-seq:
def redirect_to(opts) RedirectTo.new(request, opts) end
def render_template(path)
response.should render_template('same_controller/_a_partial')
response.should render_template('_a_partial')
#partials
response.should render_template('other_controller/list.rjs')
response.should render_template('same_controller/list.rjs')
response.should render_template('list.rjs')
#rjs
response.should render_template('other_controller/list')
response.should render_template('same_controller/list')
response.should render_template('list')
== Examples
Note that partials must be spelled with the preceding underscore.
can also include an optional extension (no extension assumes .rhtml).
path
can include the controller path or not. ItUseful in controller specs (integration or isolation mode).
Passes if the specified template is rendered by the response.
response.should_not render_template(path)
response.should render_template(path)
:call-seq:
def render_template(path) RenderTemplate.new(path.to_s, @controller) end
def send_email(*args, &block)
wrapper for assert_select_email
response.should send_email(*args, &block)
:call-seq:
def send_email(*args, &block) AssertSelect.new(:assert_select_email, self, *args, &block) end
def with_encoded(*args, &block)
wrapper for assert_select_encoded
def with_encoded(*args, &block) should AssertSelect.new(:assert_select_encoded, self, *args, &block) end
def with_tag(*args, &block)
end
with_tag("input#person_name[name=?]", "person[name]")
response.should have_tag("div#form") do
wrapper for a nested assert_select
def with_tag(*args, &block) should have_tag(*args, &block) end
def without_tag(*args, &block)
end
without_tag("span", "some text that shouldn't be there")
response.should have_tag("div#1") do
wrapper for a nested assert_select with false
def without_tag(*args, &block) should_not have_tag(*args, &block) end