-
-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
314 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
module RSpec | ||
module Mocks | ||
module Matchers | ||
class ReceiveMessages | ||
|
||
def initialize(message_return_value_hash) | ||
@message_return_value_hash = message_return_value_hash | ||
@backtrace_line = CallerFilter.first_non_rspec_line | ||
end | ||
|
||
def name | ||
"receive_messages" | ||
end | ||
|
||
def setup_expectation(subject, &block) | ||
each_message_on( proxy_on(subject) ) do |host, message, return_value| | ||
host.add_simple_expectation(message, return_value, @backtrace_line) | ||
end | ||
end | ||
alias matches? setup_expectation | ||
|
||
def setup_negative_expectation(subject, &block) | ||
raise NegationUnsupportedError, | ||
"`expect(...).to_not receive_messages` is not supported since it " + | ||
"doesn't really make sense. What would it even mean?" | ||
end | ||
alias does_not_match? setup_negative_expectation | ||
|
||
def setup_allowance(subject) | ||
each_message_on( proxy_on(subject) ) do |host, message, return_value| | ||
host.add_simple_stub(message, return_value) | ||
end | ||
end | ||
|
||
def setup_any_instance_expectation(subject) | ||
each_message_on( any_instance_of(subject) ) do |host, message, return_value| | ||
host.should_receive(message).and_return(return_value) | ||
end | ||
end | ||
|
||
def setup_any_instance_allowance(subject) | ||
any_instance_of(subject).stub(@message_return_value_hash) | ||
end | ||
|
||
private | ||
|
||
def proxy_on(subject) | ||
::RSpec::Mocks.proxy_for(subject) | ||
end | ||
|
||
def any_instance_of(subject) | ||
::RSpec::Mocks.any_instance_recorder_for(subject) | ||
end | ||
|
||
def each_message_on(host) | ||
@message_return_value_hash.each do |message, value| | ||
yield host, message, value | ||
end | ||
end | ||
|
||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.