Class: Spec::Mocks::MessageExpectation

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

### Methods

any_number_of_times at_least at_most exactly 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 times twice verify_messages_received with

### Public Instance methods

any_number_of_times(&block)

[Source]

         # File lib/spec/mocks/message_expectation.rb, line 206
    206:       def any_number_of_times(&block)
    207:         @method_block = block if block
    208:         @expected_received_count = :any
    209:         self
    210:       end

at_least(n)

[Source]

         # File lib/spec/mocks/message_expectation.rb, line 191
    191:       def at_least(n)
    192:         set_expected_received_count :at_least, n
    193:         self
    194:       end

at_most(n)

[Source]

         # File lib/spec/mocks/message_expectation.rb, line 196
    196:       def at_most(n)
    197:         set_expected_received_count :at_most, n
    198:         self
    199:       end

exactly(n)

[Source]

         # File lib/spec/mocks/message_expectation.rb, line 186
    186:       def exactly(n)
    187:         set_expected_received_count :exactly, n
    188:         self
    189:       end

generate_error()

[Source]

         # File lib/spec/mocks/message_expectation.rb, line 176
    176:       def generate_error
    177:         @error_generator.raise_expectation_error(@sym, @expected_received_count, @actual_received_count, *@args_expectation.args)
    178:       end

ignoring_args?()

[Source]

         # File lib/spec/mocks/message_expectation.rb, line 160
    160:       def ignoring_args?
    161:         @expected_received_count == :any
    162:       end

matches_at_least_count?()

[Source]

         # File lib/spec/mocks/message_expectation.rb, line 164
    164:       def matches_at_least_count?
    165:         @at_least && @actual_received_count >= @expected_received_count
    166:       end

matches_at_most_count?()

[Source]

         # File lib/spec/mocks/message_expectation.rb, line 168
    168:       def matches_at_most_count?
    169:         @at_most && @actual_received_count <= @expected_received_count
    170:       end

matches_exact_count?()

[Source]

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

matches_name_but_not_args(sym, args)

[Source]

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

negative_expectation_for?(sym)

[Source]

         # File lib/spec/mocks/message_expectation.rb, line 236
    236:       def negative_expectation_for?(sym)
    237:         return false
    238:       end

never()

[Source]

         # File lib/spec/mocks/message_expectation.rb, line 212
    212:       def never
    213:         @expected_received_count = 0
    214:         self
    215:       end

once(&block)

[Source]

         # File lib/spec/mocks/message_expectation.rb, line 217
    217:       def once(&block)
    218:         @method_block = block if block
    219:         @expected_received_count = 1
    220:         self
    221:       end

ordered(&block)

[Source]

         # File lib/spec/mocks/message_expectation.rb, line 229
    229:       def ordered(&block)
    230:         @method_block = block if block
    231:         @order_group.register(self)
    232:         @ordered = true
    233:         self
    234:       end

times(&block)

[Source]

         # File lib/spec/mocks/message_expectation.rb, line 201
    201:       def times(&block)
    202:         @method_block = block if block
    203:         self
    204:       end

twice(&block)

[Source]

         # File lib/spec/mocks/message_expectation.rb, line 223
    223:       def twice(&block)
    224:         @method_block = block if block
    225:         @expected_received_count = 2
    226:         self
    227:       end

verify_messages_received()

[Source]

         # File lib/spec/mocks/message_expectation.rb, line 150
    150:       def verify_messages_received
    151:         return if ignoring_args? || matches_exact_count? ||
    152:            matches_at_least_count? || matches_at_most_count?
    153:
    154:         generate_error
    155:       rescue Spec::Mocks::MockExpectationError => error
    156:         error.backtrace.insert(0, @expected_from)
    157:         Kernel::raise error
    158:       end

with(*args, &block)

[Source]

         # File lib/spec/mocks/message_expectation.rb, line 180
    180:       def with(*args, &block)
    181:         @method_block = block if block
    182:         @args_expectation = ArgumentExpectation.new(args)
    183:         self
    184:       end

### Protected Instance methods

set_expected_received_count(relativity, n)

[Source]

         # File lib/spec/mocks/message_expectation.rb, line 241
    241:         def set_expected_received_count(relativity, n)
    242:           @at_least = (relativity == :at_least)
    243:           @at_most = (relativity == :at_most)
    244:           @expected_received_count = case n
    245:             when Numeric
    246:               n
    247:             when :once
    248:               1
    249:             when :twice
    250:               2
    251:           end
    252:         end

[Validate]