Class: RSpec::ProcessMocks::ChildProcessMessageExpectation
- Inherits:
-
Mocks::MessageExpectation
- Object
- Mocks::MessageExpectation
- RSpec::ProcessMocks::ChildProcessMessageExpectation
- Defined in:
- lib/rspec/process_mocks/message_expectation.rb
Instance Method Summary collapse
-
#actual_messages ⇒ Object
Reads back the actual/exact-match arguments written to the temp file.
-
#actual_received_count ⇒ Object
The following methods used to use instance variables.
-
#advise(*args) ⇒ Object
This method is executed in the child process when the stubbed method is called with similar argument.
- #generate_error ⇒ Object
-
#initialize(*args) ⇒ ChildProcessMessageExpectation
constructor
A new instance of ChildProcessMessageExpectation.
-
#invoke(*args, &block) ⇒ Object
This method is executed in the child process when the stubbed method is called exact arguments Overwritten from rspec.
- #matches_at_least_count? ⇒ Boolean
- #matches_at_most_count? ⇒ Boolean
- #matches_exact_count? ⇒ Boolean
-
#similar_messages ⇒ Object
This overwrites the rspec implementation because we need to record similar messages in a temp file not instance variables.
Constructor Details
#initialize(*args) ⇒ ChildProcessMessageExpectation
Returns a new instance of ChildProcessMessageExpectation.
6 7 8 9 10 11 12 13 14 |
# File 'lib/rspec/process_mocks/message_expectation.rb', line 6 def initialize(*args) super # The temp files are used for interprocess communication. # This one stores the calls that are exact matches. @actual_tempfile = Tempfile.new("should-receive-#{@expected_from.object_id}-#{@sym}") # This one stores the similar calls. @similar_tempfile = Tempfile.new("should-receive-similar-#{@expected_from.object_id}-#{@sym}") end |
Instance Method Details
#actual_messages ⇒ Object
Reads back the actual/exact-match arguments written to the temp file. This is not a method in rspec.
44 45 46 47 |
# File 'lib/rspec/process_mocks/message_expectation.rb', line 44 def @actual_tempfile.rewind @actual_tempfile.readlines end |
#actual_received_count ⇒ Object
The following methods used to use instance variables. But we can’t do that because those aren’t shared between processes. These methods overwrite rspec’s behavior and instead keep the state in temp files.
52 53 54 |
# File 'lib/rspec/process_mocks/message_expectation.rb', line 52 def actual_received_count .size end |
#advise(*args) ⇒ Object
This method is executed in the child process when the stubbed method is called with similar argument. Overwritten from rspec.
29 30 31 32 33 |
# File 'lib/rspec/process_mocks/message_expectation.rb', line 29 def advise(*args) @similar_tempfile.puts msg @similar_tempfile.flush end |
#generate_error ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/rspec/process_mocks/message_expectation.rb', line 55 def generate_error if .empty? @error_generator.raise_expectation_error(@sym, @expected_received_count, actual_received_count, *@args_expectation.args) else @error_generator.(self, *) end end |
#invoke(*args, &block) ⇒ Object
This method is executed in the child process when the stubbed method is called exact arguments Overwritten from rspec.
20 21 22 23 24 |
# File 'lib/rspec/process_mocks/message_expectation.rb', line 20 def invoke(*args, &block) msg = args.inspect @actual_tempfile.puts msg @actual_tempfile.flush end |
#matches_at_least_count? ⇒ Boolean
62 63 64 |
# File 'lib/rspec/process_mocks/message_expectation.rb', line 62 def matches_at_least_count? @at_least && actual_received_count >= @expected_received_count end |
#matches_at_most_count? ⇒ Boolean
65 66 67 |
# File 'lib/rspec/process_mocks/message_expectation.rb', line 65 def matches_at_most_count? @at_most && actual_received_count <= @expected_received_count end |
#matches_exact_count? ⇒ Boolean
68 69 70 |
# File 'lib/rspec/process_mocks/message_expectation.rb', line 68 def matches_exact_count? @expected_received_count == actual_received_count end |
#similar_messages ⇒ Object
This overwrites the rspec implementation because we need to record similar messages in a temp file not instance variables.
37 38 39 40 |
# File 'lib/rspec/process_mocks/message_expectation.rb', line 37 def @similar_tempfile.rewind @similar_tempfile.readlines end |