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. Useful for testing sort order, for example.



57
58
59
# File 'lib/suhyo/view_matchers.rb', line 57

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



73
74
75
76
77
78
79
80
81
82
# File 'lib/suhyo/view_matchers.rb', line 73

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.



155
156
157
# File 'lib/suhyo/view_matchers.rb', line 155

def have_restful_form(method, options = {})
	HaveRestfulForm.new(method, options)
end