Class: RSpec::Crispy::CrispyFeatures::CrispyHaveReceived
- Inherits:
-
Object
- Object
- RSpec::Crispy::CrispyFeatures::CrispyHaveReceived
- Defined in:
- lib/rspec/crispy/crispy_features.rb
Direct Known Subclasses
Defined Under Namespace
Classes: NTimes
Instance Method Summary collapse
- #actually_received_messages_for_failure_message ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(method_name, *arguments) ⇒ CrispyHaveReceived
constructor
A new instance of CrispyHaveReceived.
- #matched_spy?(spy) ⇒ Boolean
- #matches?(subject) ⇒ Boolean
- #name ⇒ Object
- #once ⇒ Object
- #spy_of_subject(subject) ⇒ Object
- #times(n) ⇒ Object
Constructor Details
#initialize(method_name, *arguments) ⇒ CrispyHaveReceived
Returns a new instance of CrispyHaveReceived.
35 36 37 38 |
# File 'lib/rspec/crispy/crispy_features.rb', line 35 def initialize method_name, *arguments @method_name = method_name @arguments = arguments end |
Instance Method Details
#actually_received_messages_for_failure_message ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/rspec/crispy/crispy_features.rb', line 79 def if @spy_of_subject..empty? "Actually, it has received no messages.\n".freeze else result = "Actually, it has received these messages:\n" @spy_of_subject..each do|| = .arguments.map(&:inspect).join(', '.freeze) # TODO: which instance actually received the message for ClassSpy result << " it.#{.method_name}(#{})\n" end result end end |
#failure_message ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/rspec/crispy/crispy_features.rb', line 62 def @spy_of_subject.stop result = "Expected #{@subject.inspect} to have received :#@method_name method" result << " with #@arguments" unless @arguments.empty? result << ".\n" result << result end |
#failure_message_when_negated ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/rspec/crispy/crispy_features.rb', line 71 def @spy_of_subject.stop result = "Expected #{@subject.inspect} NOT to have received :#@method_name method" result << " with #@arguments" unless @arguments.empty? result << ". But actually received.\n".freeze result end |
#matched_spy?(spy) ⇒ Boolean
50 51 52 |
# File 'lib/rspec/crispy/crispy_features.rb', line 50 def matched_spy? spy spy.received? @method_name, *@arguments end |
#matches?(subject) ⇒ Boolean
44 45 46 47 48 |
# File 'lib/rspec/crispy/crispy_features.rb', line 44 def matches?(subject) @subject = subject @spy_of_subject = spy_of_subject subject matched_spy?(@spy_of_subject) end |
#name ⇒ Object
40 41 42 |
# File 'lib/rspec/crispy/crispy_features.rb', line 40 def name 'have_received'.freeze end |
#once ⇒ Object
54 55 56 |
# File 'lib/rspec/crispy/crispy_features.rb', line 54 def once times 1 end |
#spy_of_subject(subject) ⇒ Object
93 94 95 96 97 98 99 100 |
# File 'lib/rspec/crispy/crispy_features.rb', line 93 def spy_of_subject subject # Don't use instance_of? method. it records received_messages. if CrispyExpectAnyInstanceOf === subject subject.get_spy_of_instances else ::Crispy.spy(subject) end end |