rspec-mocks 2.4.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -5,15 +5,6 @@ Bundler::GemHelper.install_tasks
5
5
  require 'rake'
6
6
  require 'rspec/core/rake_task'
7
7
  require 'rspec/mocks/version'
8
- require 'cucumber/rake/task'
9
-
10
- class Cucumber::Rake::Task::ForkedCucumberRunner
11
- # When cucumber shells out, we still need it to run in the context of our
12
- # bundle.
13
- def run
14
- sh "bundle exec #{RUBY} " + args.join(" ")
15
- end
16
- end
17
8
 
18
9
  task :cleanup_rcov_files do
19
10
  rm_rf 'coverage.data'
@@ -24,8 +15,6 @@ RSpec::Core::RakeTask.new(:spec) do |t|
24
15
  t.rspec_opts = %w[--color]
25
16
  end
26
17
 
27
- Cucumber::Rake::Task.new(:cucumber)
28
-
29
18
  namespace :spec do
30
19
  desc "Run all examples using rcov"
31
20
  RSpec::Core::RakeTask.new :rcov => :cleanup_rcov_files do |t|
@@ -35,17 +24,35 @@ namespace :spec do
35
24
  end
36
25
  end
37
26
 
38
- namespace :cucumber do
39
- desc "Run cucumber features using rcov"
40
- Cucumber::Rake::Task.new :rcov => :cleanup_rcov_files do |t|
41
- t.cucumber_opts = %w{--format progress}
42
- t.rcov = true
43
- t.rcov_opts = %[-Ilib -Ispec --exclude "gems/*,features"]
44
- t.rcov_opts << %[--text-report --sort coverage --aggregate coverage.data]
27
+ task :default => :spec
28
+
29
+ begin
30
+ require 'cucumber/rake/task'
31
+
32
+ class Cucumber::Rake::Task::ForkedCucumberRunner
33
+ # When cucumber shells out, we still need it to run in the context of our
34
+ # bundle.
35
+ def run
36
+ sh "bundle exec #{RUBY} " + args.join(" ")
37
+ end
45
38
  end
46
- end
47
39
 
48
- task :default => [:spec, :cucumber]
40
+ Cucumber::Rake::Task.new(:cucumber)
41
+
42
+ namespace :cucumber do
43
+ desc "Run cucumber features using rcov"
44
+ Cucumber::Rake::Task.new :rcov => :cleanup_rcov_files do |t|
45
+ t.cucumber_opts = %w{--format progress}
46
+ t.rcov = true
47
+ t.rcov_opts = %[-Ilib -Ispec --exclude "gems/*,features"]
48
+ t.rcov_opts << %[--text-report --sort coverage --aggregate coverage.data]
49
+ end
50
+ end
51
+
52
+ task :default => :cucumber
53
+ rescue LoadError
54
+ $stderr.puts "unable to load cucumber, some tasks unavailable"
55
+ end
49
56
 
50
57
  task :clobber do
51
58
  rm_rf 'pkg'
@@ -66,5 +73,3 @@ task :relish, :version do |t, args|
66
73
  raise "rake relish[VERSION]" unless args[:version]
67
74
  sh "relish push rspec/rspec-mocks:#{args[:version]}"
68
75
  end
69
-
70
- task :default => [:spec, :cucumber]
@@ -1,3 +1,5 @@
1
+ - Upgrade.md
2
+ - Changelog.md
1
3
  - method_stubs:
2
4
  - simple_return_value.feature
3
5
  - stub_implementation.feature
