Class: Spec::Mocks::ArgumentExpectation
- Defined in:
- lib/spec/mocks/argument_expectation.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
Instance Method Summary collapse
- #args_match?(given_args) ⇒ Boolean
-
#initialize(args, &block) ⇒ ArgumentExpectation
constructor
A new instance of ArgumentExpectation.
- #is_matcher?(obj) ⇒ Boolean
- #match_any_args? ⇒ Boolean
- #matcher_for(arg) ⇒ Object
- #matchers_block_matches?(given_args) ⇒ Boolean
- #matchers_match?(given_args) ⇒ Boolean
Constructor Details
#initialize(args, &block) ⇒ ArgumentExpectation
Returns a new instance of ArgumentExpectation.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/spec/mocks/argument_expectation.rb', line 7 def initialize(args, &block) @args = args @matchers_block = block if ArgumentMatchers::AnyArgsMatcher === args.first @match_any_args = true elsif ArgumentMatchers::NoArgsMatcher === args.first @matchers = [] else @matchers = args.collect {|arg| matcher_for(arg)} end end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
5 6 7 |
# File 'lib/spec/mocks/argument_expectation.rb', line 5 def args @args end |
Instance Method Details
#args_match?(given_args) ⇒ Boolean
30 31 32 |
# File 'lib/spec/mocks/argument_expectation.rb', line 30 def args_match?(given_args) match_any_args? || matchers_block_matches?(given_args) || matchers_match?(given_args) end |
#is_matcher?(obj) ⇒ Boolean
26 27 28 |
# File 'lib/spec/mocks/argument_expectation.rb', line 26 def is_matcher?(obj) return obj.respond_to?(:matches?) & obj.respond_to?(:description) end |
#match_any_args? ⇒ Boolean
42 43 44 |
# File 'lib/spec/mocks/argument_expectation.rb', line 42 def match_any_args? @match_any_args end |
#matcher_for(arg) ⇒ Object
20 21 22 23 24 |
# File 'lib/spec/mocks/argument_expectation.rb', line 20 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?(given_args) ⇒ Boolean
34 35 36 |
# File 'lib/spec/mocks/argument_expectation.rb', line 34 def matchers_block_matches?(given_args) @matchers_block ? @matchers_block.call(*given_args) : nil end |
#matchers_match?(given_args) ⇒ Boolean
38 39 40 |
# File 'lib/spec/mocks/argument_expectation.rb', line 38 def matchers_match?(given_args) @matchers == given_args end |