Sha256: 76d1679813f9eaa38e77a13b5d4f82e82d1891a4e0aad90f4e424912c9d458b6

Contents?: true

Size: 1.95 KB

Versions: 39

Compression:

Stored size: 1.95 KB

Contents

### Basics

    # create a double
    obj = double()

    # expect a message
    obj.should_receive(:message)

    # specify a return value
    obj.should_receive(:message) { :value }
    obj.should_receive(:message => :value)
    obj.should_receive(:message).and_return(:value)

These forms are somewhat interchangeable. The difference is that the
block contents are evaluated lazily when the `obj` receives the
`message` message, whereas the others are evaluated as they are read.

### Fake implementation

    obj.should_receive(:message) do |arg1, arg2|
      # set expectations about the args in this block
      # and set a return value
    end

### Using the original implementation

    obj.should_receive(:message).and_call_original

### Raising/Throwing

    obj.should_receive(:message).and_raise("this error")
    obj.should_receive(:message).and_throw(:this_symbol)

You can also use the block format:

    obj.should_receive(:message) { raise "this error" }
    obj.should_receive(:message) { throw :this_symbol }

### Argument constraints

#### Explicit arguments

    obj.should_receive(:message).with('an argument')
    obj.should_receive(:message).with('more_than', 'one_argument')

#### Argument matchers

    obj.should_receive(:message).with(anything())
    obj.should_receive(:message).with(an_instance_of(Money))
    obj.should_receive(:message).with(hash_including(:a => 'b'))

#### Regular expressions

    obj.should_receive(:message).with(/abc/)

### Counts

    obj.should_receive(:message).once
    obj.should_receive(:message).twice
    obj.should_receive(:message).exactly(3).times

    obj.should_receive(:message).at_least(:once)
    obj.should_receive(:message).at_least(:twice)
    obj.should_receive(:message).at_least(n).times

    obj.should_receive(:message).at_most(:once)
    obj.should_receive(:message).at_most(:twice)
    obj.should_receive(:message).at_most(n).times

### Ordering

    obj.should_receive(:one).ordered
    obj.should_receive(:two).ordered

Version data entries

39 entries across 39 versions & 8 rubygems

Version Path
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/rspec-mocks-2.14.6/features/message_expectations/README.md
vagrant-unbundled-1.9.5.1 vendor/bundle/ruby/2.4.0/gems/rspec-mocks-2.14.6/features/message_expectations/README.md
vagrant-unbundled-1.9.1.1 vendor/bundle/ruby/2.4.0/gems/rspec-mocks-2.14.6/features/message_expectations/README.md
vagrant-unbundled-1.8.5.2 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/features/message_expectations/README.md
vagrant-unbundled-1.8.5.1 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/features/message_expectations/README.md
vagrant-unbundled-1.8.4.2 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/features/message_expectations/README.md
vagrant-unbundled-1.8.4.1 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/features/message_expectations/README.md
vagrant-unbundled-1.8.1.1 vendor/bundle/ruby/2.3.0/gems/rspec-mocks-2.14.6/features/message_expectations/README.md
rspec-mocks-2.99.4 features/message_expectations/README.md
vagrant-cloudstack-1.1.0 vendor/bundle/gems/rspec-mocks-2.14.6/features/message_expectations/README.md
rspec-mocks-2.99.3 features/message_expectations/README.md
rspec-mocks-2.99.2 features/message_expectations/README.md
dxruby_rp5-0.0.4 spec/vendor/rspec-mocks-2.14.4/features/message_expectations/README.md
rspec-mocks-2.99.1 features/message_expectations/README.md
rspec-mocks-2.99.0 features/message_expectations/README.md
rspec-mocks-2.99.0.rc1 features/message_expectations/README.md
rspec-mocks-2.14.6 features/message_expectations/README.md
rspec-mocks-2.99.0.beta2 features/message_expectations/README.md
rspec-mocks-2.14.5 features/message_expectations/README.md
mango-0.8.0 vendor/bundler/ruby/2.1.0/gems/rspec-mocks-2.14.4/features/message_expectations/README.md