@@ -1,4 +1,12 @@
1
- ## rspec-mocks release history (incomplete)
1
+ ### 2.5.0 / 2011-02-05
2
+
3
+ [full changelog](http://github.com/rspec/rspec-mocks/compare/v2.4.0...v2.5.0)
4
+
5
+ * Bug fixes
6
+ * message expectation counts now work in combination with a stub (Damian
7
+ Nurzynski)
8
+ * fix failure message when message received with incorrect args (Josep M.
9
+ Bach)
2
10
 
3
11
  ### 2.4.0 / 2011-01-02
4
12
 
@@ -1,5 +1,4 @@
1
- We're working on improving these docs. In the mean time, here's a cheat sheet
2
- to cover the basics.
1
+ ### Basics
3
2
 
4
3
  # create a double
5
4
  obj = double()
@@ -1,5 +1,4 @@
1
- We're working on improving these docs. In the mean time, here's a cheat sheet
2
- to cover the basics.
1
+ ### Basics
3
2
 
4
3
  # create a double
5
4
  obj = double()
@@ -24,6 +24,7 @@ module RSpec
24
24
  @order_group = expectation_ordering
25
25
  @at_least = nil
26
26
  @at_most = nil
27
+ @exactly = nil
27
28
  @args_to_yield = []
28
29
  @failed_fast = nil
29
30
  @args_to_yield_were_cloned = false
@@ -286,13 +287,13 @@ module RSpec
286
287
 
287
288
  def once(&block)
288
289
  @method_block = block if block
289
- @expected_received_count = 1
290
+ set_expected_received_count :exactly, 1
290
291
  self
291
292
  end
292
293
 
293
294
  def twice(&block)
294
295
  @method_block = block if block
295
- @expected_received_count = 2
296
+ set_expected_received_count :exactly, 2
296
297
  self
297
298
  end
298
299
 
@@ -307,10 +308,19 @@ module RSpec
307
308
  return false
308
309
  end
309
310
 
311
+ def actual_received_count_matters?
312
+ @at_least || @at_most || @exactly
313
+ end
314
+
315
+ def increase_actual_received_count!
316
+ @actual_received_count += 1
317
+ end
318
+
310
319
  protected
311
320
  def set_expected_received_count(relativity, n)
312
321
  @at_least = (relativity == :at_least)
313
322
  @at_most = (relativity == :at_most)
323
+ @exactly = (relativity == :exactly)
314
324
  @expected_received_count = case n
315
325
  when Numeric
316
326
  n
@@ -324,7 +334,7 @@ module RSpec
324
334
  def clear_actual_received_count!
325
335
  @actual_received_count = 0
326
336
  end
327
-
337
+
328
338
  end
329
339
 
330
340
  class NegativeMessageExpectation < MessageExpectation
@@ -96,6 +96,7 @@ module RSpec
96
96
  stub = find_matching_method_stub(method_name, *args)
97
97
 
98
98
  if (stub && expectation && expectation.called_max_times?) || (stub && !expectation)
99
+ expectation.increase_actual_received_count! if expectation && expectation.actual_received_count_matters?
99
100
  if expectation = find_almost_matching_expectation(method_name, *args)
100
101
  expectation.advise(*args) unless expectation.expected_messages_received?
101
102
  end
@@ -141,7 +142,7 @@ module RSpec
141
142
  end
142
143
 
143
144
  def find_almost_matching_expectation(method_name, *args)
144
- method_double[method_name].expectations.find {|expectation| expectation.matches_name_but_not_args(method_name, *args)}
145
+ method_double[method_name].expectations.find {|expectation| expectation.matches_name_but_not_args(method_name, *args) && !expectation.called_max_times?}
145
146
  end
146
147
 
147
148
  def find_matching_method_stub(method_name, *args)
@@ -1,7 +1,7 @@
1
1
  module RSpec # :nodoc:
2
2
  module Mocks # :nodoc:
3
3
  module Version # :nodoc:
4
- STRING = '2.4.0'
4
+ STRING = '2.5.0'
5
5
  end
6
6
  end
7
7
  end
@@ -109,6 +109,17 @@ module RSpec
109
109
  }.should raise_error(RSpec::Mocks::MockExpectationError, "Double \"test double\" received :something with unexpected arguments\n expected: (\"a\", \"b\", \"c\")\n got: (\"a\", \"d\", \"c\")")
110
110
  end
111
111
 
112
+ describe "even when a similar expectation with different arguments exist" do
113
+ it "raises exception if args don't match when method called, correctly reporting the offending arguments" do
114
+ @mock.should_receive(:something).with("a","b","c").once
115
+ @mock.should_receive(:something).with("z","x","c").once
116
+ lambda {
117
+ @mock.something("a","b","c")
118
+ @mock.something("z","x","g")
119
+ }.should raise_error(RSpec::Mocks::MockExpectationError, "Double \"test double\" received :something with unexpected arguments\n expected: (\"z\", \"x\", \"c\")\n got: (\"z\", \"x\", \"g\")")
120
+ end
121
+ end
122
+
112
123
  it "raises exception if args don't match when method called even when the method is stubbed" do
113
124
  @mock.stub(:something)
114
125
  @mock.should_receive(:something).with("a","b","c")
@@ -8,7 +8,7 @@ module RSpec
8
8
  @return_values = ["1",2,Object.new]
9
9
  @mock.should_receive(:message).and_return(@return_values[0],@return_values[1],@return_values[2])
10
10
  end
11
-
11
+
12
12
  it "returns values in order to consecutive calls" do
13
13
  @mock.message.should == @return_values[0]
14
14
  @mock.message.should == @return_values[1]
