Module: Suhyo::ViewMatchers
- Includes:
- Webrat::Matchers
- Defined in:
- lib/suhyo/view_matchers.rb
Defined Under Namespace
Classes: HaveOrderedContent, HaveRestfulForm
Instance Method Summary collapse
-
#contain_in_order(content, options = {}) ⇒ Object
Like Webrat’s
contain
matcher, except it checks that one bit of text comes before or after another. -
#have_button(options = {}) ⇒ Object
A simple wrapper around
have_selector
. -
#have_link(options = {}) ⇒ Object
A simple wrapper around
have_selector
. -
#have_restful_form(method, options = {}) ⇒ Object
Wrapper around
have_selector
.
Instance Method Details
#contain_in_order(content, options = {}) ⇒ Object
Like Webrat’s contain
matcher, except it checks that one bit of text comes before or after another. Can be used to test sort order in an integration test. Usage:
response.should contain_in_order('ABC', :before => 'DEF')
response.should contain_in_order('DEF', :after => 'ABC')
79 80 81 |
# File 'lib/suhyo/view_matchers.rb', line 79 def contain_in_order(content, = {}) HaveOrderedContent.new(content, ) end |
#have_button(options = {}) ⇒ Object
A simple wrapper around have_selector
. Usage:
response.should (:text => 'Submit')
8 9 10 11 12 |
# File 'lib/suhyo/view_matchers.rb', line 8 def ( = {}) [:type] = 'button' [:value] = .delete(:text) if .has_key?(:text) have_selector('input', ) end |
#have_link(options = {}) ⇒ Object
A simple wrapper around have_selector
. Usage:
response.should have_link(:url => people_url, :text => 'People', :ancestors => 'div#main')
The above example would match the following:
<div id="main">
<a href="http://test.host/people">People</a>
</div>
Options other than :url
, :text
, and ancestors
will be passed through to have_selector
.
95 96 97 98 99 100 101 102 103 104 |
# File 'lib/suhyo/view_matchers.rb', line 95 def have_link( = {}) [:href] = .delete(:url) if .has_key?(:url) [:content] = .delete(:text) if .has_key?(:text) if ancestors = .delete(:ancestors) selector = ancestors + ' a' else selector = 'a' end have_selector(selector, ) end |
#have_restful_form(method, options = {}) ⇒ Object
Wrapper around have_selector
. Checks for a Rails-style form with the given HTTP method. You can also specify the action
and any other other attributes in the options
hash. Usage:
response.should have_restful_form('put', :action => person_path(42), :class => 'edit_person', :ancestors => 'div#main')
The above example would match the following:
<div id="main">
<form method="post" action="/people/42">
<input type="hidden" name="_method" value="put"/>
</form>
</div>
Options other than ancestors
will be passed through to have_selector
.
177 178 179 |
# File 'lib/suhyo/view_matchers.rb', line 177 def have_restful_form(method, = {}) HaveRestfulForm.new(method, ) end |