mocha 0.9.4 → 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
data/RELEASE CHANGED
@@ -1,3 +1,9 @@
1
+ = 0.9.5 (93cad010345ce5d68f31422cfc32ed9dd6de13ec)
2
+ * Fixed Lighthouse bug #32 - stub_everything should mean mock responds to anything.
3
+ * Added Expectation#twice to improve readability. Tthanks to pull request from Celestino Gomes.
4
+ * In Ruby 1.9, requiring 'test/unit' loads a thin wrapper around MiniTest and Test::Unit::TestCase ends up inheriting from MiniTest::Unit::TestCase. So we need to avoid including the Mocha modules more than once to avoid nasty consequences. Thanks to Matthias Hennemeyer for help with this.
5
+ * Ruby 1.9 includes rake, but not rake/contrib. For the moment I've moved the sshpublisher require into the only rake task that needs it, so that I can at least run the tests in Ruby 1.9. It looks like I will need to build a rake/contrib gem or similar to get this working properly - http://intertwingly.net/blog/2008/01/07/Rake-Contrib-for-1-9
6
+
1
7
  = 0.9.4 (8a59c6ff0f99f34b02bd99f19536a7893be2b340)
2
8
  * Added mocha.gemspec file generated with Chad Woolley's new rake task, so that a floehopper-mocha gem will get built on GitHub.
3
9
  * Add rake task to update mocha.gemspec with unique version, which will cause gem to be auto-built on github
@@ -5,7 +11,7 @@
5
11
  * Removed deprecated gem autorequire.
6
12
 
7
13
  = 0.9.3 (8219bb2d2881c8529c93fc21e97a11d01203c759)
8
- * Added support for MiniTest thanks to sprsquish.
14
+ * Added support for MiniTest thanks to Jeff Smick.
9
15
  * Fixed a possible bug with some of the non-default Configuration options relating to the argument to Object#respond_to?
10
16
  * As per Jay Fields recommendations [1] and with further impetus from a talk at Ruby Manor, any methods added to core classes are now added by including a module. This means that Mocha is a better citizen of the Ruby world and it's behaviour is more easily extended. [1] http://blog.jayfields.com/2008/07/ruby-underuse-of-modules.html & http://blog.jayfields.com/2008/07/ruby-redefine-method-behavior.html
11
17
  * Removed deprecated gem autorequire.
data/Rakefile CHANGED
@@ -2,10 +2,9 @@ require 'rubygems'
2
2
  require 'rake/rdoctask'
3
3
  require 'rake/gempackagetask'
4
4
  require 'rake/testtask'
5
- require 'rake/contrib/sshpublisher'
6
5
 
7
6
  module Mocha
8
- VERSION = "0.9.4"
7
+ VERSION = "0.9.5"
9
8
  end
10
9
 
11
10
  desc "Run all tests"
@@ -84,10 +83,13 @@ Rake::RDocTask.new('rdoc') do |task|
84
83
  'lib/mocha/stubbing_error.rb'
85
84
  )
86
85
  end
87
- task 'rdoc' => 'examples'
86
+
87
+ desc "Generate all documentation"
88
+ task 'generate_docs' => ['clobber_rdoc', 'rdoc', 'examples', 'agiledox.txt']
88
89
 
89
90
  desc "Upload RDoc to RubyForge"
90
- task 'publish_rdoc' => ['rdoc', 'examples'] do
91
+ task 'publish_docs' do
92
+ require 'rake/contrib/sshpublisher'
91
93
  Rake::SshDirPublisher.new("jamesmead@rubyforge.org", "/var/www/gforge-projects/mocha", "doc").upload
92
94
  end
93
95
 
@@ -168,7 +170,6 @@ task :update_gemspec do
168
170
  end
169
171
  end
170
172
 
171
-
172
173
  task 'verify_user' do
173
174
  raise "RUBYFORGE_USER environment variable not set!" unless ENV['RUBYFORGE_USER']
174
175
  end
@@ -178,7 +179,7 @@ task 'verify_password' do
178
179
  end
179
180
 
180
181
  desc "Publish package files on RubyForge."
