Module: Merb::Test::ViewHelper

Defined in:
lib/merb-core/test/helpers/view_helper.rb

Defined Under Namespace

Classes: DocumentOutput

Instance Method Summary collapse

Instance Method Details

#element(css_query, output = process_output) ⇒ Object

Parameters

css_query<String>

A CSS query to find the element for.

output<DocumentOutput>

The output to look for the element in. Defaults to process_output.

Returns

Hpricot::Elem

The first tag matching the query.



73
74
75
# File 'lib/merb-core/test/helpers/view_helper.rb', line 73

def element(css_query, output = process_output)
  output[css_query].first
end

#elements(css_query, output = process_output) ⇒ Object

Parameters

css_query<String>

A CSS query to find the elements for.

output<DocumentOutput>

The output to look for the elements in. Defaults to process_output.

Returns

Array

All tags matching the query.



84
85
86
87
88
# File 'lib/merb-core/test/helpers/view_helper.rb', line 84

def elements(css_query, output = process_output)
  Hpricot::Elements[*css_query.to_s.split(",").map{|s| s.strip}.map do |query|
    output[query]
  end.flatten]
end

#get_elements(css_query, text, output = nil) ⇒ Object

Parameters

css_query<String>

A CSS query to find the elements for.

text<String, Regexp>

A pattern to match tag contents for.

output<DocumentOutput>

The output to look for the elements in. Defaults to process_output.

Returns

Array

All tags matching the query and pattern.



98
99
100
101
102
103
104
105
# File 'lib/merb-core/test/helpers/view_helper.rb', line 98

def get_elements(css_query, text, output = nil)
  els = elements(*[css_query, output].compact)
  case text
    when String then els.reject {|t| !t.contains?(text) }
    when Regexp then els.reject {|t| !t.matches?(text) }
    else []
  end
end

#tag(css_query, output = process_output) ⇒ Object

Parameters

css_query<String>

A CSS query to find the element for.

output<DocumentOutput>

The output to look for the element in. Defaults to process_output.

Returns

String

The content of the first tag matching the query.



51
52
53
# File 'lib/merb-core/test/helpers/view_helper.rb', line 51

def tag(css_query, output = process_output)
  output.content_for(css_query)
end

#tags(css_query, output = process_output) ⇒ Object

Parameters

css_query<String>

A CSS query to find the elements for.

output<DocumentOutput>

The output to look for the element in. Defaults to process_output.

Returns

Array

Content of all tags matching the query.



62
63
64
# File 'lib/merb-core/test/helpers/view_helper.rb', line 62

def tags(css_query, output = process_output)
  output.content_for_all(css_query)
end