Class Spec::Mocks::ArgumentExpectation
In: vendor/plugins/rspec/lib/spec/mocks/argument_expectation.rb
Parent: Object

Methods

Public Class methods

[Source]

     # File vendor/plugins/rspec/lib/spec/mocks/argument_expectation.rb, line 120
120:       def initialize(args)
121:         @args = args
122:         if [:any_args] == args
123:           @expected_params = nil
124:           warn_deprecated(:any_args.inspect, "any_args()")
125:         elsif args.length == 1 && args[0].is_a?(AnyArgsConstraint) then @expected_params = nil
126:         elsif [:no_args] == args
127:           @expected_params = []
128:           warn_deprecated(:no_args.inspect, "no_args()")
129:         elsif args.length == 1 && args[0].is_a?(NoArgsConstraint) then @expected_params = []
130:         else @expected_params = process_arg_constraints(args)
131:         end
132:       end

Public Instance methods

[Source]

     # File vendor/plugins/rspec/lib/spec/mocks/argument_expectation.rb, line 168
168:       def check_args(args)
169:         return true if @expected_params.nil?
170:         return true if @expected_params == args
171:         return constraints_match?(args)
172:       end

[Source]

     # File vendor/plugins/rspec/lib/spec/mocks/argument_expectation.rb, line 174
174:       def constraints_match?(args)
175:         return false if args.length != @expected_params.length
176:         @expected_params.each_index { |i| return false unless @expected_params[i].matches?(args[i]) }
177:         return true
178:       end

[Source]

     # File vendor/plugins/rspec/lib/spec/mocks/argument_expectation.rb, line 144
144:       def convert_constraint(constraint)
145:         if [:anything, :numeric, :boolean, :string].include?(constraint)
146:           case constraint
147:           when :anything
148:             instead = "anything()"
149:           when :boolean
150:             instead = "boolean()"
151:           when :numeric
152:             instead = "an_instance_of(Numeric)"
153:           when :string
154:             instead = "an_instance_of(String)"
155:           end
156:           warn_deprecated(constraint.inspect, instead)
157:           return @@constraint_classes[constraint].new(constraint)
158:         end
159:         return MatcherConstraint.new(constraint) if is_matcher?(constraint)
160:         return RegexpArgConstraint.new(constraint) if constraint.is_a?(Regexp)
161:         return LiteralArgConstraint.new(constraint)
162:       end

[Source]

     # File vendor/plugins/rspec/lib/spec/mocks/argument_expectation.rb, line 164
164:       def is_matcher?(obj)
165:         return obj.respond_to?(:matches?) && obj.respond_to?(:description)
166:       end

[Source]

     # File vendor/plugins/rspec/lib/spec/mocks/argument_expectation.rb, line 134
134:       def process_arg_constraints(constraints)
135:         constraints.collect do |constraint| 
136:           convert_constraint(constraint)
137:         end
138:       end

[Source]

     # File vendor/plugins/rspec/lib/spec/mocks/argument_expectation.rb, line 140
140:       def warn_deprecated(deprecated_method, instead)
141:         Kernel.warn "The #{deprecated_method} constraint is deprecated. Use #{instead} instead."
142:       end

[Validate]