181
- task 'publish_packages' => ['verify_user', 'verify_password', 'package'] do
182
+ task 'publish_packages' => ['verify_user', 'verify_password', 'clobber_package', 'package'] do
182
183
  $:.unshift File.expand_path(File.join(File.dirname(__FILE__), "vendor", "meta_project-0.4.15", "lib"))
183
184
  require 'meta_project'
184
185
  require 'rake/contrib/xforge'
@@ -197,3 +198,10 @@ task 'publish_packages' => ['verify_user', 'verify_password', 'package'] do
197
198
  release.release_notes = ''
198
199
  end
199
200
  end
201
+
202
+ desc "Do a full release."
203
+ task 'release' => ['default', 'generate_docs', 'publish_packages', 'publish_docs', 'update_gemspec'] do
204
+ puts
205
+ puts "*** Remember to commit newly generated gemspec after release ***"
206
+ puts
207
+ end
@@ -37,11 +37,13 @@ end
37
37
  require 'mocha/test_case_adapter'
38
38
  require 'test/unit/testcase'
39
39
 
40
- module Test
41
- module Unit
42
- class TestCase
43
- include Mocha::Standalone
44
- include Mocha::TestCaseAdapter
40
+ unless Test::Unit::TestCase.ancestors.include?(Mocha::Standalone)
41
+ module Test
42
+ module Unit
43
+ class TestCase
44
+ include Mocha::Standalone
45
+ include Mocha::TestCaseAdapter
46
+ end
45
47
  end
46
48
  end
47
49
  end
@@ -17,7 +17,7 @@ module Mocha
17
17
  def hide_original_method
18
18
  if method_exists?(method)
19
19
  begin
20
- stubbee.class_eval("alias_method :#{hidden_method}, :#{method}", __FILE__, __LINE__)
20
+ stubbee.send(:alias_method, hidden_method, method)
21
21
  rescue NameError
22
22
  # deal with nasties like ActiveRecord::Associations::AssociationProxy
23
23
  end
@@ -29,13 +29,14 @@ module Mocha
29
29
  end
30
30
 
31
31
  def remove_new_method
32
- stubbee.class_eval("remove_method :#{method}", __FILE__, __LINE__)
32
+ stubbee.send(:remove_method, method)
33
33
  end
34
34
 
35
35
  def restore_original_method
36
36
  if method_exists?(hidden_method)
37
37
  begin
38
- stubbee.class_eval("alias_method :#{method}, :#{hidden_method}; remove_method :#{hidden_method}", __FILE__, __LINE__)
38
+ stubbee.send(:alias_method, method, hidden_method)
39
+ stubbee.send(:remove_method, hidden_method)
39
40
  rescue NameError
40
41
  # deal with nasties like ActiveRecord::Associations::AssociationProxy
41
42
  end
@@ -29,7 +29,7 @@ module Mocha
29
29
  def hide_original_method
30
30
  if method_exists?(method)
31
31
  begin
32
- stubbee.__metaclass__.class_eval("alias_method :#{hidden_method}, :#{method}", __FILE__, __LINE__)
32
+ stubbee.__metaclass__.send(:alias_method, hidden_method, method)
33
33
  rescue NameError
34
34
  # deal with nasties like ActiveRecord::Associations::AssociationProxy
35
35
  end
@@ -41,13 +41,14 @@ module Mocha
41
41
  end
42
42
 
43
43
  def remove_new_method
44
- stubbee.__metaclass__.class_eval("remove_method :#{method}", __FILE__, __LINE__)
44
+ stubbee.__metaclass__.send(:remove_method, method)
45
45
  end
46
46
 
47
47
  def restore_original_method
48
48
  if method_exists?(hidden_method)
49
49
  begin
50
- stubbee.__metaclass__.class_eval("alias_method :#{method}, :#{hidden_method}; remove_method :#{hidden_method}", __FILE__, __LINE__)
50
+ stubbee.__metaclass__.send(:alias_method, method, hidden_method)
51
+ stubbee.__metaclass__.send(:remove_method, hidden_method)
51
52
  rescue NameError
52
53
  # deal with nasties like ActiveRecord::Associations::AssociationProxy
53
54
  end
@@ -43,6 +43,31 @@ module Mocha # :nodoc:
43
43
  self
44
44
  end
45
45
 
