Sha256: 83e32578c865c4037f7859f0ba682f2b9d12592c0acf13994a28114a0096e5bd

Contents?: true

Size: 1.19 KB

Versions: 145

Compression:

Stored size: 1.19 KB

Contents

### Stub return values

    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, for consistency with other stubs:

    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

145 entries across 91 versions & 12 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/rspec-mocks-2.10.1/features/method_stubs/README.md
classiccms-0.7.5 vendor/bundle/gems/rspec-mocks-2.9.0/features/method_stubs/README.md
classiccms-0.7.4 vendor/bundle/gems/rspec-mocks-2.10.1/features/method_stubs/README.md
classiccms-0.7.4 vendor/bundle/gems/rspec-mocks-2.9.0/features/method_stubs/README.md
classiccms-0.7.3 vendor/bundle/gems/rspec-mocks-2.10.1/features/method_stubs/README.md
classiccms-0.7.3 vendor/bundle/gems/rspec-mocks-2.9.0/features/method_stubs/README.md
classiccms-0.7.2 vendor/bundle/gems/rspec-mocks-2.10.1/features/method_stubs/README.md
classiccms-0.7.2 vendor/bundle/gems/rspec-mocks-2.9.0/features/method_stubs/README.md
classiccms-0.7.1 vendor/bundle/gems/rspec-mocks-2.9.0/features/method_stubs/README.md
classiccms-0.7.1 vendor/bundle/gems/rspec-mocks-2.10.1/features/method_stubs/README.md
classiccms-0.7.0 vendor/bundle/gems/rspec-mocks-2.10.1/features/method_stubs/README.md
classiccms-0.7.0 vendor/bundle/gems/rspec-mocks-2.9.0/features/method_stubs/README.md
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/rspec-mocks-2.10.1/features/method_stubs/README.md
classiccms-0.6.9 vendor/bundle/gems/rspec-mocks-2.10.1/features/method_stubs/README.md
classiccms-0.6.9 vendor/bundle/gems/rspec-mocks-2.9.0/features/method_stubs/README.md
classiccms-0.6.8 vendor/bundle/gems/rspec-mocks-2.9.0/features/method_stubs/README.md
classiccms-0.6.8 vendor/bundle/gems/rspec-mocks-2.10.1/features/method_stubs/README.md
classiccms-0.6.7 vendor/bundle/gems/rspec-mocks-2.10.1/features/method_stubs/README.md
classiccms-0.6.7 vendor/bundle/gems/rspec-mocks-2.9.0/features/method_stubs/README.md
classiccms-0.6.6 vendor/bundle/gems/rspec-mocks-2.10.1/features/method_stubs/README.md