rr 1.1.2 → 3.0.2
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 +5 -5
- data/Appraisals +3 -43
- data/CHANGES.md +93 -0
- data/CREDITS.md +5 -0
- data/Gemfile +1 -17
- data/README.md +29 -32
- data/Rakefile +42 -40
- data/doc/02_syntax_comparison.md +1 -0
- data/lib/rr/class_instance_method_defined.rb +1 -1
- data/lib/rr/core_ext/array.rb +2 -0
- data/lib/rr/core_ext/hash.rb +2 -0
- data/lib/rr/deprecations.rb +97 -0
- data/lib/rr/double.rb +28 -10
- data/lib/rr/double_definitions/double_definition.rb +39 -16
- data/lib/rr/double_definitions/double_definition_create.rb +5 -5
- data/lib/rr/double_definitions/double_definition_create_blank_slate.rb +10 -4
- data/lib/rr/double_definitions/double_injections/any_instance_of.rb +1 -1
- data/lib/rr/double_definitions/double_injections/instance.rb +2 -2
- data/lib/rr/double_definitions/strategies/strategy.rb +27 -8
- data/lib/rr/double_definitions/strategies/verification/mock.rb +8 -2
- data/lib/rr/double_matches.rb +4 -3
- data/lib/rr/dsl.rb +152 -0
- data/lib/rr/expectations/any_argument_expectation.rb +4 -4
- data/lib/rr/expectations/argument_equality_expectation.rb +43 -5
- data/lib/rr/injections/double_injection.rb +85 -26
- data/lib/rr/injections/method_missing_injection.rb +37 -6
- data/lib/rr/integrations/minitest_4.rb +1 -1
- data/lib/rr/integrations/minitest_4_active_support.rb +1 -1
- data/lib/rr/integrations/rspec/invocation_matcher.rb +0 -8
- data/lib/rr/integrations/rspec_2.rb +20 -2
- data/lib/rr/keyword_arguments.rb +15 -0
- data/lib/rr/method_dispatches/base_method_dispatch.rb +22 -5
- data/lib/rr/method_dispatches/method_dispatch.rb +21 -10
- data/lib/rr/method_dispatches/method_missing_dispatch.rb +14 -5
- data/lib/rr/recorded_call.rb +35 -0
- data/lib/rr/recorded_calls.rb +23 -9
- data/lib/rr/space.rb +15 -5
- data/lib/rr/spy_verification.rb +13 -5
- data/lib/rr/version.rb +1 -1
- data/lib/rr/wildcard_matchers.rb +10 -10
- data/lib/rr/without_autohook.rb +7 -14
- data/rr.gemspec +8 -3
- data/spec/defines_spec_suite_tasks.rb +12 -0
- data/spec/global_helper.rb +5 -0
- data/spec/spec_suite_configuration.rb +1 -7
- data/spec/suites.yml +0 -14
- data/spec/suites/rspec_2/functional/any_instance_of_spec.rb +133 -33
- data/spec/suites/rspec_2/functional/dont_allow_spec.rb +13 -8
- data/spec/suites/rspec_2/functional/mock_bang_spec.rb +20 -0
- data/spec/suites/rspec_2/functional/mock_instance_of_spec.rb +14 -0
- data/spec/suites/rspec_2/functional/mock_instance_of_strong_spec.rb +15 -0
- data/spec/suites/rspec_2/functional/mock_proxy_instance_of_spec.rb +15 -0
- data/spec/suites/rspec_2/functional/mock_proxy_spec.rb +14 -0
- data/spec/suites/rspec_2/functional/mock_spec.rb +8 -232
- data/spec/suites/rspec_2/functional/mock_strong_spec.rb +14 -0
- data/spec/suites/rspec_2/functional/received_spec.rb +16 -0
- data/spec/suites/rspec_2/functional/spy_spec.rb +89 -28
- data/spec/suites/rspec_2/functional/stub_bang_spec.rb +20 -0
- data/spec/suites/rspec_2/functional/stub_instance_of_spec.rb +15 -0
- data/spec/suites/rspec_2/functional/stub_instance_of_strong_spec.rb +15 -0
- data/spec/suites/rspec_2/functional/stub_proxy_instance_of_spec.rb +16 -0
- data/spec/suites/rspec_2/functional/stub_proxy_spec.rb +45 -0
- data/spec/suites/rspec_2/functional/stub_spec.rb +42 -161
- data/spec/suites/rspec_2/functional/stub_strong_spec.rb +15 -0
- data/spec/suites/rspec_2/helper.rb +2 -2
- data/spec/suites/rspec_2/support/mixins/double_definition_creator_helpers.rb +173 -0
- data/spec/suites/rspec_2/support/mixins/mock_definition_creator_helpers.rb +45 -0
- data/spec/suites/rspec_2/support/mixins/proxy_definition_creator_helpers.rb +33 -0
- data/spec/suites/rspec_2/support/mixins/stub_creator_helpers.rb +43 -0
- data/spec/suites/rspec_2/support/mixins/stub_definition_creator_helpers.rb +45 -0
- data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/argument_expectations_with_never_called_qualifier.rb +39 -0
- data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/argument_expectations_with_times_called_qualifier.rb +50 -0
- data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/argument_expectations_without_qualifiers.rb +131 -0
- data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/dont_allow.rb +148 -0
- data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/mock_instance_of.rb +26 -0
- data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/mock_instance_of_strong.rb +28 -0
- data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/mock_proxy.rb +11 -0
- data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/mock_strong.rb +37 -0
- data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/mocking.rb +107 -0
- data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stub_instance_of.rb +32 -0
- data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stub_instance_of_strong.rb +39 -0
- data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stub_proxy.rb +11 -0
- data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stub_strong.rb +37 -0
- data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/stubbing.rb +57 -0
- data/spec/suites/rspec_2/support/shared_examples/double_definition_creators/array_flatten_bug.rb +35 -0
- data/spec/suites/rspec_2/support/shared_examples/double_definition_creators/block_form.rb +31 -0
- data/spec/suites/rspec_2/support/shared_examples/double_definition_creators/comparing_arity.rb +63 -0
- data/spec/suites/rspec_2/support/shared_examples/double_definition_creators/object_is_proxy.rb +43 -0
- data/spec/suites/rspec_2/support/shared_examples/double_definition_creators/sequential_invocations.rb +26 -0
- data/spec/suites/rspec_2/support/shared_examples/double_definition_creators/setting_implementation.rb +51 -0
- data/spec/suites/rspec_2/support/shared_examples/double_definition_creators/yields.rb +81 -0
- data/spec/suites/rspec_2/unit/core_ext/enumerable_spec.rb +0 -28
- data/spec/suites/rspec_2/unit/deprecations_spec.rb +27 -0
- data/spec/suites/rspec_2/unit/double_definitions/double_definition_create_spec.rb +18 -18
- data/spec/suites/rspec_2/unit/dsl/double_creators_spec.rb +133 -0
- data/spec/suites/rspec_2/unit/dsl/space_spec.rb +99 -0
- data/spec/suites/rspec_2/unit/dsl/wildcard_matchers_spec.rb +67 -0
- data/spec/suites/rspec_2/unit/expectations/any_argument_expectation_spec.rb +9 -9
- data/spec/suites/rspec_2/unit/expectations/argument_equality_expectation_spec.rb +21 -21
- data/spec/suites/rspec_2/unit/expectations/boolean_argument_equality_expectation_spec.rb +4 -4
- data/spec/suites/rspec_2/unit/expectations/hash_including_argument_equality_expectation_spec.rb +31 -21
- data/spec/suites/rspec_2/unit/injections/double_injection/double_injection_spec.rb +0 -12
- data/spec/suites/rspec_2/unit/integrations/rspec_spec.rb +4 -19
- data/spec/suites/rspec_2/unit/space_spec.rb +7 -4
- data/spec/suites/rspec_2/unit/spy_verification_spec.rb +1 -1
- data/spec/support/adapter.rb +1 -1
- data/spec/support/adapter_tests/rspec.rb +19 -15
- data/spec/support/project/generator.rb +0 -4
- metadata +112 -57
- data/gemfiles/ruby_18_rspec_1.gemfile +0 -14
- data/gemfiles/ruby_18_rspec_1.gemfile.lock +0 -38
- data/gemfiles/ruby_18_rspec_1_rails_2.gemfile +0 -18
- data/gemfiles/ruby_18_rspec_1_rails_2.gemfile.lock +0 -64
- data/gemfiles/ruby_19_rspec_2_rails_3.gemfile +0 -15
- data/gemfiles/ruby_19_rspec_2_rails_3.gemfile.lock +0 -123
- data/lib/rr/adapters.rb +0 -34
- data/lib/rr/adapters/rr_methods.rb +0 -142
- data/lib/rr/integrations/rspec_1.rb +0 -46
- data/lib/rr/integrations/test_unit_1.rb +0 -63
- data/lib/rr/integrations/test_unit_2.rb +0 -17
- data/lib/rr/integrations/test_unit_200.rb +0 -27
- data/lib/rr/integrations/test_unit_200_active_support.rb +0 -25
- data/lib/rr/integrations/test_unit_2_active_support.rb +0 -38
- data/lib/rr/proc_from_block.rb +0 -11
- data/spec/suites/rspec_1/helper.rb +0 -24
- data/spec/suites/rspec_1/integration/rspec_1_spec.rb +0 -93
- data/spec/suites/rspec_1/integration/test_unit_1_spec.rb +0 -102
- data/spec/suites/rspec_1/integration/test_unit_2_spec.rb +0 -109
- data/spec/suites/rspec_1/spec_helper.rb +0 -3
- data/spec/suites/rspec_1_rails_2/integration/astc_rails_2_spec.rb +0 -141
- data/spec/suites/rspec_1_rails_2/integration/rspec_1_rails_2_spec.rb +0 -132
- data/spec/suites/rspec_1_rails_2/integration/test_unit_1_rails_2_spec.rb +0 -141
- data/spec/suites/rspec_1_rails_2/integration/test_unit_2_rails_2_spec.rb +0 -148
- data/spec/suites/rspec_1_rails_2/spec_helper.rb +0 -3
- data/spec/suites/rspec_2/functional/dsl_spec.rb +0 -13
- data/spec/suites/rspec_2/functional/instance_of_spec.rb +0 -14
- data/spec/suites/rspec_2/functional/proxy_spec.rb +0 -136
- data/spec/suites/rspec_2/functional/strong_spec.rb +0 -79
- data/spec/suites/rspec_2/integration/rspec_2_spec.rb +0 -133
- data/spec/suites/rspec_2/integration/test_unit_200_spec.rb +0 -102
- data/spec/suites/rspec_2/integration/test_unit_2_spec.rb +0 -109
- data/spec/suites/rspec_2/unit/adapters/rr_methods/double_creators_spec.rb +0 -135
- data/spec/suites/rspec_2/unit/adapters/rr_methods/space_spec.rb +0 -101
- data/spec/suites/rspec_2/unit/adapters/rr_methods/wildcard_matchers_spec.rb +0 -69
- data/spec/suites/rspec_2/unit/proc_from_block_spec.rb +0 -14
- data/spec/suites/rspec_2_rails_3/integration/astc_rails_3_spec.rb +0 -141
- data/spec/suites/rspec_2_rails_3/integration/minitest_4_rails_3_spec.rb +0 -148
- data/spec/suites/rspec_2_rails_3/integration/rspec_2_rails_3_spec.rb +0 -172
- data/spec/suites/rspec_2_rails_3/integration/test_unit_200_rails_3_spec.rb +0 -141
- data/spec/suites/rspec_2_rails_3/integration/test_unit_2_rails_3_spec.rb +0 -148
- data/spec/suites/rspec_2_rails_3/spec_helper.rb +0 -3
- data/spec/suites/rspec_2_rails_4/integration/astc_rails_4_spec.rb +0 -142
- data/spec/suites/rspec_2_rails_4/integration/minitest_4_rails_4_spec.rb +0 -149
- data/spec/suites/rspec_2_rails_4/integration/rspec_2_rails_4_spec.rb +0 -173
- data/spec/suites/rspec_2_rails_4/integration/test_unit_200_rails_4_spec.rb +0 -142
- data/spec/suites/rspec_2_rails_4/integration/test_unit_2_rails_4_spec.rb +0 -149
- data/spec/suites/rspec_2_rails_4/spec_helper.rb +0 -3
@@ -0,0 +1,131 @@
|
|
1
|
+
shared_context 'using 1 of 2 ways to define a method double with an argument expectation without any qualifiers' do
|
2
|
+
include DoubleDefinitionCreatorHelpers
|
3
|
+
|
4
|
+
it "defines the double just for that specific invocation" do
|
5
|
+
object = build_object_with_possible_methods(some_method: ->(*args) { 'value' }) do |subject|
|
6
|
+
double_creator = double_definition_creator_for(subject)
|
7
|
+
double = define_double_with_argument_expectation(double_creator, :some_method, 1)
|
8
|
+
double.returns { 'bar' }
|
9
|
+
end
|
10
|
+
expect_call_to_return_or_raise_times_called_error('bar', object, :some_method, 1)
|
11
|
+
end
|
12
|
+
|
13
|
+
if supports_dont_allow?
|
14
|
+
|
15
|
+
context 'upon verification after the invocation occurs too few times' do
|
16
|
+
specify "no error is raised if the method is never called at all" do
|
17
|
+
build_object_with_possible_methods(some_method: ->(*args) {}) do |subject|
|
18
|
+
double_creator = double_definition_creator_for(subject)
|
19
|
+
define_double_with_argument_expectation(double_creator, :some_method, 1)
|
20
|
+
end
|
21
|
+
expect { RR.verify }.not_to raise_error
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'the moment an unknown invocation occurs' do
|
26
|
+
specify "DoubleNotFoundError is raised" do
|
27
|
+
object = build_object_with_possible_methods(some_method: ->(*args) {}) do |subject|
|
28
|
+
double_creator = double_definition_creator_for(subject)
|
29
|
+
define_double_with_argument_expectation(double_creator, :some_method, 1)
|
30
|
+
end
|
31
|
+
expect { object.some_method }.to raise_error(RR::Errors::DoubleNotFoundError)
|
32
|
+
RR.reset
|
33
|
+
end
|
34
|
+
|
35
|
+
it "is reset correctly" do
|
36
|
+
object = build_object_with_possible_methods(some_method: ->(*args) {}) do |subject|
|
37
|
+
double_creator = double_definition_creator_for(subject)
|
38
|
+
define_double_with_argument_expectation(double_creator, :some_method, 1)
|
39
|
+
end
|
40
|
+
RR.reset
|
41
|
+
expect {
|
42
|
+
call_possible_method_on(object, :some_method)
|
43
|
+
}.not_to raise_error
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
elsif supports_mocking?
|
48
|
+
|
49
|
+
context 'upon verification after the invocation occurs too few times' do
|
50
|
+
specify "TimesCalledError is raised at the verify step if the method is never called at all" do
|
51
|
+
build_object_with_possible_methods(some_method: ->(*args) {}) do |subject|
|
52
|
+
double_creator = double_definition_creator_for(subject)
|
53
|
+
define_double_with_argument_expectation(double_creator, :some_method, 1)
|
54
|
+
end
|
55
|
+
expect { RR.verify }.to raise_error(RR::Errors::TimesCalledError)
|
56
|
+
end
|
57
|
+
|
58
|
+
specify "nothing happens upon being reset" do
|
59
|
+
build_object_with_possible_methods(some_method: ->(*args) {}) do |subject|
|
60
|
+
double_creator = double_definition_creator_for(subject)
|
61
|
+
define_double_with_argument_expectation(double_creator, :some_method, 1)
|
62
|
+
end
|
63
|
+
RR.reset
|
64
|
+
expect { RR.verify }.not_to raise_error
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'the moment an unknown invocation occurs' do
|
69
|
+
specify "DoubleNotFoundError is raised" do
|
70
|
+
object = build_object_with_possible_methods(some_method: ->(*args) {}) do |subject|
|
71
|
+
double_creator = double_definition_creator_for(subject)
|
72
|
+
define_double_with_argument_expectation(double_creator, :some_method, 1)
|
73
|
+
end
|
74
|
+
expect { object.some_method }.to raise_error(RR::Errors::DoubleNotFoundError)
|
75
|
+
RR.reset
|
76
|
+
end
|
77
|
+
|
78
|
+
specify "is reset correctly" do
|
79
|
+
object = build_object_with_possible_methods(some_method: ->(*args) {}) do |subject|
|
80
|
+
double_creator = double_definition_creator_for(subject)
|
81
|
+
define_double_with_argument_expectation(double_creator, :some_method, 1)
|
82
|
+
end
|
83
|
+
RR.reset
|
84
|
+
expect {
|
85
|
+
call_possible_method_on(object, :some_method, 1)
|
86
|
+
}.not_to raise_error
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
else
|
91
|
+
|
92
|
+
it "resets the double correctly" do
|
93
|
+
object = build_object_with_possible_methods(some_method: ->(*args) { 'existing value' }) do |subject, object|
|
94
|
+
expect_method_to_have_value_or_be_absent('existing value', object, :some_method, 1)
|
95
|
+
double_creator = double_definition_creator_for(subject)
|
96
|
+
double = define_double_with_argument_expectation(double_creator, :some_method, 1)
|
97
|
+
double.returns { 'new value' }
|
98
|
+
end
|
99
|
+
RR.reset
|
100
|
+
expect_method_to_have_value_or_be_absent('existing value', object, :some_method, 1)
|
101
|
+
end
|
102
|
+
|
103
|
+
it "raises DoubleNotFoundError the moment the method is called but not with the specified arguments" do
|
104
|
+
object = build_object_with_possible_methods(some_method: ->(*args) {}) do |subject|
|
105
|
+
double_creator = double_definition_creator_for(subject)
|
106
|
+
define_double_with_argument_expectation(double_creator, :some_method, 1)
|
107
|
+
end
|
108
|
+
expect { object.some_method }.to raise_error(RR::Errors::DoubleNotFoundError)
|
109
|
+
RR.reset
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
unless supports_dont_allow?
|
115
|
+
it "lets you define a catch-all double by defining a stub without arguments" do
|
116
|
+
object = build_object_with_possible_methods(some_method: ->(*args) {}) do |subject|
|
117
|
+
double_creator =
|
118
|
+
if supports_instance_of?
|
119
|
+
stub.instance_of(subject)
|
120
|
+
else
|
121
|
+
stub(subject)
|
122
|
+
end
|
123
|
+
double_creator.some_method
|
124
|
+
double_creator = double_definition_creator_for(subject)
|
125
|
+
define_double_with_argument_expectation(double_creator, :some_method, 1)
|
126
|
+
end
|
127
|
+
object.some_method(1)
|
128
|
+
object.some_method(2) # shouldn't raise an error
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
shared_context 'tests for a double definition creator method that supports dont_allow' do
|
2
|
+
include DoubleDefinitionCreatorHelpers
|
3
|
+
|
4
|
+
specify "TimesCalledError is raised as soon as the method is called" do
|
5
|
+
object = build_object_with_possible_methods(some_method: -> {}) do |subject|
|
6
|
+
dont_allow(subject).some_method
|
7
|
+
end
|
8
|
+
expect { object.some_method }.to raise_error(RR::Errors::TimesCalledError)
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'defining a mock with an argument expectation with a times-called qualifier' do
|
12
|
+
context 'by passing arguments to the double definition directly' do
|
13
|
+
include_context 'using 1 of 2 ways to define a mock with an argument expectation with a times-called qualifier'
|
14
|
+
|
15
|
+
def define_double_with_argument_expectation(double_creator, method_name, *args)
|
16
|
+
double_creator.__send__(method_name, *args)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# https://github.com/rr/rr/issues/23
|
21
|
+
unless supports_strong?
|
22
|
+
context 'by using #with and arguments' do
|
23
|
+
include_context 'using 1 of 2 ways to define a mock with an argument expectation with a times-called qualifier'
|
24
|
+
|
25
|
+
def define_double_with_argument_expectation(double_creator, method_name, *args)
|
26
|
+
double_creator.__send__(method_name).with(*args)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'defining a mock with an argument expectation with a never-called qualifier' do
|
33
|
+
context 'by passing arguments to the double definition directly' do
|
34
|
+
include_context 'using 1 of 2 ways to define a mock with an argument expectation with a never-called qualifier'
|
35
|
+
|
36
|
+
def define_double_with_argument_expectation(double_creator, method_name, *args)
|
37
|
+
double_creator.__send__(method_name, *args)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# https://github.com/rr/rr/issues/23
|
42
|
+
unless supports_strong?
|
43
|
+
context 'by using #with and arguments' do
|
44
|
+
include_context 'using 1 of 2 ways to define a mock with an argument expectation with a never-called qualifier'
|
45
|
+
|
46
|
+
def define_double_with_argument_expectation(double_creator, method_name, *args)
|
47
|
+
double_creator.__send__(method_name).with(*args)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'defining a mock with an argument expectation without any qualifiers' do
|
54
|
+
context 'by passing arguments to the double definition directly' do
|
55
|
+
include_context 'using 1 of 2 ways to define a method double with an argument expectation without any qualifiers'
|
56
|
+
|
57
|
+
specify "no error is raised if the method is never called at all" do
|
58
|
+
build_object_with_possible_methods(some_method: -> {}) do |subject|
|
59
|
+
double_creator = double_definition_creator_for(subject)
|
60
|
+
define_double_with_argument_expectation(double_creator, :some_method, 1)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
specify "a DoubleNotFoundError is raised if the method is called but not with the specified arguments" do
|
65
|
+
object = build_object_with_possible_methods(some_method: -> {}) do |subject|
|
66
|
+
double_creator = double_definition_creator_for(subject)
|
67
|
+
define_double_with_argument_expectation(double_creator, :some_method, 1)
|
68
|
+
end
|
69
|
+
expect { object.some_method }.to raise_error(RR::Errors::DoubleNotFoundError)
|
70
|
+
end
|
71
|
+
|
72
|
+
specify "a TimesCalledError is raised the moment the method is called with the specified arguments" do
|
73
|
+
object = build_object_with_possible_methods(some_method: -> {}) do |subject|
|
74
|
+
double_creator = double_definition_creator_for(subject)
|
75
|
+
define_double_with_argument_expectation(double_creator, :some_method, 1)
|
76
|
+
end
|
77
|
+
expect { object.some_method(1) }.to raise_error(RR::Errors::TimesCalledError)
|
78
|
+
end
|
79
|
+
|
80
|
+
def define_double_with_argument_expectation(double_creator, method_name, *args)
|
81
|
+
double_creator.__send__(method_name, *args)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# https://github.com/rr/rr/issues/23
|
86
|
+
unless supports_strong?
|
87
|
+
context 'by using #with and arguments' do
|
88
|
+
include_context 'using 1 of 2 ways to define a method double with an argument expectation without any qualifiers'
|
89
|
+
|
90
|
+
specify "no error is raised if the method is never called at all" do
|
91
|
+
build_object_with_possible_methods(some_method: -> {}) do |subject|
|
92
|
+
double_creator = double_definition_creator_for(subject)
|
93
|
+
define_double_with_argument_expectation(double_creator, :some_method, 1)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
specify "a DoubleNotFoundError is raised if the method is called but not with the specified arguments" do
|
98
|
+
object = build_object_with_possible_methods(some_method: -> {}) do |subject|
|
99
|
+
double_creator = double_definition_creator_for(subject)
|
100
|
+
define_double_with_argument_expectation(double_creator, :some_method, 1)
|
101
|
+
end
|
102
|
+
expect { object.some_method }.to raise_error(RR::Errors::DoubleNotFoundError)
|
103
|
+
end
|
104
|
+
|
105
|
+
specify "a TimesCalledError is raised the moment the method is called with the specified arguments" do
|
106
|
+
object = build_object_with_possible_methods(some_method: -> {}) do |subject|
|
107
|
+
double_creator = double_definition_creator_for(subject)
|
108
|
+
define_double_with_argument_expectation(double_creator, :some_method, 1)
|
109
|
+
end
|
110
|
+
expect { object.some_method(1) }.to raise_error(RR::Errors::TimesCalledError)
|
111
|
+
end
|
112
|
+
|
113
|
+
def define_double_with_argument_expectation(double_creator, method_name, *args)
|
114
|
+
double_creator.__send__(method_name).with(*args)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
it_behaves_like 'defining method doubles using the block form of the double definition creator'
|
121
|
+
it_behaves_like 'defining a method double for sequential invocations of that method using #ordered/#then'
|
122
|
+
it_behaves_like 'an object which has a method double wrapped in an array and flattened'
|
123
|
+
|
124
|
+
if supports_proxying? && !supports_instance_of?
|
125
|
+
it_behaves_like 'defining a method double on an object which is a proxy for another object'
|
126
|
+
end
|
127
|
+
|
128
|
+
if methods_being_doubled_exist_already?
|
129
|
+
it "lets you double operator methods as well as normal ones" do
|
130
|
+
object = build_object do |subject|
|
131
|
+
double_definition_creator_for(subject).==(anything) { 'value' }
|
132
|
+
end
|
133
|
+
expect_call_to_return_or_raise_times_called_error('value', object, :==, :whatever)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
if type_of_methods_being_tested == :class && methods_being_doubled_exist_already? && !supports_instance_of?
|
138
|
+
it "in a parent class doesn't affect child classes" do
|
139
|
+
parent_class = Class.new do
|
140
|
+
def self.some_method; 'existing value'; end
|
141
|
+
end
|
142
|
+
child_class = Class.new(parent_class)
|
143
|
+
double_creator = double_definition_creator_for(parent_class)
|
144
|
+
double_creator.some_method { 'value' }
|
145
|
+
expect(child_class.some_method).to eq 'existing value'
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
data/spec/suites/rspec_2/support/shared_contexts/double_definition_creators/mock_instance_of.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
shared_context 'mock + instance_of' do
|
2
|
+
include MockDefinitionCreatorHelpers
|
3
|
+
|
4
|
+
context 'where subject is a class', method_type: :class do
|
5
|
+
include_context 'tests for a double definition creator method that supports mocking'
|
6
|
+
|
7
|
+
it "lets you stub methods which are called in #initialize" do
|
8
|
+
klass = Class.new do
|
9
|
+
def initialize; method_run_in_initialize; end
|
10
|
+
def method_run_in_initialize; end
|
11
|
+
end
|
12
|
+
method_double_called = false
|
13
|
+
double_creator = double_definition_creator_for(klass)
|
14
|
+
double_creator.method_run_in_initialize { method_double_called = true }
|
15
|
+
klass.new
|
16
|
+
expect(method_double_called).to eq true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'where subject is an instance of a class', method_type: :instance do
|
21
|
+
it "doesn't work" do
|
22
|
+
double_creator = double_definition_creator_for(Object.new)
|
23
|
+
expect { double_creator.some_method }.to raise_error(ArgumentError)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
shared_context 'mock + instance_of + strong' do
|
2
|
+
include MockDefinitionCreatorHelpers
|
3
|
+
|
4
|
+
context 'where subject is a class', method_type: :class do
|
5
|
+
include_context 'tests for a double definition creator method that supports stubbing'
|
6
|
+
|
7
|
+
it_behaves_like 'comparing the arity between the method and double definition'
|
8
|
+
|
9
|
+
it "lets you stub methods which are called in #initialize" do
|
10
|
+
klass = Class.new do
|
11
|
+
def initialize; method_run_in_initialize; end
|
12
|
+
def method_run_in_initialize; end
|
13
|
+
end
|
14
|
+
method_double_called = false
|
15
|
+
double_creator = double_definition_creator_for(klass)
|
16
|
+
double_creator.method_run_in_initialize { method_double_called = true }
|
17
|
+
klass.new
|
18
|
+
expect(method_double_called).to eq true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'where subject is an instance of a class', method_type: :instance do
|
23
|
+
it "doesn't work" do
|
24
|
+
double_creator = double_definition_creator_for(Object.new)
|
25
|
+
expect { double_creator.some_method }.to raise_error(ArgumentError)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
shared_context 'mock + proxy' do
|
2
|
+
include ProxyDefinitionCreatorHelpers
|
3
|
+
|
4
|
+
context 'against instance methods', method_type: :instance do
|
5
|
+
include_context 'tests for a double definition creator method that supports mocking'
|
6
|
+
end
|
7
|
+
|
8
|
+
context 'against class methods', method_type: :class do
|
9
|
+
include_context 'tests for a double definition creator method that supports mocking'
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
shared_context 'mock + strong' do
|
2
|
+
include MockDefinitionCreatorHelpers
|
3
|
+
|
4
|
+
context 'against instance methods', method_type: :instance do
|
5
|
+
context 'that exist', methods_exist: true do
|
6
|
+
include_context 'tests for a double definition creator method that supports mocking'
|
7
|
+
|
8
|
+
it_behaves_like 'comparing the arity between the method and double definition'
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'that do not exist', methods_exist: false do
|
12
|
+
it "doesn't work" do
|
13
|
+
object = Object.new
|
14
|
+
double_creator = double_definition_creator_for(object)
|
15
|
+
expect { double_creator.some_method }.to \
|
16
|
+
raise_error(RR::Errors::SubjectDoesNotImplementMethodError)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'against class methods', method_type: :class do
|
22
|
+
context 'that exist', methods_exist: true do
|
23
|
+
include_context 'tests for a double definition creator method that supports mocking'
|
24
|
+
|
25
|
+
it_behaves_like 'comparing the arity between the method and double definition'
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'that do not exist', methods_exist: false do
|
29
|
+
it "doesn't work" do
|
30
|
+
klass = Class.new
|
31
|
+
double_creator = double_definition_creator_for(klass)
|
32
|
+
expect { double_creator.some_method }.to \
|
33
|
+
raise_error(RR::Errors::SubjectDoesNotImplementMethodError)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
shared_context 'tests for a double definition creator method that supports mocking' do
|
2
|
+
include DoubleDefinitionCreatorHelpers
|
3
|
+
|
4
|
+
specify "TimesCalledError is raised at the verify step if the method is never called" do
|
5
|
+
build_object_with_possible_methods(some_method: -> {}) do |subject|
|
6
|
+
double_creator = double_definition_creator_for(subject)
|
7
|
+
double_creator.some_method
|
8
|
+
end
|
9
|
+
expect { RR.verify }.to raise_error(RR::Errors::TimesCalledError)
|
10
|
+
end
|
11
|
+
|
12
|
+
it_behaves_like 'defining a method double that sets the implementation of that method'
|
13
|
+
|
14
|
+
context 'defining a mock with an argument expectation with a times-called qualifier' do
|
15
|
+
context 'by passing arguments to the double definition directly' do
|
16
|
+
include_context 'using 1 of 2 ways to define a mock with an argument expectation with a times-called qualifier'
|
17
|
+
|
18
|
+
def define_double_with_argument_expectation(double_creator, method_name, *args)
|
19
|
+
double_creator.__send__(method_name, *args)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# https://github.com/rr/rr/issues/23
|
24
|
+
unless supports_strong?
|
25
|
+
context 'by using #with and arguments' do
|
26
|
+
include_context 'using 1 of 2 ways to define a mock with an argument expectation with a times-called qualifier'
|
27
|
+
|
28
|
+
def define_double_with_argument_expectation(double_creator, method_name, *args)
|
29
|
+
double_creator.__send__(method_name).with(*args)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'defining a mock with an argument expectation with a never-called qualifier' do
|
36
|
+
context 'by passing arguments to the double definition directly' do
|
37
|
+
include_context 'using 1 of 2 ways to define a mock with an argument expectation with a never-called qualifier'
|
38
|
+
|
39
|
+
def define_double_with_argument_expectation(double_creator, method_name, *args)
|
40
|
+
double_creator.__send__(method_name, *args)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# https://github.com/rr/rr/issues/23
|
45
|
+
unless supports_strong?
|
46
|
+
context 'by using #with and arguments' do
|
47
|
+
include_context 'using 1 of 2 ways to define a mock with an argument expectation with a never-called qualifier'
|
48
|
+
|
49
|
+
def define_double_with_argument_expectation(double_creator, method_name, *args)
|
50
|
+
double_creator.__send__(method_name).with(*args)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'defining a mock with an argument expectation without any qualifiers' do
|
57
|
+
context 'by passing arguments to the double definition directly' do
|
58
|
+
include_context 'using 1 of 2 ways to define a method double with an argument expectation without any qualifiers'
|
59
|
+
|
60
|
+
def define_double_with_argument_expectation(double_creator, method_name, *args)
|
61
|
+
double_creator.__send__(method_name, *args)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# https://github.com/rr/rr/issues/23
|
66
|
+
unless supports_strong?
|
67
|
+
context 'by using #with and arguments' do
|
68
|
+
include_context 'using 1 of 2 ways to define a method double with an argument expectation without any qualifiers'
|
69
|
+
|
70
|
+
def define_double_with_argument_expectation(double_creator, method_name, *args)
|
71
|
+
double_creator.__send__(method_name).with(*args)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
it_behaves_like 'defining a method double qualified with #yields'
|
78
|
+
it_behaves_like 'defining method doubles using the block form of the double definition creator'
|
79
|
+
it_behaves_like 'defining a method double for sequential invocations of that method using #ordered/#then'
|
80
|
+
it_behaves_like 'an object which has a method double wrapped in an array and flattened'
|
81
|
+
|
82
|
+
if supports_proxying? && !supports_instance_of?
|
83
|
+
it_behaves_like 'defining a method double on an object which is a proxy for another object'
|
84
|
+
end
|
85
|
+
|
86
|
+
if methods_being_doubled_exist_already?
|
87
|
+
it "lets you double operator methods as well as normal ones" do
|
88
|
+
object = build_object do |subject|
|
89
|
+
double_definition_creator_for(subject).==(anything) { 'value' }
|
90
|
+
end
|
91
|
+
expect(object == :whatever).to eq 'value'
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
if type_of_methods_being_tested == :class && methods_being_doubled_exist_already? && !supports_instance_of?
|
96
|
+
it "in a parent class doesn't affect child classes" do
|
97
|
+
parent_class = Class.new do
|
98
|
+
def self.some_method; 'existing value'; end
|
99
|
+
end
|
100
|
+
child_class = Class.new(parent_class)
|
101
|
+
double_creator = double_definition_creator_for(parent_class)
|
102
|
+
double_creator.some_method { 'value' }
|
103
|
+
parent_class.some_method
|
104
|
+
expect(child_class.some_method).to eq 'existing value'
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|