Class: Stencil::ViewMatcher::SubviewMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/stencil/spec/view_matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(subview) ⇒ SubviewMatcher

Returns a new instance of SubviewMatcher.



14
15
16
# File 'lib/stencil/spec/view_matcher.rb', line 14

def initialize(subview)
  @subview = subview
end

Instance Method Details

#create_submatches(path, subview) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/stencil/spec/view_matcher.rb', line 24

def create_submatches(path, subview)
  case subview
  when Hash
    subview.each_pair do |name, value|
      create_submatches(path + [name], value)
    end
  when Array
    subview.each_with_index do |value, index|
      create_submatches(path + [index], value)
    end
  else
    if subview.respond_to?(:matches?)
      @view.at_path(*path).should(subview)
    else
      @view.at_path(*path).should == subview
    end
  end
end

#matches?(view) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
# File 'lib/stencil/spec/view_matcher.rb', line 18

def matches?(view)
  @view = view
  create_submatches([], @subview)
  return true
end