Class: Merb::Test::Rspec::ViewMatchers::MatchTag

Inherits:
Object
  • Object
show all
Defined in:
lib/merb-core/test/matchers/view_matchers.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, attrs) ⇒ MatchTag

Parameters

name<~to_s>

The name of the tag to look for.

attrs<Hash>

Attributes to look for in the tag (see below).

Options (attrs)

:content<String>

Optional content to match.



48
49
50
51
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 48

def initialize(name, attrs)
  @name, @attrs = name, attrs
  @content = @attrs.delete(:content)
end

Instance Method Details

#failure_messageObject

Returns

String

The failure message.



78
79
80
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 78

def failure_message
  @errors[0]
end

#matches?(target) ⇒ Boolean

Parameters

target<String>

The string to look for the tag in.

Returns

Boolean

True if the tag matched.

Returns:

  • (Boolean)


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 58

def matches?(target)
  @errors = []
  unless target.include?("<#{@name}")
    @errors << "Expected a <#{@name}>, but was #{target}"
  end
  @attrs.each do |attr, val|
    unless target.include?("#{attr}=\"#{val}\"")
      @errors << "Expected #{attr}=\"#{val}\", but was #{target}"
    end
  end
  if @content
    unless target.include?(">#{@content}<")
      @errors << "Expected #{target} to include #{@content}"
    end
  end
  @errors.size == 0
end

#negative_failure_messageObject

Returns

String

The failure message to be displayed in negative matches.



84
85
86
# File 'lib/merb-core/test/matchers/view_matchers.rb', line 84

def negative_failure_message
  "Expected not to match against <#{@name} #{@attrs.map{ |a,v| "#{a}=\"#{v}\"" }.join(" ")}> tag, but it matched"
end