mocha 0.11.4 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- = Mocha {<img src="https://secure.travis-ci.org/floehopper/mocha.png" />}[http://travis-ci.org/floehopper/mocha]
1
+ = Mocha {<img src="https://secure.travis-ci.org/freerange/mocha.png" />}[http://travis-ci.org/freerange/mocha]
2
2
 
3
3
  Mocha is a library for mocking and stubbing using a syntax like that of {JMock}[http://www.jmock.org].
4
4
 
@@ -1,3 +1,11 @@
1
+ = 0.12.0
2
+ * Fail fast if neither Test::Unit nor MiniTest is loaded. Fixes #40.
3
+ * Officially support MiniTest up to v3.2.0 (still monkey-patching).
4
+ * Officially support test-unit v2.5.0 (still monkey-patching).
5
+ * Do not monkey-patch Test::Unit or MiniTest unless we *know* it's ok.
6
+ * Add acceptance tests to demonstrate using a block as a custom parameter matcher.
7
+ * Update Travis CI build status image to use the new build under the freerange account.
8
+
1
9
  = 0.11.4
2
10
  * Homepage has moved to http://gofreerange.com/mocha/docs.
3
11
 
data/Rakefile CHANGED
@@ -116,7 +116,8 @@ task 'generate_docs' => ['clobber_yardoc', 'yardoc']
116
116
 
117
117
  desc "Publish docs to Github (relies on running 'generate_docs' task and committing changes to master branch)"
118
118
  task 'publish_docs' do
119
- `scp -r doc/* gofreerange.com:/home/freerange/docs/mocha && ssh gofreerange.com "sudo su - freerange -c 'sudo chmod -R g+w /home/freerange/docs/mocha'"`
119
+ path = "/home/freerange/docs/mocha"
120
+ system %{ssh gofreerange.com "sudo rm -fr #{path} && mkdir -p #{path}" && scp -r doc/* gofreerange.com:#{path}}
120
121
  end
121
122
 
122
123
  task 'release' => 'default' do
@@ -0,0 +1,7 @@
1
+ source :rubygems
2
+
3
+ gemspec :path=>"../"
4
+
5
+ group :development do
6
+ gem "minitest", "2.11.0"
7
+ end
@@ -0,0 +1,7 @@
1
+ source :rubygems
2
+
3
+ gemspec :path=>"../"
4
+
5
+ group :development do
6
+ gem "minitest", "2.11.2"
7
+ end
@@ -1,4 +1,4 @@
1
1
  require 'mocha/version'
2
+ require 'mocha/integration'
2
3
  require 'mocha_standalone'
3
4
  require 'mocha/configuration'
4
- require 'mocha/integration'
@@ -1,3 +1,5 @@
1
+ require 'mocha/options'
2
+
1
3
  module Mocha
2
4
 
3
5
  module Integration
@@ -9,22 +11,22 @@ module Mocha
9
11
  if test_unit_testcase_defined? && !test_unit_testcase_inherits_from_miniunit_testcase?
10
12
  patches << 'mocha/integration/test_unit'
11
13
  end
12
- if mini_unit_testcase_defined?
14
+ if mini_test_testcase_defined?
13
15
  patches << 'mocha/integration/mini_test'
14
16
  end
15
17
  patches
16
18
  end
17
19
 
18
20
  def test_unit_testcase_defined?
19
- defined?(Test) && defined?(Test::Unit) && defined?(Test::Unit::TestCase)
21
+ defined?(Test::Unit::TestCase)
20
22
  end
21
23
 
22
- def mini_unit_testcase_defined?
23
- defined?(MiniTest) && defined?(MiniTest::Unit) && defined?(MiniTest::Unit::TestCase)
24
+ def mini_test_testcase_defined?
25
+ defined?(MiniTest::Unit::TestCase)
24
26
  end
25
27
 
26
28
  def test_unit_testcase_inherits_from_miniunit_testcase?
27
- test_unit_testcase_defined? && mini_unit_testcase_defined? && Test::Unit::TestCase.ancestors.include?(MiniTest::Unit::TestCase)
29
+ test_unit_testcase_defined? && mini_test_testcase_defined? && Test::Unit::TestCase.ancestors.include?(MiniTest::Unit::TestCase)
28
30
  end
29
31
 
30
32
  end
@@ -33,6 +35,10 @@ module Mocha
33
35
 
34
36
  end
35
37
 
38
+ unless Mocha::Integration.monkey_patches.any? || $mocha_options["skip_integration"]
39
+ raise "Test::Unit or MiniTest must be loaded *before* Mocha (use MOCHA_OPTIONS=skip_integration if you know what you are doing)."
40
+ end
41
+
36
42
  Mocha::Integration.monkey_patches.each do |patch|
37
43
  require patch
38
44
  end
@@ -10,7 +10,9 @@ if !MiniTest::Unit::TestCase.ancestors.include?(Mocha::API)
10
10
  require 'mocha/integration/mini_test/version_142_to_172'
11
11
  require 'mocha/integration/mini_test/version_200'
12
12
  require 'mocha/integration/mini_test/version_201_to_222'
13
- require 'mocha/integration/mini_test/version_230_to_262'
13
+ require 'mocha/integration/mini_test/version_230_to_2101'
14
+ require 'mocha/integration/mini_test/version_2110_to_2111'
15
+ require 'mocha/integration/mini_test/version_2112_to_320'
14
16
 
15
17
  module MiniTest
16
18
  class Unit
@@ -41,9 +43,12 @@ if !MiniTest::Unit::TestCase.ancestors.include?(Mocha::API)
41
43
  include Mocha::Integration::MiniTest::Version200
42
44
  elsif Gem::Requirement.new('>= 2.0.1', '<= 2.2.2').satisfied_by?(mini_test_version)
43
45
  include Mocha::Integration::MiniTest::Version201To222
44
- elsif Gem::Requirement.new('>= 2.3.0').satisfied_by?(mini_test_version)
45
- $stderr.puts "*** MiniTest integration has not been verified but patching anyway ***" if (Gem::Requirement.new('> 2.6.2').satisfied_by?(mini_test_version)) && $mocha_options['debug']
46
- include Mocha::Integration::MiniTest::Version230To262
46
+ elsif Gem::Requirement.new('>= 2.3.0', '<= 2.10.1').satisfied_by?(mini_test_version)
47
+ include Mocha::Integration::MiniTest::Version230To2101
48
+ elsif Gem::Requirement.new('>= 2.11.0', '<= 2.11.1').satisfied_by?(mini_test_version)
49
+ include Mocha::Integration::MiniTest::Version2110To2111
50
+ elsif Gem::Requirement.new('>= 2.11.2', '<= 3.2.0').satisfied_by?(mini_test_version)
51
+ include Mocha::Integration::MiniTest::Version2112To320
47
52
  else
48
53
  $stderr.puts "*** No Mocha integration for MiniTest version ***" if $mocha_options['debug']
49
54
  end
@@ -0,0 +1,61 @@
1
+ require 'mocha/integration/mini_test/assertion_counter'
2
+ require 'mocha/expectation_error'
3
+
4
+ module Mocha
5
+
6
+ module Integration
7
+
8
+ module MiniTest
9
+
10
+ module Version2110To2111
11
+ def self.included(mod)
12
+ $stderr.puts "Monkey patching MiniTest >= v2.11.0 <= v2.11.1" if $mocha_options['debug']
13
+ end
14
+ def run runner
15
+ trap 'INFO' do
16
+ time = runner.start_time ? Time.now - runner.start_time : 0
17
+ warn "%s#%s %.2fs" % [self.class, self.__name__, time]
18
+ runner.status $stderr
19
+ end if ::MiniTest::Unit::TestCase::SUPPORTS_INFO_SIGNAL
20
+
21
+ assertion_counter = AssertionCounter.new(self)
22
+ result = ""
23
+ begin
24
+ begin
25
+ @passed = nil
26
+ self.before_setup
27
+ self.setup
28
+ self.after_setup
29
+ self.run_test self.__name__
30
+ mocha_verify(assertion_counter)
31
+ result = "." unless io?
32
+ @passed = true
33
+ rescue *::MiniTest::Unit::TestCase::PASSTHROUGH_EXCEPTIONS
34
+ raise
35
+ rescue Exception => e
36
+ @passed = false
37
+ result = runner.puke self.class, self.__name__, Mocha::Integration::MiniTest.translate(e)
38
+ ensure
39
+ %w{ before_teardown teardown after_teardown }.each do |hook|
40
+ begin
41
+ self.send hook
42
+ rescue *::MiniTest::Unit::TestCase::PASSTHROUGH_EXCEPTIONS
43
+ raise
44
+ rescue Exception => e
45
+ result = runner.puke self.class, self.__name__, Mocha::Integration::MiniTest.translate(e)
46
+ end
47
+ end
48
+ trap 'INFO', 'DEFAULT' if ::MiniTest::Unit::TestCase::SUPPORTS_INFO_SIGNAL
49
+ end
50
+ ensure
51
+ mocha_teardown
52
+ end
53
+ result
54
+ end
55
+ end
56
+
57
+ end
58
+
59
+ end
60
+
61
+ end
@@ -0,0 +1,64 @@
1
+ require 'mocha/integration/mini_test/assertion_counter'
2
+ require 'mocha/expectation_error'
3
+
4
+ module Mocha
5
+
6
+ module Integration
7
+
8
+ module MiniTest
9
+
10
+ module Version2112To320
11
+ def self.included(mod)
12
+ $stderr.puts "Monkey patching MiniTest >= v2.11.2 <= v3.2.0" if $mocha_options['debug']
13
+ end
14
+ def run runner
15
+ trap "INFO" do
16
+ runner.report.each_with_index do |msg, i|
17
+ warn "\n%3d) %s" % [i + 1, msg]
18
+ end
19
+ warn ''
20
+ time = runner.start_time ? Time.now - runner.start_time : 0
21
+ warn "Current Test: %s#%s %.2fs" % [self.class, self.__name__, time]
22
+ runner.status $stderr
23
+ end if ::MiniTest::Unit::TestCase::SUPPORTS_INFO_SIGNAL
24
+ assertion_counter = AssertionCounter.new(self)
25
+ result = ""
26
+ begin
27
+ begin
28
+ @passed = nil
29
+ self.before_setup
30
+ self.setup
31
+ self.after_setup
32
+ self.run_test self.__name__
33
+ mocha_verify(assertion_counter)
34
+ result = "." unless io?
35
+ @passed = true
36
+ rescue *::MiniTest::Unit::TestCase::PASSTHROUGH_EXCEPTIONS
37
+ raise
38
+ rescue Exception => e
39
+ @passed = false
40
+ result = runner.puke self.class, self.__name__, Mocha::Integration::MiniTest.translate(e)
41
+ ensure
42
+ %w{ before_teardown teardown after_teardown }.each do |hook|
43
+ begin
44
+ self.send hook
45
+ rescue *::MiniTest::Unit::TestCase::PASSTHROUGH_EXCEPTIONS
46
+ raise
47
+ rescue Exception => e
48
+ result = runner.puke self.class, self.__name__, Mocha::Integration::MiniTest.translate(e)
49
+ end
50
+ end
51
+ trap 'INFO', 'DEFAULT' if ::MiniTest::Unit::TestCase::SUPPORTS_INFO_SIGNAL
52
+ end
53
+ ensure
54
+ mocha_teardown
55
+ end
56
+ result
57
+ end
58
+ end
59
+
60
+ end
61
+
62
+ end
63
+
64
+ end
@@ -7,9 +7,9 @@ module Mocha
7
7
 
8
8
  module MiniTest
9
9
 
10
- module Version230To262
10
+ module Version230To2101
11
11
  def self.included(mod)
12
- $stderr.puts "Monkey patching MiniTest >= v2.3.0 <= v2.6.2" if $mocha_options['debug']
12
+ $stderr.puts "Monkey patching MiniTest >= v2.3.0 <= v2.10.1" if $mocha_options['debug']
13
13
  end
14
14
  def run runner
15
15
  trap 'INFO' do
@@ -6,7 +6,7 @@ if !Test::Unit::TestCase.ancestors.include?(Mocha::API)
6
6
  require 'mocha/integration/test_unit/gem_version_200'
7
7
  require 'mocha/integration/test_unit/gem_version_201_to_202'
8
8
  require 'mocha/integration/test_unit/gem_version_203_to_220'
9
- require 'mocha/integration/test_unit/gem_version_230_to_240'
9
+ require 'mocha/integration/test_unit/gem_version_230_to_250'
10
10
  require 'mocha/integration/test_unit/ruby_version_185_and_below'
11
11
  require 'mocha/integration/test_unit/ruby_version_186_and_above'
12
12
 
@@ -43,9 +43,8 @@ if !Test::Unit::TestCase.ancestors.include?(Mocha::API)
43
43
  include Mocha::Integration::TestUnit::GemVersion201To202
44
44
  elsif Gem::Requirement.new('>= 2.0.3', '<= 2.2.0').satisfied_by?(test_unit_version)
45
45
  include Mocha::Integration::TestUnit::GemVersion203To220
46
- elsif Gem::Requirement.new('>= 2.3.0').satisfied_by?(test_unit_version)
47
- $stderr.puts "*** Test::Unit integration has not been verified but patching anyway ***" if (Gem::Requirement.new('> 2.4.0').satisfied_by?(test_unit_version)) && $mocha_options['debug']
48
- include Mocha::Integration::TestUnit::GemVersion230To240
46
+ elsif Gem::Requirement.new('>= 2.3.0', '<= 2.5.0').satisfied_by?(test_unit_version)
47
+ include Mocha::Integration::TestUnit::GemVersion230To250
49
48
  else
50
49
  $stderr.puts "*** No Mocha integration for Test::Unit version ***" if $mocha_options['debug']
51
50
  end
@@ -8,9 +8,9 @@ module Mocha
8
8
 
9
9
  module TestUnit
10
10
 
11
- module GemVersion230To240
11
+ module GemVersion230To250
12
12
  def self.included(mod)
13
- $stderr.puts "Monkey patching Test::Unit gem >= v2.3.0 and <= v2.4.0" if $mocha_options['debug']
13
+ $stderr.puts "Monkey patching Test::Unit gem >= v2.3.0 and <= v2.5.0" if $mocha_options['debug']
14
14
  end
15
15
  def run(result)
16
16
  assertion_counter = AssertionCounter.new(result)
@@ -1,3 +1,3 @@
1
1
  module Mocha
2
- VERSION = "0.11.4"
2
+ VERSION = "0.12.0"
3
3
  end
@@ -297,4 +297,41 @@ class ParameterMatcherTest < Test::Unit::TestCase
297
297
  assert_passed(test_result)
298
298
  end
299
299
 
300
+ def test_should_match_parameter_when_value_is_divisible_by_four
301
+ test_result = run_as_test do
302
+ mock = mock()
303
+ mock.expects(:method).with { |actual_value| actual_value % 4 == 0 }
304
+ mock.method(8)
305
+ end
306
+ assert_passed(test_result)
307
+ end
308
+
309
+ def test_should_not_match_parameter_when_value_is_not_divisible_by_four
310
+ test_result = run_as_test do
311
+ mock = mock()
312
+ mock.expects(:method).with { |actual_value| actual_value % 4 == 0 }
313
+ mock.method(9)
314
+ end
315
+ assert_failed(test_result)
316
+ end
317
+
318
+ def test_should_match_parameters_when_values_add_up_to_ten
319
+ test_result = run_as_test do
320
+ mock = mock()
321
+ matcher = lambda { |*values| values.inject(0) { |sum, n| sum + n } == 10 }
322
+ mock.expects(:method).with(&matcher)
323
+ mock.method(1, 2, 3, 4)
324
+ end
325
+ assert_passed(test_result)
326
+ end
327
+
328
+ def test_should_not_match_parameters_when_values_do_not_add_up_to_ten
329
+ test_result = run_as_test do
330
+ mock = mock()
331
+ matcher = lambda { |*values| values.inject(0) { |sum, n| sum + n } == 10 }
332
+ mock.expects(:method).with(&matcher)
333
+ mock.method(1, 2, 3, 4, 5)
334
+ end
335
+ assert_failed(test_result)
336
+ end
300
337
  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.11.4
4
+ version: 0.12.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-04 00:00:00.000000000 Z
12
+ date: 2012-07-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: metaclass
16
- requirement: &70132715601560 !ruby/object:Gem::Requirement
16
+ requirement: &70238404164500 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.0.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70132715601560
24
+ version_requirements: *70238404164500
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &70132715600240 !ruby/object:Gem::Requirement
27
+ requirement: &70238404163180 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70132715600240
35
+ version_requirements: *70238404163180
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: introspection
38
- requirement: &70132715599780 !ruby/object:Gem::Requirement
38
+ requirement: &70238404162720 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.0.1
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70132715599780
46
+ version_requirements: *70238404162720
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: yard
49
- requirement: &70132715599400 !ruby/object:Gem::Requirement
49
+ requirement: &70238404162340 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70132715599400
57
+ version_requirements: *70238404162340
58
58
  description: Mocking and stubbing library with JMock/SchMock syntax, which allows
59
59
  mocking and stubbing of methods on real (non-mock) classes.
60
60
  email: mocha-developer@googlegroups.com
@@ -80,6 +80,8 @@ files:
80
80
  - gemfiles/Gemfile.minitest.1.4.2
81
81
  - gemfiles/Gemfile.minitest.2.0.0
82
82
  - gemfiles/Gemfile.minitest.2.0.1
83
+ - gemfiles/Gemfile.minitest.2.11.0
84
+ - gemfiles/Gemfile.minitest.2.11.2
83
85
  - gemfiles/Gemfile.minitest.2.3.0
84
86
  - gemfiles/Gemfile.minitest.latest
85
87
  - gemfiles/Gemfile.test-unit.2.0.0
@@ -115,13 +117,15 @@ files:
115
117
  - lib/mocha/integration/mini_test/version_142_to_172.rb
116
118
  - lib/mocha/integration/mini_test/version_200.rb
117
119
  - lib/mocha/integration/mini_test/version_201_to_222.rb
118
- - lib/mocha/integration/mini_test/version_230_to_262.rb
120
+ - lib/mocha/integration/mini_test/version_2110_to_2111.rb
121
+ - lib/mocha/integration/mini_test/version_2112_to_320.rb
122
+ - lib/mocha/integration/mini_test/version_230_to_2101.rb
119
123
  - lib/mocha/integration/test_unit.rb
120
124
  - lib/mocha/integration/test_unit/assertion_counter.rb
121
125
  - lib/mocha/integration/test_unit/gem_version_200.rb
122
126
  - lib/mocha/integration/test_unit/gem_version_201_to_202.rb
123
127
  - lib/mocha/integration/test_unit/gem_version_203_to_220.rb
124
- - lib/mocha/integration/test_unit/gem_version_230_to_240.rb
128
+ - lib/mocha/integration/test_unit/gem_version_230_to_250.rb
125
129
  - lib/mocha/integration/test_unit/ruby_version_185_and_below.rb
126
130
  - lib/mocha/integration/test_unit/ruby_version_186_and_above.rb
127
131
  - lib/mocha/is_a.rb
@@ -306,7 +310,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
306
310
  version: '0'
307
311
  segments:
308
312
  - 0
309
- hash: -1391677123881760922
313
+ hash: -586468752341133139
310
314
  required_rubygems_version: !ruby/object:Gem::Requirement
311
315
  none: false
312
316
  requirements: