mocha 1.16.1 → 2.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +10 -13
  3. data/.yardopts +1 -2
  4. data/COPYING.md +2 -2
  5. data/Gemfile +7 -4
  6. data/MIT-LICENSE.md +1 -1
  7. data/README.md +23 -24
  8. data/RELEASE.md +294 -0
  9. data/Rakefile +23 -24
  10. data/lib/mocha/api.rb +30 -71
  11. data/lib/mocha/backtrace_filter.rb +2 -2
  12. data/lib/mocha/cardinality.rb +4 -0
  13. data/lib/mocha/configuration.rb +44 -126
  14. data/lib/mocha/debug.rb +2 -5
  15. data/lib/mocha/detection/{mini_test.rb → minitest.rb} +5 -5
  16. data/lib/mocha/detection/test_unit.rb +2 -2
  17. data/lib/mocha/expectation.rb +99 -12
  18. data/lib/mocha/expectation_error_factory.rb +2 -2
  19. data/lib/mocha/expectation_list.rb +8 -6
  20. data/lib/mocha/hooks.rb +10 -4
  21. data/lib/mocha/inspect.rb +15 -4
  22. data/lib/mocha/integration/{mini_test → minitest}/adapter.rb +21 -6
  23. data/lib/mocha/integration/{mini_test → minitest}/exception_translation.rb +2 -2
  24. data/lib/mocha/integration/minitest.rb +28 -0
  25. data/lib/mocha/integration/test_unit/adapter.rb +9 -4
  26. data/lib/mocha/integration/test_unit.rb +10 -31
  27. data/lib/mocha/invocation.rb +2 -15
  28. data/lib/mocha/minitest.rb +3 -6
  29. data/lib/mocha/mock.rb +45 -18
  30. data/lib/mocha/mockery.rb +13 -9
  31. data/lib/mocha/names.rb +1 -1
  32. data/lib/mocha/object_methods.rb +2 -2
  33. data/lib/mocha/parameter_matchers/base.rb +4 -9
  34. data/lib/mocha/parameter_matchers/equivalent_uri.rb +1 -2
  35. data/lib/mocha/parameter_matchers/has_entries.rb +7 -2
  36. data/lib/mocha/parameter_matchers/includes.rb +3 -3
  37. data/lib/mocha/parameter_matchers/instance_methods.rb +10 -2
  38. data/lib/mocha/parameter_matchers/positional_or_keyword_hash.rb +66 -0
  39. data/lib/mocha/parameter_matchers/responds_with.rb +32 -5
  40. data/lib/mocha/parameters_matcher.rb +10 -6
  41. data/lib/mocha/ruby_version.rb +2 -9
  42. data/lib/mocha/stubbed_method.rb +3 -39
  43. data/lib/mocha/test_unit.rb +1 -4
  44. data/lib/mocha/version.rb +1 -1
  45. data/mocha.gemspec +11 -1
  46. metadata +31 -31
  47. data/init.rb +0 -1
  48. data/lib/mocha/integration/mini_test/nothing.rb +0 -19
  49. data/lib/mocha/integration/mini_test/version_13.rb +0 -54
  50. data/lib/mocha/integration/mini_test/version_140.rb +0 -54
  51. data/lib/mocha/integration/mini_test/version_141.rb +0 -65
  52. data/lib/mocha/integration/mini_test/version_142_to_172.rb +0 -65
  53. data/lib/mocha/integration/mini_test/version_200.rb +0 -66
  54. data/lib/mocha/integration/mini_test/version_201_to_222.rb +0 -66
  55. data/lib/mocha/integration/mini_test/version_2110_to_2111.rb +0 -70
  56. data/lib/mocha/integration/mini_test/version_2112_to_320.rb +0 -73
  57. data/lib/mocha/integration/mini_test/version_230_to_2101.rb +0 -68
  58. data/lib/mocha/integration/mini_test.rb +0 -56
  59. data/lib/mocha/integration/test_unit/gem_version_200.rb +0 -62
  60. data/lib/mocha/integration/test_unit/gem_version_201_to_202.rb +0 -62
  61. data/lib/mocha/integration/test_unit/gem_version_203_to_220.rb +0 -62
  62. data/lib/mocha/integration/test_unit/gem_version_230_to_250.rb +0 -68
  63. data/lib/mocha/integration/test_unit/nothing.rb +0 -19
  64. data/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb +0 -63
  65. data/lib/mocha/integration.rb +0 -11
  66. data/lib/mocha/setup.rb +0 -14
  67. data/yard-templates/default/layout/html/google_analytics.erb +0 -8
  68. data/yard-templates/default/layout/html/setup.rb +0 -5
@@ -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,56 +0,0 @@
1
- require 'mocha/debug'
2
-
3
- require 'mocha/detection/mini_test'
4
-
5
- require 'mocha/integration/mini_test/nothing'
6
- require 'mocha/integration/mini_test/version_13'
7
- require 'mocha/integration/mini_test/version_140'
8
- require 'mocha/integration/mini_test/version_141'
9
- require 'mocha/integration/mini_test/version_142_to_172'
10
- require 'mocha/integration/mini_test/version_200'
11
- require 'mocha/integration/mini_test/version_201_to_222'
12
- require 'mocha/integration/mini_test/version_230_to_2101'
13
- require 'mocha/integration/mini_test/version_2110_to_2111'
14
- require 'mocha/integration/mini_test/version_2112_to_320'
15
- require 'mocha/integration/mini_test/adapter'
16
-
17
- require 'mocha/deprecation'
18
-
19
- module Mocha
20
- module Integration
21
- module MiniTest
22
- def self.activate
23
- return false unless Detection::MiniTest.testcase
24
- mini_test_version = Gem::Version.new(Detection::MiniTest.version)
25
-
26
- Debug.puts "Detected MiniTest version: #{mini_test_version}"
27
-
28
- integration_module = [
29
- MiniTest::Adapter,
30
- MiniTest::Version2112To320,
31
- MiniTest::Version2110To2111,
32
- MiniTest::Version230To2101,
33
- MiniTest::Version201To222,
34
- MiniTest::Version200,
35
- MiniTest::Version142To172,
36
- MiniTest::Version141,
37
- MiniTest::Version140,
38
- MiniTest::Version13,
39
- MiniTest::Nothing
40
- ].detect { |m| m.applicable_to?(mini_test_version) }
41
-
42
- target = Detection::MiniTest.testcase
43
- unless target < integration_module
44
- unless integration_module == MiniTest::Adapter
45
- Deprecation.warning(
46
- 'Versions of minitest earlier than v3.3.0 will not be supported in future versions of Mocha.'
47
- )
48
- end
49
- Debug.puts "Applying #{integration_module.description}"
50
- target.send(:include, integration_module)
51
- end
52
- true
53
- end
54
- end
55
- end
56
- 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,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,8 +0,0 @@
1
- <script async src="https://www.googletagmanager.com/gtag/js?id=<%= ENV['GOOGLE_ANALYTICS_WEB_PROPERTY_ID'] %>"></script>
2
- <script>
3
- window.dataLayer = window.dataLayer || [];
4
- function gtag(){dataLayer.push(arguments);}
5
- gtag('js', new Date());
6
-
7
- gtag('config', '<%= ENV['GOOGLE_ANALYTICS_WEB_PROPERTY_ID'] %>');
8
- </script>
@@ -1,5 +0,0 @@
1
- def init
2
- super
3
- return unless ENV['GOOGLE_ANALYTICS_WEB_PROPERTY_ID']
4
- sections[:layout] << :google_analytics
5
- end