Class | Spec::Mocks::MessageExpectation
In: | lib/spec/mocks/message_expectation.rb
Parent: | BaseExpectation

### Methods

advise any_number_of_times at_least at_most exactly expected_messages_received? generate_error ignoring_args? matches_at_least_count? matches_at_most_count? matches_exact_count? matches_name_but_not_args negative_expectation_for? never once ordered set_expected_received_count similar_messages times twice verify_messages_received with

### Public Instance methods

advise(args, block)

[Source]

         # File lib/spec/mocks/message_expectation.rb, line 192
    192:       def advise(args, block)
    193:         similar_messages << args
    194:       end

any_number_of_times(&block)

[Source]

         # File lib/spec/mocks/message_expectation.rb, line 230
    230:       def any_number_of_times(&block)
    231:         @method_block = block if block
    232:         @expected_received_count = :any
    233:         self
    234:       end

at_least(n)

[Source]

         # File lib/spec/mocks/message_expectation.rb, line 215
    215:       def at_least(n)
    216:         set_expected_received_count :at_least, n
    217:         self
    218:       end

at_most(n)

[Source]

         # File lib/spec/mocks/message_expectation.rb, line 220
    220:       def at_most(n)
    221:         set_expected_received_count :at_most, n
    222:         self
    223:       end

exactly(n)

[Source]

         # File lib/spec/mocks/message_expectation.rb, line 210
    210:       def exactly(n)
    211:         set_expected_received_count :exactly, n
    212:         self
    213:       end

expected_messages_received?()

[Source]

         # File lib/spec/mocks/message_expectation.rb, line 167
    167:       def expected_messages_received?
    168:         ignoring_args? || matches_exact_count? ||
    169:            matches_at_least_count? || matches_at_most_count?
    170:       end

generate_error()

[Source]

         # File lib/spec/mocks/message_expectation.rb, line 196
    196:       def generate_error
    197:         if similar_messages.empty?
    198:           @error_generator.raise_expectation_error(@sym, @expected_received_count, @actual_received_count, *@args_expectation.args)
    199:         else
    200:           @error_generator.raise_unexpected_message_args_error(self, *@similar_messages.first)
    201:         end
    202:       end

ignoring_args?()

[Source]

         # File lib/spec/mocks/message_expectation.rb, line 172
    172:       def ignoring_args?
    173:         @expected_received_count == :any
    174:       end

matches_at_least_count?()

[Source]

         # File lib/spec/mocks/message_expectation.rb, line 176
    176:       def matches_at_least_count?
    177:         @at_least && @actual_received_count >= @expected_received_count
    178:       end

matches_at_most_count?()

[Source]

         # File lib/spec/mocks/message_expectation.rb, line 180
    180:       def matches_at_most_count?
    181:         @at_most && @actual_received_count <= @expected_received_count
    182:       end

matches_exact_count?()

[Source]

         # File lib/spec/mocks/message_expectation.rb, line 184
    184:       def matches_exact_count?
    185:         @expected_received_count == @actual_received_count
    186:       end

matches_name_but_not_args(sym, args)

[Source]

         # File lib/spec/mocks/message_expectation.rb, line 154
    154:       def matches_name_but_not_args(sym, args)
    155:         @sym == sym and not @args_expectation.check_args(args)
    156:       end

negative_expectation_for?(sym)

[Source]

         # File lib/spec/mocks/message_expectation.rb, line 260
    260:       def negative_expectation_for?(sym)
    261:         return false
    262:       end

never()

[Source]

         # File lib/spec/mocks/message_expectation.rb, line 236
    236:       def never
    237:         @expected_received_count = 0
    238:         self
    239:       end

once(&block)

[Source]

         # File lib/spec/mocks/message_expectation.rb, line 241
    241:       def once(&block)
    242:         @method_block = block if block
    243:         @expected_received_count = 1
    244:         self
    245:       end

ordered(&block)

[Source]

         # File lib/spec/mocks/message_expectation.rb, line 253
    253:       def ordered(&block)
    254:         @method_block = block if block
    255:         @order_group.register(self)
    256:         @ordered = true
    257:         self
    258:       end

similar_messages()

[Source]

         # File lib/spec/mocks/message_expectation.rb, line 188
    188:       def similar_messages
    189:         @similar_messages ||= []
    190:       end

times(&block)

[Source]

         # File lib/spec/mocks/message_expectation.rb, line 225
    225:       def times(&block)
    226:         @method_block = block if block
    227:         self
    228:       end

twice(&block)

[Source]

         # File lib/spec/mocks/message_expectation.rb, line 247
    247:       def twice(&block)
    248:         @method_block = block if block
    249:         @expected_received_count = 2
    250:         self
    251:       end

verify_messages_received()

[Source]

         # File lib/spec/mocks/message_expectation.rb, line 158
    158:       def verify_messages_received
    159:         return if expected_messages_received?
    160:
    161:         generate_error
    162:       rescue Spec::Mocks::MockExpectationError => error
    163:         error.backtrace.insert(0, @expected_from)
    164:         Kernel::raise error
    165:       end

with(*args, &block)

[Source]

         # File lib/spec/mocks/message_expectation.rb, line 204
    204:       def with(*args, &block)
    205:         @method_block = block if block
    206:         @args_expectation = ArgumentExpectation.new(args)
    207:         self
    208:       end

### Protected Instance methods

set_expected_received_count(relativity, n)

[Source]

         # File lib/spec/mocks/message_expectation.rb, line 265
    265:         def set_expected_received_count(relativity, n)
    266:           @at_least = (relativity == :at_least)
    267:           @at_most = (relativity == :at_most)
    268:           @expected_received_count = case n
    269:             when Numeric
    270:               n
    271:             when :once
    272:               1
    273:             when :twice
    274:               2
    275:           end
    276:         end

[Validate]