46
+ # :call-seq: twice() -> expectation
47
+ #
48
+ # Modifies expectation so that the expected method must be called exactly twice.
49
+ # object = mock()
50
+ # object.expects(:expected_method).twice
51
+ # object.expected_method
52
+ # object.expected_method
53
+ # # => verify succeeds
54
+ #
55
+ # object = mock()
56
+ # object.expects(:expected_method).twice
57
+ # object.expected_method
58
+ # object.expected_method
59
+ # object.expected_method
60
+ # # => verify fails
61
+ #
62
+ # object = mock()
63
+ # object.expects(:expected_method).twice
64
+ # object.expected_method
65
+ # # => verify fails
66
+ def twice
67
+ @cardinality = Cardinality.exactly(2)
68
+ self
69
+ end
70
+
46
71
  # :call-seq: once() -> expectation
47
72
  #
48
73
  # Modifies expectation so that the expected method must be called exactly once.
@@ -173,7 +173,7 @@ module Mocha # :nodoc:
173
173
  @responder.respond_to?(symbol)
174
174
  end
175
175
  else
176
- @expectations.matches_method?(symbol)
176
+ @everything_stubbed || @expectations.matches_method?(symbol)
177
177
  end
178
178
  end
179
179
 
@@ -35,7 +35,7 @@ class ExpectedInvocationCountTest < Test::Unit::TestCase
35
35
  def test_should_pass_if_method_is_expected_twice_and_is_called_twice
36
36
  test_result = run_test do
37
37
  mock = mock('mock')
38
- mock.expects(:method).times(2)
38
+ mock.expects(:method).twice
39
39
  2.times { mock.method }
40
40
  end
41
41
  assert_passed(test_result)
@@ -44,7 +44,7 @@ class ExpectedInvocationCountTest < Test::Unit::TestCase
44
44
  def test_should_fail_if_method_is_expected_twice_but_is_called_once
45
45
  test_result = run_test do
46
46
  mock = mock('mock')
47
- mock.expects(:method).times(2)
47
+ mock.expects(:method).twice
48
48
  1.times { mock.method }
49
49
  end
50
50
  assert_failed(test_result)
@@ -54,7 +54,7 @@ class ExpectedInvocationCountTest < Test::Unit::TestCase
54
54
  def test_should_fail_fast_if_method_is_expected_twice_but_is_called_three_times
55
55
  test_result = run_test do
56
56
  mock = mock('mock')
57
- mock.expects(:method).times(2)
57
+ mock.expects(:method).twice
58
58
  3.times { mock.method }
59
59
  end
60
60
  assert_failed(test_result)
@@ -253,6 +253,27 @@ class ExpectationTest < Test::Unit::TestCase
253
253
  assert expectation.verified?
254
254
  end
255
255
 
256
+ def test_should_not_verify_successfully_if_call_expected_twice_and_invoked_three_times
257
+ expectation = new_expectation.twice
258
+ expectation.invoke
259
+ expectation.invoke
260
+ expectation.invoke
261
+ assert !expectation.verified?
262
+ end
263
+
264
+ def test_should_not_verify_successfully_if_call_expected_twice_but_invoked_once
265
+ expectation = new_expectation.twice
266
+ expectation.invoke
267
+ assert !expectation.verified?
268
+ end
269
+
270
+ def test_should_verify_successfully_if_call_expected_twice_and_invoked_twice
271
+ expectation = new_expectation.twice
272
+ expectation.invoke
273
+ expectation.invoke
274
+ assert expectation.verified?
275
+ end
276
+
256
277
  def test_should_verify_successfully_if_expected_call_was_made_at_least_once
257
278
  expectation = new_expectation.at_least_once
258
279
  3.times {expectation.invoke}
@@ -292,4 +292,11 @@ class MockTest < Test::Unit::TestCase
292
292
  assert_nothing_raised{ mock.respond_to?(:object_id, false) }
293
293
  end
294
294
 
295
+ def test_should_respond_to_any_method_if_stubbing_everything
296
+ mock = Mock.new
297
+ mock.stub_everything
298
+ assert mock.respond_to?(:abc)
299
+ assert mock.respond_to?(:xyz)
300
+ end
301
+
295
302
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mocha
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.4
4
+ version: 0.9.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Mead
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-30 00:00:00 +00:00
12
+ date: 2009-02-01 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency