Sha256: da6e05398cbb05e737acfde8408a12eb0634348f7a6bd3f06ce2a844b604e724

Contents?: true

Size: 1.22 KB

Versions: 18

Compression:

Stored size: 1.22 KB

Contents

### Stub return values

    # create a double
    obj = double()

    # specify a return value
    obj.stub(:message) { :value }
    obj.stub(:message => :value)
    obj.stub(: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.stub(:message) do |arg1, arg2|
      # set expectations about the args in this block
      # and/or set a return value
    end

### Raising/Throwing

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

You can also use the block format:

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

### Argument constraints
   
#### Explicit arguments

    obj.stub(:message).with('an argument') { ... }
    obj.stub(:message).with('more_than', 'one_argument') { ... }

#### Argument matchers

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

#### Regular expressions

    obj.stub(:message).with(/abc/) { ... }

Version data entries

18 entries across 18 versions & 8 rubygems

Version Path
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/rspec-mocks-2.13.0/features/method_stubs/README.md
tnargav-1.3.3 vendor/bundle/ruby/1.9.1/gems/rspec-mocks-2.11.3/features/method_stubs/README.md
tnargav-1.2.3 vendor/bundle/ruby/1.9.1/gems/rspec-mocks-2.11.3/features/method_stubs/README.md
sshp-0.0.2 vendor/ruby/1.9.1/gems/rspec-mocks-2.13.1/features/method_stubs/README.md
sshp-0.0.1 vendor/ruby/1.9.1/gems/rspec-mocks-2.13.1/features/method_stubs/README.md
sidekiq-statsd-0.1.1 vendor/ruby/1.9.1/gems/rspec-mocks-2.13.1/features/method_stubs/README.md
sidekiq-statsd-0.1.0 vendor/ruby/1.9.1/gems/rspec-mocks-2.13.1/features/method_stubs/README.md
rspec-mocks-2.13.1 features/method_stubs/README.md
vagrant-actionio-0.0.9 vendor/bundle/gems/rspec-mocks-2.13.0/features/method_stubs/README.md
rspec-mocks-2.13.0 features/method_stubs/README.md
remq-0.0.4 vendor/bundle/gems/rspec-mocks-2.12.2/features/method_stubs/README.md
remq-0.0.3 vendor/bundle/gems/rspec-mocks-2.12.2/features/method_stubs/README.md
rspec-mocks-2.12.2 features/method_stubs/README.md
rspec-mocks-2.12.1 features/method_stubs/README.md
rspec-mocks-2.12.0 features/method_stubs/README.md
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/rspec-mocks-2.11.3/features/method_stubs/README.md
rspec-mocks-2.11.3 features/method_stubs/README.md
rspec-mocks-2.11.2 features/method_stubs/README.md