@@ -20,7 +20,7 @@ module RSpec
20
20
  @mock.message.should == @return_values[0]
21
21
  @mock.message.should == @return_values[1]
22
22
  expect { @mock.rspec_verify }.to raise_error(
23
- RSpec::Mocks::MockExpectationError,
23
+ RSpec::Mocks::MockExpectationError,
24
24
  %Q|(Mock "mock").message(any args)\n expected: 3 times\n received: 2 times|
25
25
  )
26
26
  end
@@ -31,10 +31,19 @@ module RSpec
31
31
  @mock.message.should == @return_values[2]
32
32
  @mock.message.should == @return_values[2]
33
33
  expect { @mock.rspec_verify }.to raise_error(
34
- RSpec::Mocks::MockExpectationError,
34
+ RSpec::Mocks::MockExpectationError,
35
35
  %Q|(Mock "mock").message(any args)\n expected: 3 times\n received: 4 times|
36
36
  )
37
37
  end
38
+
39
+ it "doesn't complain when there are too many calls but method is stubbed too" do
40
+ @mock.stub(:message).and_return :stub_result
41
+ @mock.message.should == @return_values[0]
42
+ @mock.message.should == @return_values[1]
43
+ @mock.message.should == @return_values[2]
44
+ @mock.message.should == :stub_result
45
+ expect { @mock.rspec_verify }.to_not raise_error(RSpec::Mocks::MockExpectationError)
46
+ end
38
47
  end
39
48
 
40
49
  describe "a Mock expectation with multiple return values with a specified count equal to the number of values" do
@@ -56,7 +65,7 @@ module RSpec
56
65
  @mock.message.should == @return_values[0]
57
66
  @mock.message.should == @return_values[1]
58
67
  expect { @mock.rspec_verify }.to raise_error(
59
- RSpec::Mocks::MockExpectationError,
68
+ RSpec::Mocks::MockExpectationError,
60
69
  %Q|(Mock "mock").message(any args)\n expected: 3 times\n received: 2 times|
61
70
  )
62
71
  end
@@ -68,7 +77,20 @@ module RSpec
68
77
  @mock.message.should == @return_values[2]
69
78
  @mock.message.should == @return_values[2]
70
79
  expect { @mock.rspec_verify }.to raise_error(
71
- RSpec::Mocks::MockExpectationError,
80
+ RSpec::Mocks::MockExpectationError,
81
+ %Q|(Mock "mock").message(any args)\n expected: 3 times\n received: 4 times|
82
+ )
83
+ end
84
+
85
+ it "complains when there are too many calls and method is stubbed too" do
86
+ third = Object.new
87
+ @mock.stub(:message).and_return :stub_result
88
+ @mock.message.should == @return_values[0]
89
+ @mock.message.should == @return_values[1]
90
+ @mock.message.should == @return_values[2]
91
+ @mock.message.should == :stub_result
92
+ expect { @mock.rspec_verify }.to raise_error(
93
+ RSpec::Mocks::MockExpectationError,
72
94
  %Q|(Mock "mock").message(any args)\n expected: 3 times\n received: 4 times|
73
95
  )
74
96
  end
@@ -79,7 +101,7 @@ module RSpec
79
101
  @mock = RSpec::Mocks::Mock.new("mock")
80
102
  @mock.should_receive(:message).at_least(:twice).with(no_args).and_return(11, 22)
81
103
  end
82
-
104
+
83
105
  it "uses the last return value for subsequent calls" do
84
106
  @mock.message.should equal(11)
85
107
  @mock.message.should equal(22)
@@ -90,10 +112,30 @@ module RSpec
90
112
  it "fails when called less than the specified number" do
91
113
  @mock.message.should equal(11)
92
114
  expect { @mock.rspec_verify }.to raise_error(
93
- RSpec::Mocks::MockExpectationError,
115
+ RSpec::Mocks::MockExpectationError,
94
116
  %Q|(Mock "mock").message(no args)\n expected: 2 times\n received: 1 time|
95
117
  )
96
118
  end
119
+
120
+ context "when method is stubbed too" do
121
+ before { @mock.stub(:message).and_return :stub_result }
122
+
123
+ it "uses the stub return value for subsequent calls" do
124
+ @mock.message.should equal(11)
125
+ @mock.message.should equal(22)
126
+ @mock.message.should equal(:stub_result)
127
+ @mock.rspec_verify
128
+ end
129
+
130
+ it "fails when called less than the specified number" do
131
+ @mock.message.should equal(11)
132
+ expect { @mock.rspec_verify }.to raise_error(
133
+ RSpec::Mocks::MockExpectationError,
134
+ %Q|(Mock "mock").message(no args)\n expected: 2 times\n received: 1 time|
135
+ )
136
+ end
137
+ end
138
+
97
139
  end
