File: README.md

package info (click to toggle)
ruby-rspec-mocks 2.14.5-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 868 kB
  • ctags: 725
  • sloc: ruby: 8,227; makefile: 4
file content (27 lines) | stat: -rw-r--r-- 680 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
### Introduction

Argument matchers can be used:

* In stubs to constrain the scope of the stubbed method

    obj.stub(:foo).with(:bar) do |arg|
      #do something for :bar
    end
    obj.stub(:foo).with(:baz) do |arg|
      #do something for :baz
    end

* In expectations to validate the arguments that should be received in a method call

    #create a double
    obj = double()

    #expect a message with given args
    obj.should_receive(:message).with('an argument')

If more control is needed, one can use a block

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