Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 41 lines (31 sloc) 1.147 kB
daa9b05 @dchelimsky change top-level module from Rspec to RSpec
dchelimsky authored
1 # RSpec Mocks
f9f8418 @dchelimsky words
dchelimsky authored
2
3 rspec-mocks provides a test-double framework for rspec including support
4 for method stubs, fakes, and message expectations.
5
6084658 @dchelimsky links to docs
dchelimsky authored
6 ## Install
f9f8418 @dchelimsky words
dchelimsky authored
7
6084658 @dchelimsky links to docs
dchelimsky authored
8 gem install rspec # for rspec-core, rspec-expectations, rspec-mocks
9 gem install rspec-mocks # for rspec-mocks only
d5a1da7 @spicycode Initial jeweler repository creation
spicycode authored
10
f26af00 @dchelimsky words
dchelimsky authored
11 ## Method Stubs
12
13 describe "consumer" do
14 it "gets stuff from a service" do
15 service = double('service')
16 service.stub(:find) { 'value' }
17 consumer = Consumer.new(service)
18 consumer.consume
19 consumer.aquired_stuff.should eq(['value'])
20 end
21 end
22
23 ## Message Expectations
24
25 describe "some action" do
26 context "when bad stuff happens" do
27 it "logs the error" do
28 logger = double('logger')
29 doer = Doer.new(logger)
30 logger.should_receive(:log).with('oops')
31 doer.do_something_with(:bad_data)
32 end
33 end
34 end
9d19ca0 @dchelimsky update readme
dchelimsky authored
35
f26af00 @dchelimsky words
dchelimsky authored
36 ## Also see
9d19ca0 @dchelimsky update readme
dchelimsky authored
37
f9f8418 @dchelimsky words
dchelimsky authored
38 * [http://github.com/rspec/rspec](http://github.com/rspec/rspec)
39 * [http://github.com/rspec/rspec-core](http://github.com/rspec/rspec-core)
40 * [http://github.com/rspec/rspec-expectations](http://github.com/rspec/rspec-expectations)
Something went wrong with that request. Please try again.