Class: Spec::Matchers::SimpleMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/vendor/plugins/rspec/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
10
# File 'lib/vendor/plugins/rspec/lib/spec/matchers/simple_matcher.rb', line 6

def initialize(description, &match_block)
  @description = description
  @match_block = match_block
  @failure_message = @negative_failure_message = nil
end

Instance Attribute Details

#descriptionObject



22
23
24
# File 'lib/vendor/plugins/rspec/lib/spec/matchers/simple_matcher.rb', line 22

def description
  @description || explanation
end

#failure_message=(value) ⇒ Object (writeonly)

Sets the attribute failure_message

Parameters:

  • value

    the value to set the attribute failure_message to.



4
5
6
# File 'lib/vendor/plugins/rspec/lib/spec/matchers/simple_matcher.rb', line 4

def failure_message=(value)
  @failure_message = value
end

#negative_failure_message=(value) ⇒ Object (writeonly)

Sets the attribute negative_failure_message

Parameters:

  • value

    the value to set the attribute negative_failure_message to.



4
5
6
# File 'lib/vendor/plugins/rspec/lib/spec/matchers/simple_matcher.rb', line 4

def negative_failure_message=(value)
  @negative_failure_message = value
end

Instance Method Details

#explanationObject



34
35
36
# File 'lib/vendor/plugins/rspec/lib/spec/matchers/simple_matcher.rb', line 34

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

#failure_message_for_shouldObject



26
27
28
# File 'lib/vendor/plugins/rspec/lib/spec/matchers/simple_matcher.rb', line 26

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

#failure_message_for_should_notObject



30
31
32
# File 'lib/vendor/plugins/rspec/lib/spec/matchers/simple_matcher.rb', line 30

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

#matches?(given) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
20
# File 'lib/vendor/plugins/rspec/lib/spec/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