Module: Suhyo::ViewMatchers

Includes:
Webrat::Matchers
Defined in:
lib/suhyo/view_matchers.rb

Defined Under Namespace

Classes: HaveOrderedContent, HaveRestfulForm

Instance Method Summary collapse

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, options = {})
	HaveOrderedContent.new(content, options)
end

#have_button(options = {}) ⇒ Object

A simple wrapper around have_selector. Usage:

response.should have_button(:text => 'Submit')


8
9
10
11
12
# File 'lib/suhyo/view_matchers.rb', line 8

def have_button(options = {})
	options[:type] = 'button'
	options[:value] = options.delete(:text) if options.has_key?(:text)
	have_selector('input', options)
end

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(options = {})
	options[:href] = options.delete(:url) if options.has_key?(:url)
	options[:content] = options.delete(:text) if options.has_key?(:text)
	if ancestors = options.delete(:ancestors)
		selector = ancestors + ' a'
	else
		selector = 'a'
	end
	have_selector(selector, options)
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, options = {})
	HaveRestfulForm.new(method, options)
end