Class: ExampleExpectations::ArbitraryMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/gems/rspec-1.1.11/spec/spec/matchers/handler_spec.rb

Direct Known Subclasses

PositiveOnlyMatcher

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ ArbitraryMatcher

Returns a new instance of ArbitraryMatcher.



6
7
8
9
10
11
12
13
14
# File 'lib/gems/rspec-1.1.11/spec/spec/matchers/handler_spec.rb', line 6

def initialize(*args, &block)
  if args.last.is_a? Hash
    @expected = args.last[:expected]
  end
  if block_given?
    @expected = block.call
  end
  @block = block
end

Instance Method Details

#failure_messageObject



26
27
28
# File 'lib/gems/rspec-1.1.11/spec/spec/matchers/handler_spec.rb', line 26

def failure_message
  "expected #{@expected}, got #{@target}"
end

#matches?(target) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
19
# File 'lib/gems/rspec-1.1.11/spec/spec/matchers/handler_spec.rb', line 16

def matches?(target)
  @target = target
  return @expected == target
end

#negative_failure_messageObject



30
31
32
# File 'lib/gems/rspec-1.1.11/spec/spec/matchers/handler_spec.rb', line 30

def negative_failure_message
  "expected not #{@expected}, got #{@target}"
end

#with(new_value) ⇒ Object



21
22
23
24
# File 'lib/gems/rspec-1.1.11/spec/spec/matchers/handler_spec.rb', line 21

def with(new_value)
  @expected = new_value
  self
end