Class: Spec::Matchers::SimpleMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/spec/matchers/simple_matcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(description, &match_block) ⇒ SimpleMatcher

Returns a new instance of SimpleMatcher.



6
7
8
9
# File 'lib/spec/matchers/simple_matcher.rb', line 6

def initialize(description, &match_block)
  @description = description
  @match_block = match_block
end

Instance Attribute Details

#descriptionObject



21
22
23
# File 'lib/spec/matchers/simple_matcher.rb', line 21

def description
  @description || explanation
end

#failure_messageObject



25
26
27
# File 'lib/spec/matchers/simple_matcher.rb', line 25

def failure_message
  @failure_message || (@description.nil? ? explanation : %[expected #{@description.inspect} but got #{@given.inspect}])
end

#negative_failure_messageObject



29
30
31
# File 'lib/spec/matchers/simple_matcher.rb', line 29

def negative_failure_message
  @negative_failure_message || (@description.nil? ? explanation : %[expected not to get #{@description.inspect}, but got #{@given.inspect}])
end

Instance Method Details

#explanationObject



33
34
35
# File 'lib/spec/matchers/simple_matcher.rb', line 33

def explanation
  "No description provided. See RDoc for simple_matcher()"
end

#matches?(given) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
# File 'lib/spec/matchers/simple_matcher.rb', line 11

def matches?(given)
  @given = given
  case @match_block.arity
  when 2
    @match_block.call(@given, self)
  else
    @match_block.call(@given)
  end
end