mocha 1.14.0 → 2.0.0.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/Gemfile +3 -5
  4. data/README.md +1 -1
  5. data/RELEASE.md +52 -0
  6. data/Rakefile +19 -20
  7. data/gemfiles/Gemfile.test-unit.latest +1 -5
  8. data/lib/mocha/any_instance_method.rb +0 -5
  9. data/lib/mocha/api.rb +29 -78
  10. data/lib/mocha/class_methods.rb +2 -2
  11. data/lib/mocha/configuration.rb +30 -108
  12. data/lib/mocha/expectation.rb +55 -7
  13. data/lib/mocha/inspect.rb +2 -2
  14. data/lib/mocha/instance_method.rb +0 -4
  15. data/lib/mocha/integration/mini_test.rb +10 -38
  16. data/lib/mocha/integration/test_unit/adapter.rb +1 -1
  17. data/lib/mocha/integration/test_unit.rb +10 -33
  18. data/lib/mocha/invocation.rb +12 -16
  19. data/lib/mocha/minitest.rb +2 -4
  20. data/lib/mocha/mock.rb +22 -26
  21. data/lib/mocha/mockery.rb +1 -3
  22. data/lib/mocha/parameter_matchers/equivalent_uri.rb +0 -1
  23. data/lib/mocha/parameter_matchers/instance_methods.rb +9 -0
  24. data/lib/mocha/parameter_matchers/positional_or_keyword_hash.rb +56 -0
  25. data/lib/mocha/parameters_matcher.rb +0 -1
  26. data/lib/mocha/ruby_version.rb +1 -2
  27. data/lib/mocha/stubbed_method.rb +5 -42
  28. data/lib/mocha/test_unit.rb +2 -4
  29. data/lib/mocha/version.rb +1 -1
  30. data/lib/mocha.rb +0 -8
  31. data/mocha.gemspec +1 -1
  32. metadata +7 -27
  33. data/init.rb +0 -1
  34. data/lib/mocha/integration/mini_test/nothing.rb +0 -19
  35. data/lib/mocha/integration/mini_test/version_13.rb +0 -54
  36. data/lib/mocha/integration/mini_test/version_140.rb +0 -54
  37. data/lib/mocha/integration/mini_test/version_141.rb +0 -65
  38. data/lib/mocha/integration/mini_test/version_142_to_172.rb +0 -65
  39. data/lib/mocha/integration/mini_test/version_200.rb +0 -66
  40. data/lib/mocha/integration/mini_test/version_201_to_222.rb +0 -66
  41. data/lib/mocha/integration/mini_test/version_2110_to_2111.rb +0 -70
  42. data/lib/mocha/integration/mini_test/version_2112_to_320.rb +0 -73
  43. data/lib/mocha/integration/mini_test/version_230_to_2101.rb +0 -68
  44. data/lib/mocha/integration/test_unit/gem_version_200.rb +0 -62
  45. data/lib/mocha/integration/test_unit/gem_version_201_to_202.rb +0 -62
  46. data/lib/mocha/integration/test_unit/gem_version_203_to_220.rb +0 -62
  47. data/lib/mocha/integration/test_unit/gem_version_230_to_250.rb +0 -68
  48. data/lib/mocha/integration/test_unit/nothing.rb +0 -19
  49. data/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb +0 -61
  50. data/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb +0 -63
  51. data/lib/mocha/integration.rb +0 -11
  52. data/lib/mocha/setup.rb +0 -14
  53. data/lib/mocha/singleton_class.rb +0 -9
