Class: Catechism::Matchers::Send

Inherits:
Struct
  • Object
show all
Defined in:
lib/catechism/matchers/send.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



3
4
5
# File 'lib/catechism/matchers/send.rb', line 3

def arguments
  @arguments
end

#destinationObject (readonly)

Returns the value of attribute destination.



3
4
5
# File 'lib/catechism/matchers/send.rb', line 3

def destination
  @destination
end

#method_nameObject

Returns the value of attribute method_name

Returns:

  • (Object)

    the current value of method_name



2
3
4
# File 'lib/catechism/matchers/send.rb', line 2

def method_name
  @method_name
end

#negatedObject

Returns the value of attribute negated

Returns:

  • (Object)

    the current value of negated



2
3
4
# File 'lib/catechism/matchers/send.rb', line 2

def negated
  @negated
end

#subjectObject

Returns the value of attribute subject

Returns:

  • (Object)

    the current value of subject



2
3
4
# File 'lib/catechism/matchers/send.rb', line 2

def subject
  @subject
end

Instance Method Details

#failure_messageObject



29
30
31
32
33
34
35
# File 'lib/catechism/matchers/send.rb', line 29

def failure_message
  if negated
    "Expected #{destination} not to receive #{method_name}, but got it anyway"
  else
    "Expected #{method_name} on #{destination}, but was not received"
  end
end

#to(destination) ⇒ Object



5
6
7
8
# File 'lib/catechism/matchers/send.rb', line 5

def to(destination)
  @destination = destination
  raise failure_message unless valid?
end

#valid?Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/catechism/matchers/send.rb', line 15

def valid?
  called = false
  send_matcher = self
  destination.class.send(:define_method, method_name) do |*args|
    if !send_matcher.arguments.nil?
      called = send_matcher.arguments == args
    else
      called = true
    end
  end
  subject.call
  called ^ negated
end

#with(*arguments) ⇒ Object



10
11
12
13
# File 'lib/catechism/matchers/send.rb', line 10

def with(*arguments)
  @arguments = arguments
  self
end