98
140
 
99
141
  describe "a Mock expectation with multiple return values with a specified count larger than the number of values" do
@@ -101,7 +143,7 @@ module RSpec
101
143
  @mock = RSpec::Mocks::Mock.new("mock")
102
144
  @mock.should_receive(:message).exactly(3).times.and_return(11, 22)
103
145
  end
104
-
146
+
105
147
  it "uses the last return value for subsequent calls" do
106
148
  @mock.message.should equal(11)
107
149
  @mock.message.should equal(22)
@@ -112,7 +154,7 @@ module RSpec
112
154
  it "fails when called less than the specified number" do
113
155
  @mock.message.should equal(11)
114
156
  expect { @mock.rspec_verify }.to raise_error(
115
- RSpec::Mocks::MockExpectationError,
157
+ RSpec::Mocks::MockExpectationError,
116
158
  %Q|(Mock "mock").message(any args)\n expected: 3 times\n received: 1 time|
117
159
  )
118
160
  end
@@ -123,10 +165,26 @@ module RSpec
123
165
  @mock.message.should equal(22)
124
166
  @mock.message.should equal(22)
125
167
  expect { @mock.rspec_verify }.to raise_error(
126
- RSpec::Mocks::MockExpectationError,
168
+ RSpec::Mocks::MockExpectationError,
127
169
  %Q|(Mock "mock").message(any args)\n expected: 3 times\n received: 4 times|
128
170
  )
129
171
  end
172
+
173
+ context "when method is stubbed too" do
174
+ before { @mock.stub(:message).and_return :stub_result }
175
+
176
+ it "fails when called greater than the specified number" do
177
+ @mock.message.should equal(11)
178
+ @mock.message.should equal(22)
179
+ @mock.message.should equal(22)
180
+ @mock.message.should equal(:stub_result)
181
+ expect { @mock.rspec_verify }.to raise_error(
182
+ RSpec::Mocks::MockExpectationError,
183
+ %Q|(Mock "mock").message(any args)\n expected: 3 times\n received: 4 times|
184
+ )
185
+ end
186
+
187
+ end
130
188
  end
131
189
  end
132
190
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-mocks
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 27
4
5
  prerelease: false
5
6
  segments:
6
7
  - 2
7
- - 4
8
+ - 5
8
9
  - 0
9
- version: 2.4.0
10
+ version: 2.5.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - David Chelimsky
@@ -15,7 +16,7 @@ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2011-01-02 00:00:00 -06:00
19
+ date: 2011-02-05 00:00:00 -06:00
19
20
  default_executable:
20
21
  dependencies: []
21
22
 
@@ -33,15 +34,15 @@ files:
33
34
  - .gitignore
34
35
  - Gemfile
35
36
  - Guardfile
36
- - History.markdown
37
37
  - License.txt
38
38
  - README.md
39
39
  - Rakefile
40
- - Upgrade.markdown
41
40
  - autotest/discover.rb
42
41
  - cucumber.yml
43
42
  - features/.nav
43
+ - features/Changelog.md
44
44
  - features/README.markdown
45
+ - features/Upgrade.md
45
46
  - features/message_expectations/README.md
46
47
  - features/message_expectations/block_local_expectations.feature.pending
47
48
  - features/message_expectations/expect_message.feature
@@ -132,7 +133,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
132
133
  requirements:
133
134
  - - ">="
134
135
  - !ruby/object:Gem::Version
135
- hash: 1914883193122525774
136
+ hash: 3
136
137
  segments:
137
138
  - 0
138
139
  version: "0"
@@ -141,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
142
  requirements:
142
143
  - - ">="
143
144
  - !ruby/object:Gem::Version
144
- hash: 1914883193122525774
145
+ hash: 3
145
146
  segments:
146
147
  - 0
147
148
  version: "0"
@@ -151,9 +152,11 @@ rubyforge_project: rspec
151
152
  rubygems_version: 1.3.7
152
153
  signing_key:
153
154
  specification_version: 3
154
- summary: rspec-mocks-2.4.0
155
+ summary: rspec-mocks-2.5.0
155
156
  test_files:
157
+ - features/Changelog.md
156
158
  - features/README.markdown
159
+ - features/Upgrade.md
157
160
  - features/message_expectations/README.md
158
161
  - features/message_expectations/block_local_expectations.feature.pending
159
162
  - features/message_expectations/expect_message.feature