Class: Bogus::WithArguments

Inherits:
Object
  • Object
show all
Defined in:
lib/bogus/stubbing/matchers/with_arguments.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&predicate) ⇒ WithArguments

Returns a new instance of WithArguments.



5
6
7
# File 'lib/bogus/stubbing/matchers/with_arguments.rb', line 5

def initialize(&predicate)
  @predicate = predicate
end

Instance Attribute Details

#predicateObject (readonly)

Returns the value of attribute predicate.



3
4
5
# File 'lib/bogus/stubbing/matchers/with_arguments.rb', line 3

def predicate
  @predicate
end

Class Method Details

.matches?(opts = {}) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
# File 'lib/bogus/stubbing/matchers/with_arguments.rb', line 13

def self.matches?(opts = {})
  stubbed = opts.fetch(:stubbed)
  recorded = opts.fetch(:recorded)
  return false unless with_matcher?(stubbed)
  return extract(stubbed).matches?(recorded)
end

.with_matcher?(args) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/bogus/stubbing/matchers/with_arguments.rb', line 20

def self.with_matcher?(args)
  args.first.is_a?(WithArguments)
end

Instance Method Details

#matches?(args) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/bogus/stubbing/matchers/with_arguments.rb', line 9

def matches?(args)
  predicate.call(*args)
end