@@ -1,68 +0,0 @@
1
- require 'mocha/integration/assertion_counter'
2
- require 'mocha/integration/monkey_patcher'
3
- require 'mocha/integration/mini_test/exception_translation'
4
-
5
- module Mocha
6
- module Integration
7
- module MiniTest
8
- module Version230To2101
9
- def self.applicable_to?(mini_test_version)
10
- Gem::Requirement.new('>= 2.3.0', '<= 2.10.1').satisfied_by?(mini_test_version)
11
- end
12
-
13
- def self.description
14
- 'monkey patch for MiniTest gem >= v2.3.0 <= v2.10.1'
15
- end
16
-
17
- def self.included(mod)
18
- MonkeyPatcher.apply(mod, RunMethodPatch)
19
- end
20
-
21
- module RunMethodPatch
22
- # rubocop:disable all
23
- def run runner
24
- trap 'INFO' do
25
- time = runner.start_time ? Time.now - runner.start_time : 0
26
- warn "%s#%s %.2fs" % [self.class, self.__name__, time]
27
- runner.status $stderr
28
- end if ::MiniTest::Unit::TestCase::SUPPORTS_INFO_SIGNAL
29
-
30
- assertion_counter = AssertionCounter.new(self)
31
- result = ""
32
- begin
33
- begin
34
- @passed = nil
35
- mocha_setup
36
- self.setup
37
- self.run_setup_hooks
38
- self.__send__ self.__name__
39
- mocha_verify(assertion_counter)
40
- result = "." unless io?
41
- @passed = true
42
- rescue *::MiniTest::Unit::TestCase::PASSTHROUGH_EXCEPTIONS
43
- raise
44
- rescue Exception => e
45
- @passed = false
46
- result = runner.puke self.class, self.__name__, Mocha::Integration::MiniTest.translate(e)
47
- ensure
48
- begin
49
- self.run_teardown_hooks
50
- self.teardown
51
- rescue *::MiniTest::Unit::TestCase::PASSTHROUGH_EXCEPTIONS
52
- raise
53
- rescue Exception => e
54
- result = runner.puke self.class, self.__name__, Mocha::Integration::MiniTest.translate(e)
55
- end
56
- trap 'INFO', 'DEFAULT' if ::MiniTest::Unit::TestCase::SUPPORTS_INFO_SIGNAL
57
- end
58
- ensure
59
- mocha_teardown
60
- end
61
- result
62
- end
63
- # rubocop:enable all
64
- end
65
- end
66
- end
67
- end
68
- end
@@ -1,62 +0,0 @@
1
- require 'mocha/integration/assertion_counter'
2
- require 'mocha/integration/monkey_patcher'
3
- require 'mocha/expectation_error'
4
-
5
- module Mocha
6
- module Integration
7
- module TestUnit
8
- module GemVersion200
9
- def self.applicable_to?(test_unit_version, _ruby_version = nil)
10
- Gem::Requirement.new('2.0.0').satisfied_by?(test_unit_version)
11
- end
12
-
13
- def self.description
14
- 'monkey patch for Test::Unit gem v2.0.0'
15
- end
16
-
17
- def self.included(mod)
18
- MonkeyPatcher.apply(mod, RunMethodPatch)
19
- end
20
-
21
- module RunMethodPatch
22
- # rubocop:disable all
23
- def run(result)
24
- assertion_counter = AssertionCounter.new(self)
25
- begin
26
- @_result = result
27
- yield(Test::Unit::TestCase::STARTED, name)
28
- begin
29
- begin
30
- mocha_setup
31
- run_setup
32
- __send__(@method_name)
33
- mocha_verify(assertion_counter)
34
- rescue Mocha::ExpectationError => e
35
- add_failure(e.message, e.backtrace)
36
- rescue Exception
37
- @interrupted = true
38
- raise unless handle_exception($!)
39
- ensure
40
- begin
41
- run_teardown
42
- rescue Mocha::ExpectationError => e
43
- add_failure(e.message, e.backtrace)
44
- rescue Exception
45
- raise unless handle_exception($!)
46
- end
47
- end
48
- ensure
49
- mocha_teardown
50
- end
51
- result.add_run
52
- yield(Test::Unit::TestCase::FINISHED, name)
53
- ensure
54
- @_result = nil
55
- end
56
- end
57
- # rubocop:enable all
58
- end
59
- end
60
- end
61
- end
62
- end
@@ -1,62 +0,0 @@
1
- require 'mocha/integration/assertion_counter'
2
- require 'mocha/integration/monkey_patcher'
3
- require 'mocha/expectation_error'
4
-
5
- module Mocha
6
- module Integration
7
- module TestUnit
8
- module GemVersion201To202
9
- def self.applicable_to?(test_unit_version, _ruby_version = nil)
10
- Gem::Requirement.new('>= 2.0.1', '<= 2.0.2').satisfied_by?(test_unit_version)
11
- end
12
-
13
- def self.description
14
- 'monkey patch for Test::Unit gem >= v2.0.1 and <= v2.0.2'
15
- end
16
-
17
- def self.included(mod)
18
- MonkeyPatcher.apply(mod, RunMethodPatch)
19
- end
20
-
21
- module RunMethodPatch
22
- # rubocop:disable all
23
- def run(result)
24
- assertion_counter = AssertionCounter.new(self)
25
- begin
26
- @_result = result
27
- yield(Test::Unit::TestCase::STARTED, name)
28
- begin
29
- begin
30
- mocha_setup
31
- run_setup
32
- run_test
33
- mocha_verify(assertion_counter)
34
- rescue Mocha::ExpectationError => e
35
- add_failure(e.message, e.backtrace)
36
- rescue Exception
37
- @interrupted = true
38
- raise unless handle_exception($!)
39
- ensure
40
- begin
41
- run_teardown
42
- rescue Mocha::ExpectationError => e
43
- add_failure(e.message, e.backtrace)
44
- rescue Exception
45
- raise unless handle_exception($!)
46
- end
47
- end
48
- ensure
49
- mocha_teardown
50
- end
51
- result.add_run
52
- yield(Test::Unit::TestCase::FINISHED, name)
53
- ensure
54
- @_result = nil
55
- end
56
- end
57
- # rubocop:enable all
58
- end
59
- end
60
- end
61
- end
62
- end
@@ -1,62 +0,0 @@
1
- require 'mocha/integration/assertion_counter'
2
- require 'mocha/integration/monkey_patcher'
3
- require 'mocha/expectation_error'
4
-
5
- module Mocha
6
- module Integration
7
- module TestUnit
8
- module GemVersion203To220
9
- def self.applicable_to?(test_unit_version, _ruby_version = nil)
10
- Gem::Requirement.new('>= 2.0.3', '<= 2.2.0').satisfied_by?(test_unit_version)
11
- end
12
-
13
- def self.description
14
- 'monkey patch for Test::Unit gem >= v2.0.3 and <= v2.2.0'
15
- end
16
-
17
- def self.included(mod)
18
- MonkeyPatcher.apply(mod, RunMethodPatch)
19
- end
20
-
21
- module RunMethodPatch
22
- # rubocop:disable all
23
- def run(result)
24
- assertion_counter = AssertionCounter.new(self)
25
- begin
26
- @_result = result
27
- yield(Test::Unit::TestCase::STARTED, name)
28
- begin
29
- begin
30
- mocha_setup
31
- run_setup
32
- run_test
33
- mocha_verify(assertion_counter)
34
- rescue Mocha::ExpectationError => e
35
- add_failure(e.message, e.backtrace)
36
- rescue Exception
37
- @interrupted = true
38
- raise unless handle_exception($!)
39
- ensure
40
- begin
41
- run_teardown
42
- rescue Mocha::ExpectationError => e
43
- add_failure(e.message, e.backtrace)
44
- rescue Exception
45
- raise unless handle_exception($!)
46
- end
47
- end
48
- ensure
49
- mocha_teardown
50
- end
51
- result.add_run
52
- yield(Test::Unit::TestCase::FINISHED, name)
53
- ensure
54
- # @_result = nil # For test-spec's after_all :<
55
- end
56
- end
57
- # rubocop:enable all
58
- end
59
- end
60
- end
61
- end
62
- end
@@ -1,68 +0,0 @@
1
- require 'mocha/integration/assertion_counter'
2
- require 'mocha/integration/monkey_patcher'
3
- require 'mocha/expectation_error'
4
-
5
- module Mocha
6
- module Integration
7
- module TestUnit
8
- module GemVersion230To250
9
- def self.applicable_to?(test_unit_version, _ruby_version = nil)
10
- Gem::Requirement.new('>= 2.3.0', '<= 2.5.0').satisfied_by?(test_unit_version)
11
- end
12
-
13
- def self.description
14
- 'monkey patch for Test::Unit gem >= v2.3.0 and <= v2.5.0'
15
- end
16
-
17
- def self.included(mod)
18
- MonkeyPatcher.apply(mod, RunMethodPatch)
19
- end
20
-
21
- module RunMethodPatch
22
- # rubocop:disable all
23
- def run(result)
24
- assertion_counter = AssertionCounter.new(self)
25
- begin
26
- @internal_data.test_started
27
- @_result = result
28
- yield(Test::Unit::TestCase::STARTED, name)
29
- yield(Test::Unit::TestCase::STARTED_OBJECT, self)
30
- begin
31
- begin
32
- mocha_setup
33
- run_setup
34
- run_test
35
- run_cleanup
36
- mocha_verify(assertion_counter)
37
- add_pass
38
- rescue Mocha::ExpectationError => e
39
- add_failure(e.message, e.backtrace)
40
- rescue Exception
41
- @internal_data.interrupted
42
- raise unless handle_exception($!)
43
- ensure
44
- begin
45
- run_teardown
46
- rescue Mocha::ExpectationError => e
47
- add_failure(e.message, e.backtrace)
48
- rescue Exception
49
- raise unless handle_exception($!)
50
- end
51
- end
52
- ensure
53
- mocha_teardown
54
- end
55
- @internal_data.test_finished
56
- result.add_run
57
- yield(Test::Unit::TestCase::FINISHED, name)
58
- yield(Test::Unit::TestCase::FINISHED_OBJECT, self)
59
- ensure
60
- # @_result = nil # For test-spec's after_all :<
61
- end
62
- end
63
- # rubocop:enable all
64
- end
65
- end
66
- end
67
- end
68
- end
@@ -1,19 +0,0 @@
1
- module Mocha
2
- module Integration
3
- module TestUnit
4
- module Nothing
5
- def self.applicable_to?(_test_unit_version, _ruby_version = nil)
6
- true
7
- end
8
-
9
- def self.description
10
- 'nothing (no Test::Unit integration available)'
11
- end
12
-
13
- def self.included(_mod)
14
- raise 'No Test::Unit integration available'
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,61 +0,0 @@
1
- require 'mocha/integration/assertion_counter'
2
- require 'mocha/integration/monkey_patcher'
3
- require 'mocha/expectation_error'
4
-
5
- module Mocha
6
- module Integration
7
- module TestUnit
8
- module RubyVersion185AndBelow
9
- def self.applicable_to?(test_unit_version, ruby_version)
10
- Gem::Requirement.new('<= 1.2.3').satisfied_by?(test_unit_version) && Gem::Requirement.new('<= 1.8.5').satisfied_by?(ruby_version)
11
- end
12
-
13
- def self.description
14
- 'monkey patch for standard library in Ruby <= v1.8.5'
15
- end
16
-
17
- def self.included(mod)
18
- MonkeyPatcher.apply(mod, RunMethodPatch)
19
- end
20
-
21
- module RunMethodPatch
22
- # rubocop:disable all
23
- def run(result)
24
- assertion_counter = AssertionCounter.new(self)
25
- yield(Test::Unit::TestCase::STARTED, name)
26
- @_result = result
27
- begin
28
- begin
29
- mocha_setup
30
- setup
31
- __send__(@method_name)
32
- mocha_verify(assertion_counter)
33
- rescue Mocha::ExpectationError => e
34
- add_failure(e.message, e.backtrace)
35
- rescue Test::Unit::AssertionFailedError => e
36
- add_failure(e.message, e.backtrace)
37
- rescue StandardError, ScriptError
38
- add_error($!)
39
- ensure
40
- begin
41
- teardown
42
- rescue Mocha::ExpectationError => e
43
- add_failure(e.message, e.backtrace)
44
- rescue Test::Unit::AssertionFailedError => e
45
- add_failure(e.message, e.backtrace)
46
- rescue StandardError, ScriptError
47
- add_error($!)
48
- end
49
- end
50
- ensure
51
- mocha_teardown
52
- end
53
- result.add_run
54
- yield(Test::Unit::TestCase::FINISHED, name)
55
- end
56
- # rubocop:enable all
57
- end
58
- end
59
- end
60
- end
61
- end
@@ -1,63 +0,0 @@
1
- require 'mocha/integration/assertion_counter'
2
- require 'mocha/integration/monkey_patcher'
3
- require 'mocha/expectation_error'
4
-
5
- module Mocha
6
- module Integration
7
- module TestUnit
8
- module RubyVersion186AndAbove
9
- def self.applicable_to?(test_unit_version, ruby_version)
10
- Gem::Requirement.new('<= 1.2.3').satisfied_by?(test_unit_version) && Gem::Requirement.new('>= 1.8.6').satisfied_by?(ruby_version)
11
- end
12
-
13
- def self.description
14
- 'monkey patch for standard library Test::Unit in Ruby >= v1.8.6'
15
- end
16
-
17
- def self.included(mod)
18
- MonkeyPatcher.apply(mod, RunMethodPatch)
19
- end
20
-
21
- module RunMethodPatch
22
- # rubocop:disable all
23
- def run(result)
24
- assertion_counter = AssertionCounter.new(self)
25
- yield(Test::Unit::TestCase::STARTED, name)
26
- @_result = result
27
- begin
28
- begin
29
- mocha_setup
30
- setup
31
- __send__(@method_name)
32
- mocha_verify(assertion_counter)
33
- rescue Mocha::ExpectationError => e
34
- add_failure(e.message, e.backtrace)
35
- rescue Test::Unit::AssertionFailedError => e
36
- add_failure(e.message, e.backtrace)
37
- rescue Exception
38
- raise if Test::Unit::TestCase::PASSTHROUGH_EXCEPTIONS.include? $!.class
39
- add_error($!)
40
- ensure
41
- begin
42
- teardown
43
- rescue Mocha::ExpectationError => e
44
- add_failure(e.message, e.backtrace)
45
- rescue Test::Unit::AssertionFailedError => e
46
- add_failure(e.message, e.backtrace)
47
- rescue Exception
48
- raise if Test::Unit::TestCase::PASSTHROUGH_EXCEPTIONS.include? $!.class
49
- add_error($!)
50
- end
51
- end
52
- ensure
53
- mocha_teardown
54
- end
55
- result.add_run
56
- yield(Test::Unit::TestCase::FINISHED, name)
57
- end
58
- # rubocop:enable all
59
- end
60
- end
61
- end
62
- end
63
- end
@@ -1,11 +0,0 @@
1
- require 'mocha/integration/test_unit'
2
- require 'mocha/integration/mini_test'
3
-
4
- module Mocha
5
- module Integration
6
- def self.activate
7
- return unless [Integration::TestUnit, Integration::MiniTest].map(&:activate).none?
8
- raise "Test::Unit or Minitest must be loaded *before* `require 'mocha/setup'`."
9
- end
10
- end
11
- end
data/lib/mocha/setup.rb DELETED
@@ -1,14 +0,0 @@
1
- require 'mocha/integration'
2
- require 'mocha/deprecation'
3
-
4
- Mocha::Deprecation.warning(
5
- "Require 'mocha/test_unit', 'mocha/minitest' or 'mocha/api' instead of 'mocha/setup'."
6
- )
7
-
8
- module Mocha
9
- def self.activate
10
- Integration.activate
11
- end
12
- end
13
-
14
- Mocha.activate
@@ -1,9 +0,0 @@
1
- if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('1.9.2')
2
- unless Kernel.method_defined?(:singleton_class)
3
- module Kernel
4
- def singleton_class
5
- class << self; self; end
6
- end
7
- end
8
- end
9
- end