mocha 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/RELEASE.md +4 -0
- data/lib/mocha/central.rb +17 -0
- data/lib/mocha/error_with_filtered_backtrace.rb +17 -0
- data/lib/mocha/hooks.rb +1 -2
- data/lib/mocha/integration/mini_test/version_13.rb +1 -0
- data/lib/mocha/integration/mini_test/version_140.rb +1 -0
- data/lib/mocha/integration/mini_test/version_141.rb +1 -0
- data/lib/mocha/integration/mini_test/version_142_to_172.rb +1 -0
- data/lib/mocha/integration/mini_test/version_200.rb +1 -0
- data/lib/mocha/integration/mini_test/version_201_to_222.rb +1 -0
- data/lib/mocha/integration/mini_test/version_2110_to_2111.rb +1 -0
- data/lib/mocha/integration/mini_test/version_2112_to_320.rb +1 -0
- data/lib/mocha/integration/mini_test/version_230_to_2101.rb +1 -0
- data/lib/mocha/integration/test_unit/gem_version_200.rb +1 -0
- data/lib/mocha/integration/test_unit/gem_version_201_to_202.rb +1 -0
- data/lib/mocha/integration/test_unit/gem_version_203_to_220.rb +1 -0
- data/lib/mocha/integration/test_unit/gem_version_230_to_250.rb +1 -0
- data/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb +1 -0
- data/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb +1 -0
- data/lib/mocha/mockery.rb +38 -3
- data/lib/mocha/not_initialized_error.rb +9 -0
- data/lib/mocha/stubbing_error.rb +2 -11
- data/lib/mocha/version.rb +1 -1
- data/test/acceptance/acceptance_test_helper.rb +0 -2
- data/test/acceptance/prevent_use_of_mocha_outside_test_test.rb +79 -0
- data/test/unit/hooks_test.rb +5 -4
- data/test/unit/mockery_test.rb +17 -2
- data/test/unit/object_methods_test.rb +6 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae952b50093776beef6c7083184899e6875738d7
|
4
|
+
data.tar.gz: b45fc4c6fe7d7ab128a7227f3fdf2db01e349989
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5ca31997f0e6342f4d757a4a42da220cbc51878b878b48f61b4d74b095f7347a846c6196f65568c4dde737c8ccbe13e15eba3fce25054d5232724535021a1b3
|
7
|
+
data.tar.gz: b8797e8b7e3a58b31e3f773860989aafc85fabd2cbf4529a965b521e7ec1f995304b26186f49062c6ec8af6b8b4749730e89373ebf1e909df1b7e7fb5ca793a1
|
data/RELEASE.md
CHANGED
data/lib/mocha/central.rb
CHANGED
@@ -2,6 +2,23 @@ module Mocha
|
|
2
2
|
|
3
3
|
class Central
|
4
4
|
|
5
|
+
class Null < self
|
6
|
+
|
7
|
+
def initialize(&block)
|
8
|
+
super
|
9
|
+
@raise_not_initialized_error = block
|
10
|
+
end
|
11
|
+
|
12
|
+
def stub(*)
|
13
|
+
@raise_not_initialized_error.call
|
14
|
+
end
|
15
|
+
|
16
|
+
def unstub(*)
|
17
|
+
@raise_not_initialized_error.call
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
5
22
|
attr_accessor :stubba_methods
|
6
23
|
|
7
24
|
def initialize
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'mocha/backtrace_filter'
|
2
|
+
|
3
|
+
module Mocha
|
4
|
+
|
5
|
+
# @private
|
6
|
+
class ErrorWithFilteredBacktrace < StandardError
|
7
|
+
|
8
|
+
# @private
|
9
|
+
def initialize(message = nil, backtrace = [])
|
10
|
+
super(message)
|
11
|
+
filter = BacktraceFilter.new
|
12
|
+
set_backtrace(filter.filtered(backtrace))
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
data/lib/mocha/hooks.rb
CHANGED
@@ -21,6 +21,7 @@ module Mocha
|
|
21
21
|
#
|
22
22
|
# This method should be called before each individual test starts (including before any "setup" code).
|
23
23
|
def mocha_setup
|
24
|
+
Mockery.setup
|
24
25
|
end
|
25
26
|
|
26
27
|
# Verifies that all mock expectations have been met (only for use by authors of test libraries).
|
@@ -37,8 +38,6 @@ module Mocha
|
|
37
38
|
# This method should be called after each individual test has finished (including after any "teardown" code).
|
38
39
|
def mocha_teardown
|
39
40
|
Mockery.teardown
|
40
|
-
ensure
|
41
|
-
Mockery.reset_instance
|
42
41
|
end
|
43
42
|
end
|
44
43
|
end
|
data/lib/mocha/mockery.rb
CHANGED
@@ -7,16 +7,46 @@ require 'mocha/state_machine'
|
|
7
7
|
require 'mocha/logger'
|
8
8
|
require 'mocha/configuration'
|
9
9
|
require 'mocha/stubbing_error'
|
10
|
+
require 'mocha/not_initialized_error'
|
10
11
|
require 'mocha/expectation_error_factory'
|
11
12
|
|
12
13
|
module Mocha
|
13
14
|
|
14
15
|
class Mockery
|
15
16
|
|
17
|
+
class Null < self
|
18
|
+
|
19
|
+
def add_mock(*)
|
20
|
+
raise_not_initialized_error
|
21
|
+
end
|
22
|
+
|
23
|
+
def add_state_machine(*)
|
24
|
+
raise_not_initialized_error
|
25
|
+
end
|
26
|
+
|
27
|
+
def stubba
|
28
|
+
Central::Null.new(&method(:raise_not_initialized_error))
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def raise_not_initialized_error
|
34
|
+
message = 'Mocha methods cannot be used outside the context of a test'
|
35
|
+
raise NotInitializedError.new(message, caller)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
16
40
|
class << self
|
17
41
|
|
18
42
|
def instance
|
19
|
-
|
43
|
+
instances.last || Null.new
|
44
|
+
end
|
45
|
+
|
46
|
+
def setup
|
47
|
+
mockery = new
|
48
|
+
mockery.logger = instance.logger unless instances.empty?
|
49
|
+
@instances.push(mockery)
|
20
50
|
end
|
21
51
|
|
22
52
|
def verify(*args)
|
@@ -25,10 +55,15 @@ module Mocha
|
|
25
55
|
|
26
56
|
def teardown
|
27
57
|
instance.teardown
|
58
|
+
ensure
|
59
|
+
@instances.pop
|
60
|
+
@instances = nil if instances.empty?
|
28
61
|
end
|
29
62
|
|
30
|
-
|
31
|
-
|
63
|
+
private
|
64
|
+
|
65
|
+
def instances
|
66
|
+
@instances ||= []
|
32
67
|
end
|
33
68
|
|
34
69
|
end
|
data/lib/mocha/stubbing_error.rb
CHANGED
@@ -1,19 +1,10 @@
|
|
1
|
-
require 'mocha/
|
1
|
+
require 'mocha/error_with_filtered_backtrace'
|
2
2
|
|
3
3
|
module Mocha
|
4
4
|
|
5
5
|
# Exception raised when stubbing a particular method is not allowed.
|
6
6
|
#
|
7
7
|
# @see Configuration.prevent
|
8
|
-
class StubbingError <
|
9
|
-
|
10
|
-
# @private
|
11
|
-
def initialize(message = nil, backtrace = [])
|
12
|
-
super(message)
|
13
|
-
filter = BacktraceFilter.new
|
14
|
-
set_backtrace(filter.filtered(backtrace))
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
8
|
+
class StubbingError < ErrorWithFilteredBacktrace; end
|
18
9
|
|
19
10
|
end
|
data/lib/mocha/version.rb
CHANGED
@@ -27,13 +27,11 @@ module AcceptanceTest
|
|
27
27
|
Mocha::Configuration.reset_configuration
|
28
28
|
@logger = FakeLogger.new
|
29
29
|
mockery = Mocha::Mockery.instance
|
30
|
-
@original_logger = mockery.logger
|
31
30
|
mockery.logger = @logger
|
32
31
|
end
|
33
32
|
|
34
33
|
def teardown_acceptance_test
|
35
34
|
Mocha::Configuration.reset_configuration
|
36
|
-
Mocha::Mockery.instance.logger = @original_logger
|
37
35
|
end
|
38
36
|
|
39
37
|
include Introspection::Assertions
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require File.expand_path('../acceptance_test_helper', __FILE__)
|
2
|
+
require 'mocha/setup'
|
3
|
+
require 'mocha/not_initialized_error'
|
4
|
+
|
5
|
+
class PreventUseOfMochaOutsideTestTest < Mocha::TestCase
|
6
|
+
|
7
|
+
include AcceptanceTest
|
8
|
+
|
9
|
+
def setup
|
10
|
+
setup_acceptance_test
|
11
|
+
mocha_teardown
|
12
|
+
end
|
13
|
+
|
14
|
+
def teardown
|
15
|
+
teardown_acceptance_test
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_should_raise_exception_when_mock_called_outside_test
|
19
|
+
assert_raises(Mocha::NotInitializedError) { mock('object') }
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_should_raise_exception_when_stub_called_outside_test
|
23
|
+
assert_raises(Mocha::NotInitializedError) { stub('object') }
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_should_raise_exception_when_stub_everything_called_outside_test
|
27
|
+
assert_raises(Mocha::NotInitializedError) { stub_everything('object') }
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_should_raise_exception_when_states_called_outside_test
|
31
|
+
assert_raises(Mocha::NotInitializedError) { states('state-machine') }
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_should_raise_exception_when_expects_called_on_instance_outside_test
|
35
|
+
instance = Class.new.new
|
36
|
+
assert_raises(Mocha::NotInitializedError) { instance.expects(:expected_method) }
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_should_raise_exception_when_expects_called_on_class_outside_test
|
40
|
+
klass = Class.new
|
41
|
+
assert_raises(Mocha::NotInitializedError) { klass.expects(:expected_method) }
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_should_raise_exception_when_expects_called_on_any_instance_outside_test
|
45
|
+
klass = Class.new
|
46
|
+
assert_raises(Mocha::NotInitializedError) { klass.any_instance.expects(:expected_method) }
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_should_raise_exception_when_stubs_called_on_instance_outside_test
|
50
|
+
instance = Class.new.new
|
51
|
+
assert_raises(Mocha::NotInitializedError) { instance.stubs(:expected_method) }
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_should_raise_exception_when_stubs_called_on_class_outside_test
|
55
|
+
klass = Class.new
|
56
|
+
assert_raises(Mocha::NotInitializedError) { klass.stubs(:expected_method) }
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_should_raise_exception_when_stubs_called_on_any_instance_outside_test
|
60
|
+
klass = Class.new
|
61
|
+
assert_raises(Mocha::NotInitializedError) { klass.any_instance.stubs(:expected_method) }
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_should_raise_exception_when_unstub_called_on_instance_outside_test
|
65
|
+
instance = Class.new.new
|
66
|
+
assert_raises(Mocha::NotInitializedError) { instance.unstub(:expected_method) }
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_should_raise_exception_when_unstub_called_on_class_outside_test
|
70
|
+
klass = Class.new
|
71
|
+
assert_raises(Mocha::NotInitializedError) { klass.unstub(:expected_method) }
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_should_raise_exception_when_unstub_called_on_any_instance_outside_test
|
75
|
+
klass = Class.new
|
76
|
+
assert_raises(Mocha::NotInitializedError) { klass.any_instance.unstub(:expected_method) }
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
data/test/unit/hooks_test.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
require File.expand_path('../../test_helper', __FILE__)
|
2
2
|
require 'mocha/hooks'
|
3
|
+
require 'mocha/mockery'
|
3
4
|
|
4
5
|
class HooksTest < Mocha::TestCase
|
5
6
|
class Mocha::Mockery
|
6
7
|
class << self
|
7
|
-
attr_writer :
|
8
|
+
attr_writer :instances
|
8
9
|
end
|
9
10
|
end
|
10
11
|
|
@@ -19,11 +20,11 @@ class HooksTest < Mocha::TestCase
|
|
19
20
|
|
20
21
|
def test_ensure_mockery_instance_is_reset_even_when_an_exception_is_raised_in_mockery_teardown
|
21
22
|
fake_test_case = Object.new.extend(Mocha::Hooks)
|
22
|
-
|
23
|
-
Mocha::Mockery.
|
23
|
+
mockery = FakeMockery.new
|
24
|
+
Mocha::Mockery.instances = [mockery]
|
24
25
|
|
25
26
|
fake_test_case.mocha_teardown rescue nil
|
26
27
|
|
27
|
-
|
28
|
+
assert_kind_of Mocha::Mockery::Null, Mocha::Mockery.instance
|
28
29
|
end
|
29
30
|
end
|
data/test/unit/mockery_test.rb
CHANGED
@@ -9,7 +9,22 @@ class MockeryTest < Mocha::TestCase
|
|
9
9
|
include Mocha
|
10
10
|
include DeprecationDisabler
|
11
11
|
|
12
|
-
def
|
12
|
+
def setup
|
13
|
+
Mockery.setup
|
14
|
+
end
|
15
|
+
|
16
|
+
def teardown
|
17
|
+
Mockery.teardown
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_should_return_null_mockery_if_not_setup
|
21
|
+
Mockery.teardown
|
22
|
+
mockery = Mockery.instance
|
23
|
+
assert_not_nil mockery
|
24
|
+
assert_kind_of Mockery::Null, mockery
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_should_return_instance_of_mockery
|
13
28
|
mockery = Mockery.instance
|
14
29
|
assert_not_nil mockery
|
15
30
|
assert_kind_of Mockery, mockery
|
@@ -23,7 +38,7 @@ class MockeryTest < Mocha::TestCase
|
|
23
38
|
|
24
39
|
def test_should_expire_mockery_instance_cache
|
25
40
|
mockery_1 = Mockery.instance
|
26
|
-
Mockery.
|
41
|
+
Mockery.teardown
|
27
42
|
mockery_2 = Mockery.instance
|
28
43
|
assert_not_same mockery_1, mockery_2
|
29
44
|
end
|
@@ -1,14 +1,20 @@
|
|
1
1
|
require File.expand_path('../../test_helper', __FILE__)
|
2
2
|
require 'mocha/object_methods'
|
3
|
+
require 'mocha/mockery'
|
3
4
|
require 'mocha/mock'
|
4
5
|
require 'mocha/expectation_error_factory'
|
5
6
|
|
6
7
|
class ObjectMethodsTest < Mocha::TestCase
|
7
8
|
|
8
9
|
def setup
|
10
|
+
Mocha::Mockery.setup
|
9
11
|
@object = Object.new.extend(Mocha::ObjectMethods)
|
10
12
|
end
|
11
13
|
|
14
|
+
def teardown
|
15
|
+
Mocha::Mockery.teardown
|
16
|
+
end
|
17
|
+
|
12
18
|
def test_should_build_mocha_referring_to_self
|
13
19
|
mocha = @object.mocha
|
14
20
|
assert_not_nil mocha
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mocha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Mead
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: metaclass
|
@@ -141,6 +141,7 @@ files:
|
|
141
141
|
- lib/mocha/deprecation.rb
|
142
142
|
- lib/mocha/detection/mini_test.rb
|
143
143
|
- lib/mocha/detection/test_unit.rb
|
144
|
+
- lib/mocha/error_with_filtered_backtrace.rb
|
144
145
|
- lib/mocha/exception_raiser.rb
|
145
146
|
- lib/mocha/expectation.rb
|
146
147
|
- lib/mocha/expectation_error.rb
|
@@ -187,6 +188,7 @@ files:
|
|
187
188
|
- lib/mocha/multiple_yields.rb
|
188
189
|
- lib/mocha/names.rb
|
189
190
|
- lib/mocha/no_yields.rb
|
191
|
+
- lib/mocha/not_initialized_error.rb
|
190
192
|
- lib/mocha/object_methods.rb
|
191
193
|
- lib/mocha/parameter_matchers.rb
|
192
194
|
- lib/mocha/parameter_matchers/all_of.rb
|
@@ -250,6 +252,7 @@ files:
|
|
250
252
|
- test/acceptance/parameter_matcher_test.rb
|
251
253
|
- test/acceptance/partial_mocks_test.rb
|
252
254
|
- test/acceptance/prepend_test.rb
|
255
|
+
- test/acceptance/prevent_use_of_mocha_outside_test_test.rb
|
253
256
|
- test/acceptance/raise_exception_test.rb
|
254
257
|
- test/acceptance/return_value_test.rb
|
255
258
|
- test/acceptance/sequence_test.rb
|