Class: RSpec::Mocks::ArgumentExpectation
- Inherits:
-
Object
- Object
- RSpec::Mocks::ArgumentExpectation
- Defined in:
- lib/rspec/mocks/argument_expectation.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
Instance Method Summary collapse
- #args_match?(*args) ⇒ Boolean
-
#initialize(*args, &block) ⇒ ArgumentExpectation
constructor
A new instance of ArgumentExpectation.
- #is_matcher?(obj) ⇒ Boolean
- #is_stub_as_null_object?(obj) ⇒ Boolean
- #match_any_args? ⇒ Boolean
- #matcher_for(arg) ⇒ Object
- #matchers_block_matches?(*args) ⇒ Boolean
- #matchers_match?(*args) ⇒ Boolean
Constructor Details
#initialize(*args, &block) ⇒ ArgumentExpectation
Returns a new instance of ArgumentExpectation.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/rspec/mocks/argument_expectation.rb', line 6 def initialize(*args, &block) @args = args @matchers_block = args.empty? ? block : nil @match_any_args = false @matchers = nil case args.first when ArgumentMatchers::AnyArgsMatcher @match_any_args = true when ArgumentMatchers::NoArgsMatcher @matchers = [] else @matchers = args.collect {|arg| matcher_for(arg)} end end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
4 5 6 |
# File 'lib/rspec/mocks/argument_expectation.rb', line 4 def args @args end |
Instance Method Details
#args_match?(*args) ⇒ Boolean
36 37 38 |
# File 'lib/rspec/mocks/argument_expectation.rb', line 36 def args_match?(*args) match_any_args? || matchers_block_matches?(*args) || matchers_match?(*args) end |
#is_matcher?(obj) ⇒ Boolean
28 29 30 |
# File 'lib/rspec/mocks/argument_expectation.rb', line 28 def is_matcher?(obj) !is_stub_as_null_object?(obj) & obj.respond_to?(:matches?) & obj.respond_to?(:description) end |
#is_stub_as_null_object?(obj) ⇒ Boolean
32 33 34 |
# File 'lib/rspec/mocks/argument_expectation.rb', line 32 def is_stub_as_null_object?(obj) obj.respond_to?(:__rspec_double_acting_as_null_object?) && obj.__rspec_double_acting_as_null_object? end |
#match_any_args? ⇒ Boolean
48 49 50 |
# File 'lib/rspec/mocks/argument_expectation.rb', line 48 def match_any_args? @match_any_args end |
#matcher_for(arg) ⇒ Object
22 23 24 25 26 |
# File 'lib/rspec/mocks/argument_expectation.rb', line 22 def matcher_for(arg) return ArgumentMatchers::MatcherMatcher.new(arg) if is_matcher?(arg) return ArgumentMatchers::RegexpMatcher.new(arg) if arg.is_a?(Regexp) return ArgumentMatchers::EqualityProxy.new(arg) end |
#matchers_block_matches?(*args) ⇒ Boolean
40 41 42 |
# File 'lib/rspec/mocks/argument_expectation.rb', line 40 def matchers_block_matches?(*args) @matchers_block ? @matchers_block.call(*args) : nil end |
#matchers_match?(*args) ⇒ Boolean
44 45 46 |
# File 'lib/rspec/mocks/argument_expectation.rb', line 44 def matchers_match?(*args) @matchers == args end |