Class: Micronaut::Matchers::SimpleMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/micronaut/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.



7
8
9
10
# File 'lib/micronaut/matchers/simple_matcher.rb', line 7

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

Instance Attribute Details

#descriptionObject



22
23
24
# File 'lib/micronaut/matchers/simple_matcher.rb', line 22

def description
  @description || explanation
end

#failure_messageObject



26
27
28
# File 'lib/micronaut/matchers/simple_matcher.rb', line 26

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

#negative_failure_messageObject



30
31
32
# File 'lib/micronaut/matchers/simple_matcher.rb', line 30

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



34
35
36
# File 'lib/micronaut/matchers/simple_matcher.rb', line 34

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

#matches?(given) ⇒ Boolean

Returns:

  • (Boolean)


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

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