rspec-mocks 2.3.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.markdown +8 -1
- data/Rakefile +2 -2
- data/features/.nav +11 -0
- data/features/README.markdown +2 -5
- data/features/message_expectations/README.md +59 -0
- data/features/message_expectations/expect_message.feature +1 -1
- data/features/message_expectations/warn_when_expectation_is_set_on_nil.feature +1 -1
- data/features/method_stubs/README.md +40 -0
- data/features/{stubs → method_stubs}/simple_return_value.feature +2 -2
- data/features/{stubs → method_stubs}/stub_chain.feature +8 -8
- data/features/{stubs → method_stubs}/stub_implementation.feature +1 -1
- data/features/outside_rspec/configuration.feature +1 -1
- data/features/outside_rspec/standalone.feature +1 -1
- data/lib/rspec/mocks/version.rb +1 -1
- metadata +17 -13
data/History.markdown
CHANGED
@@ -1,8 +1,15 @@
|
|
1
1
|
## rspec-mocks release history (incomplete)
|
2
2
|
|
3
|
+
### 2.4.0 / 2011-01-02
|
4
|
+
|
5
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.3.0...v2.4.0)
|
6
|
+
|
7
|
+
No functional changes in this release, which was made to align with the
|
8
|
+
rspec-core-2.4.0 release.
|
9
|
+
|
3
10
|
### 2.3.0 / 2010-12-12
|
4
11
|
|
5
|
-
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.2.
|
12
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.2.0...v2.3.0)
|
6
13
|
|
7
14
|
* Bug fixes
|
8
15
|
* Fix our Marshal extension so that it does not interfere with objects that
|
data/Rakefile
CHANGED
@@ -61,10 +61,10 @@ Rake::RDocTask.new do |rdoc|
|
|
61
61
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
62
62
|
end
|
63
63
|
|
64
|
-
desc "Push cukes to relishapp using the relish-client-gem"
|
64
|
+
desc "Push docs/cukes to relishapp using the relish-client-gem"
|
65
65
|
task :relish, :version do |t, args|
|
66
66
|
raise "rake relish[VERSION]" unless args[:version]
|
67
|
-
sh "relish push
|
67
|
+
sh "relish push rspec/rspec-mocks:#{args[:version]}"
|
68
68
|
end
|
69
69
|
|
70
70
|
task :default => [:spec, :cucumber]
|
data/features/.nav
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
- method_stubs:
|
2
|
+
- simple_return_value.feature
|
3
|
+
- stub_implementation.feature
|
4
|
+
- stub_chain.feature
|
5
|
+
- message_expectations:
|
6
|
+
- expect_message.feature
|
7
|
+
- block_local_expectations.feature.pending
|
8
|
+
- warn_when_expectation_is_set_on_nil.feature
|
9
|
+
- outside_rspec:
|
10
|
+
- configuration.feature
|
11
|
+
- standalone.feature
|
data/features/README.markdown
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
rspec-mocks is used to create dynamic "doubles", which stand in for real
|
2
|
-
objects in examples. You can
|
3
|
-
|
2
|
+
objects in examples. You can stub return values and/or set message
|
3
|
+
expectations:
|
4
4
|
|
5
5
|
describe Account do
|
6
6
|
context "when closed" do
|
@@ -16,9 +16,6 @@ methods), and/or stub return values for arbitrary messages:
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
Message expectations like the one in the example above are verified at
|
20
|
-
the end of each example.
|
21
|
-
|
22
19
|
## Issues
|
23
20
|
|
24
21
|
The documentation for rspec-mocks is a work in progress. We'll be adding
|
@@ -0,0 +1,59 @@
|
|
1
|
+
We're working on improving these docs. In the mean time, here's a cheat sheet
|
2
|
+
to cover the basics.
|
3
|
+
|
4
|
+
# create a double
|
5
|
+
obj = double()
|
6
|
+
|
7
|
+
# expect a message
|
8
|
+
obj.should_receive(:message)
|
9
|
+
|
10
|
+
# specify a return value
|
11
|
+
obj.should_receive(:message) { 'this is the value to return' }
|
12
|
+
|
13
|
+
### Argument constraints
|
14
|
+
|
15
|
+
#### Explicit arguments
|
16
|
+
|
17
|
+
obj.should_receive(:message).with('an argument')
|
18
|
+
obj.should_receive(:message).with('more_than', 'one_argument')
|
19
|
+
|
20
|
+
#### Argument matchers
|
21
|
+
|
22
|
+
obj.should_receive(:message).with(anything())
|
23
|
+
obj.should_receive(:message).with(an_instance_of(Money))
|
24
|
+
obj.should_receive(:message).with(hash_including(:a => 'b'))
|
25
|
+
|
26
|
+
#### Regular expressions
|
27
|
+
|
28
|
+
obj.should_receive(:message).with(/abc/)
|
29
|
+
|
30
|
+
### Counts
|
31
|
+
|
32
|
+
obj.should_receive(:message).once
|
33
|
+
obj.should_receive(:message).twice
|
34
|
+
obj.should_receive(:message).exactly(3).times
|
35
|
+
|
36
|
+
obj.should_receive(:message).at_least(:once)
|
37
|
+
obj.should_receive(:message).at_least(:twice)
|
38
|
+
obj.should_receive(:message).at_least(n).times
|
39
|
+
|
40
|
+
obj.should_receive(:message).at_most(:once)
|
41
|
+
obj.should_receive(:message).at_most(:twice)
|
42
|
+
obj.should_receive(:message).at_most(n).times
|
43
|
+
|
44
|
+
### Raising/Throwing
|
45
|
+
|
46
|
+
obj.should_receive(:message) { raise "this error" }
|
47
|
+
obj.should_receive(:message) { throw :this_symbol }
|
48
|
+
|
49
|
+
### Ordering
|
50
|
+
|
51
|
+
obj.should_receive(:one).ordered
|
52
|
+
obj.should_receive(:two).ordered
|
53
|
+
|
54
|
+
### Arbitrary handling
|
55
|
+
|
56
|
+
obj.should_receive(:message) do |arg1, arg2|
|
57
|
+
# set expectations about the args in this block
|
58
|
+
# and set a return value
|
59
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
We're working on improving these docs. In the mean time, here's a cheat sheet
|
2
|
+
to cover the basics.
|
3
|
+
|
4
|
+
# create a double
|
5
|
+
obj = double()
|
6
|
+
|
7
|
+
# stub a method
|
8
|
+
obj.stub(:message) # returns obj
|
9
|
+
|
10
|
+
# specify a return value
|
11
|
+
obj.stub(:message) { 'this is the value to return' }
|
12
|
+
|
13
|
+
### Argument constraints
|
14
|
+
|
15
|
+
#### Explicit arguments
|
16
|
+
|
17
|
+
obj.stub(:message).with('an argument')
|
18
|
+
obj.stub(:message).with('more_than', 'one_argument')
|
19
|
+
|
20
|
+
#### Argument matchers
|
21
|
+
|
22
|
+
obj.stub(:message).with(anything())
|
23
|
+
obj.stub(:message).with(an_instance_of(Money))
|
24
|
+
obj.stub(:message).with(hash_including(:a => 'b'))
|
25
|
+
|
26
|
+
#### Regular expressions
|
27
|
+
|
28
|
+
obj.stub(:message).with(/abc/)
|
29
|
+
|
30
|
+
### Raising/Throwing
|
31
|
+
|
32
|
+
obj.stub(:message) { raise "this error" }
|
33
|
+
obj.stub(:message) { throw :this_symbol }
|
34
|
+
|
35
|
+
### Arbitrary handling
|
36
|
+
|
37
|
+
obj.stub(:message) do |arg1, arg2|
|
38
|
+
# set expectations about the args in this block
|
39
|
+
# and set a return value
|
40
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
Feature:
|
1
|
+
Feature: stub with a simple return value
|
2
2
|
|
3
|
-
Use the stub
|
3
|
+
Use the `stub` method on a test double or a real object to tell the object to
|
4
4
|
return a value (or values) in response to a given message. If the message is
|
5
5
|
never received, nothing happens.
|
6
6
|
|
@@ -1,23 +1,23 @@
|
|
1
|
-
Feature:
|
1
|
+
Feature: stub a chain of methods
|
2
2
|
|
3
|
-
The stub_chain method lets you to stub a chain of methods in one statement.
|
3
|
+
The `stub_chain` method lets you to stub a chain of methods in one statement.
|
4
4
|
Method chains are considered a design smell, but it's not really the method
|
5
5
|
chain that is the problem - it's the dependency chain represented by a chain
|
6
6
|
of messages to different objects:
|
7
7
|
|
8
|
-
|
8
|
+
foo.get_bar.get_baz
|
9
9
|
|
10
|
-
This is a Law of Demeter violation if get_bar
|
11
|
-
foo
|
10
|
+
This is a Law of Demeter violation if `get_bar` returns an object other than
|
11
|
+
`foo`, and `get_baz` returns yet another object.
|
12
12
|
|
13
13
|
Fluent interfaces look similar from a caller's perspective, but don't
|
14
14
|
represent a dependency chain (the caller depends only on the object it is
|
15
15
|
calling). Consider this common example from Ruby on Rails:
|
16
16
|
|
17
|
-
|
17
|
+
Article.recent.by(current_user)
|
18
18
|
|
19
|
-
The recent
|
20
|
-
|
19
|
+
The `recent` and `by` methods return the same object, so this is not a Law of
|
20
|
+
Demeter violation.
|
21
21
|
|
22
22
|
Scenario: stub a chain of methods
|
23
23
|
Given a file named "stub_chain_spec.rb" with:
|
@@ -4,7 +4,7 @@ Feature: standalone
|
|
4
4
|
outside the RSpec environment. This is especially useful for
|
5
5
|
exploring rspec-mocks in irb.
|
6
6
|
|
7
|
-
Scenario: stub outside rspec
|
7
|
+
Scenario: method stub outside rspec
|
8
8
|
Given a file named "example.rb" with:
|
9
9
|
"""
|
10
10
|
require "rspec/mocks/standalone"
|
data/lib/rspec/mocks/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-mocks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 3
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 2
|
8
|
-
-
|
7
|
+
- 4
|
9
8
|
- 0
|
10
|
-
version: 2.
|
9
|
+
version: 2.4.0
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- David Chelimsky
|
@@ -16,7 +15,7 @@ autorequire:
|
|
16
15
|
bindir: bin
|
17
16
|
cert_chain: []
|
18
17
|
|
19
|
-
date:
|
18
|
+
date: 2011-01-02 00:00:00 -06:00
|
20
19
|
default_executable:
|
21
20
|
dependencies: []
|
22
21
|
|
@@ -41,15 +40,18 @@ files:
|
|
41
40
|
- Upgrade.markdown
|
42
41
|
- autotest/discover.rb
|
43
42
|
- cucumber.yml
|
43
|
+
- features/.nav
|
44
44
|
- features/README.markdown
|
45
|
+
- features/message_expectations/README.md
|
45
46
|
- features/message_expectations/block_local_expectations.feature.pending
|
46
47
|
- features/message_expectations/expect_message.feature
|
47
48
|
- features/message_expectations/warn_when_expectation_is_set_on_nil.feature
|
49
|
+
- features/method_stubs/README.md
|
50
|
+
- features/method_stubs/simple_return_value.feature
|
51
|
+
- features/method_stubs/stub_chain.feature
|
52
|
+
- features/method_stubs/stub_implementation.feature
|
48
53
|
- features/outside_rspec/configuration.feature
|
49
54
|
- features/outside_rspec/standalone.feature
|
50
|
-
- features/stubs/simple_return_value.feature
|
51
|
-
- features/stubs/stub_chain.feature
|
52
|
-
- features/stubs/stub_implementation.feature
|
53
55
|
- features/support/env.rb
|
54
56
|
- lib/rspec/mocks.rb
|
55
57
|
- lib/rspec/mocks/argument_expectation.rb
|
@@ -130,7 +132,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
130
132
|
requirements:
|
131
133
|
- - ">="
|
132
134
|
- !ruby/object:Gem::Version
|
133
|
-
hash:
|
135
|
+
hash: 1914883193122525774
|
134
136
|
segments:
|
135
137
|
- 0
|
136
138
|
version: "0"
|
@@ -139,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
141
|
requirements:
|
140
142
|
- - ">="
|
141
143
|
- !ruby/object:Gem::Version
|
142
|
-
hash:
|
144
|
+
hash: 1914883193122525774
|
143
145
|
segments:
|
144
146
|
- 0
|
145
147
|
version: "0"
|
@@ -149,17 +151,19 @@ rubyforge_project: rspec
|
|
149
151
|
rubygems_version: 1.3.7
|
150
152
|
signing_key:
|
151
153
|
specification_version: 3
|
152
|
-
summary: rspec-mocks-2.
|
154
|
+
summary: rspec-mocks-2.4.0
|
153
155
|
test_files:
|
154
156
|
- features/README.markdown
|
157
|
+
- features/message_expectations/README.md
|
155
158
|
- features/message_expectations/block_local_expectations.feature.pending
|
156
159
|
- features/message_expectations/expect_message.feature
|
157
160
|
- features/message_expectations/warn_when_expectation_is_set_on_nil.feature
|
161
|
+
- features/method_stubs/README.md
|
162
|
+
- features/method_stubs/simple_return_value.feature
|
163
|
+
- features/method_stubs/stub_chain.feature
|
164
|
+
- features/method_stubs/stub_implementation.feature
|
158
165
|
- features/outside_rspec/configuration.feature
|
159
166
|
- features/outside_rspec/standalone.feature
|
160
|
-
- features/stubs/simple_return_value.feature
|
161
|
-
- features/stubs/stub_chain.feature
|
162
|
-
- features/stubs/stub_implementation.feature
|
163
167
|
- features/support/env.rb
|
164
168
|
- spec/rspec/mocks/and_yield_spec.rb
|
165
169
|
- spec/rspec/mocks/any_number_of_times_spec.rb
|