shoulda-matchers 2.8.0 → 3.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.hound_config/ruby.yml +7 -0
- data/.travis.yml +11 -54
- data/Appraisals +45 -100
- data/CONTRIBUTING.md +51 -7
- data/Gemfile +7 -19
- data/Gemfile.lock +60 -134
- data/Guardfile +5 -0
- data/NEWS.md +203 -0
- data/README.md +95 -50
- data/Rakefile +1 -0
- data/doc_config/yard/templates/default/layout/html/setup.rb +1 -1
- data/gemfiles/4.0.0.gemfile +10 -7
- data/gemfiles/4.0.0.gemfile.lock +103 -79
- data/gemfiles/4.0.1.gemfile +10 -7
- data/gemfiles/4.0.1.gemfile.lock +109 -83
- data/gemfiles/4.1.gemfile +10 -7
- data/gemfiles/4.1.gemfile.lock +109 -85
- data/gemfiles/4.2.gemfile +10 -9
- data/gemfiles/4.2.gemfile.lock +86 -78
- data/lib/shoulda/matchers.rb +13 -18
- data/lib/shoulda/matchers/action_controller.rb +4 -1
- data/lib/shoulda/matchers/action_controller/flash_store.rb +95 -0
- data/lib/shoulda/matchers/action_controller/{strong_parameters_matcher.rb → permit_matcher.rb} +147 -30
- data/lib/shoulda/matchers/action_controller/redirect_to_matcher.rb +1 -1
- data/lib/shoulda/matchers/action_controller/render_template_matcher.rb +1 -1
- data/lib/shoulda/matchers/action_controller/render_with_layout_matcher.rb +1 -1
- data/lib/shoulda/matchers/action_controller/rescue_from_matcher.rb +1 -1
- data/lib/shoulda/matchers/action_controller/route_matcher.rb +5 -1
- data/lib/shoulda/matchers/action_controller/route_params.rb +15 -6
- data/lib/shoulda/matchers/action_controller/session_store.rb +34 -0
- data/lib/shoulda/matchers/action_controller/set_flash_matcher.rb +30 -136
- data/lib/shoulda/matchers/action_controller/set_session_matcher.rb +28 -109
- data/lib/shoulda/matchers/action_controller/set_session_or_flash_matcher.rb +103 -0
- data/lib/shoulda/matchers/active_model/allow_mass_assignment_of_matcher.rb +1 -12
- data/lib/shoulda/matchers/active_model/allow_value_matcher.rb +79 -10
- data/lib/shoulda/matchers/active_model/numericality_matchers/numeric_type_matcher.rb +10 -0
- data/lib/shoulda/matchers/active_model/validate_absence_of_matcher.rb +21 -0
- data/lib/shoulda/matchers/active_model/validate_acceptance_of_matcher.rb +24 -0
- data/lib/shoulda/matchers/active_model/validate_confirmation_of_matcher.rb +22 -5
- data/lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb +29 -10
- data/lib/shoulda/matchers/active_model/validate_inclusion_of_matcher.rb +27 -10
- data/lib/shoulda/matchers/active_model/validate_length_of_matcher.rb +27 -12
- data/lib/shoulda/matchers/active_model/validate_numericality_of_matcher.rb +56 -20
- data/lib/shoulda/matchers/active_model/validate_presence_of_matcher.rb +3 -11
- data/lib/shoulda/matchers/active_model/validation_message_finder.rb +65 -0
- data/lib/shoulda/matchers/active_record/association_matcher.rb +40 -6
- data/lib/shoulda/matchers/active_record/association_matchers/join_table_matcher.rb +21 -7
- data/lib/shoulda/matchers/active_record/association_matchers/model_reflection.rb +11 -40
- data/lib/shoulda/matchers/active_record/association_matchers/model_reflector.rb +1 -1
- data/lib/shoulda/matchers/active_record/define_enum_for_matcher.rb +2 -6
- data/lib/shoulda/matchers/active_record/validate_uniqueness_of_matcher.rb +137 -22
- data/lib/shoulda/matchers/configuration.rb +20 -0
- data/lib/shoulda/matchers/doublespeak.rb +11 -1
- data/lib/shoulda/matchers/doublespeak/double.rb +29 -11
- data/lib/shoulda/matchers/doublespeak/double_collection.rb +4 -3
- data/lib/shoulda/matchers/doublespeak/method_call.rb +35 -0
- data/lib/shoulda/matchers/doublespeak/object_double.rb +7 -2
- data/lib/shoulda/matchers/doublespeak/proxy_implementation.rb +4 -3
- data/lib/shoulda/matchers/doublespeak/stub_implementation.rb +3 -3
- data/lib/shoulda/matchers/doublespeak/world.rb +21 -1
- data/lib/shoulda/matchers/integrations.rb +43 -0
- data/lib/shoulda/matchers/integrations/configuration.rb +68 -0
- data/lib/shoulda/matchers/integrations/configuration_error.rb +9 -0
- data/lib/shoulda/matchers/integrations/inclusion.rb +20 -0
- data/lib/shoulda/matchers/integrations/libraries.rb +15 -0
- data/lib/shoulda/matchers/integrations/libraries/action_controller.rb +31 -0
- data/lib/shoulda/matchers/integrations/libraries/active_model.rb +26 -0
- data/lib/shoulda/matchers/integrations/libraries/active_record.rb +26 -0
- data/lib/shoulda/matchers/integrations/libraries/missing_library.rb +19 -0
- data/lib/shoulda/matchers/integrations/libraries/rails.rb +30 -0
- data/lib/shoulda/matchers/integrations/rails.rb +12 -0
- data/lib/shoulda/matchers/integrations/registry.rb +28 -0
- data/lib/shoulda/matchers/integrations/test_frameworks.rb +16 -0
- data/lib/shoulda/matchers/integrations/test_frameworks/active_support_test_case.rb +37 -0
- data/lib/shoulda/matchers/integrations/test_frameworks/minitest_4.rb +36 -0
- data/lib/shoulda/matchers/integrations/test_frameworks/minitest_5.rb +37 -0
- data/lib/shoulda/matchers/integrations/test_frameworks/missing_test_framework.rb +40 -0
- data/lib/shoulda/matchers/integrations/test_frameworks/rspec.rb +29 -0
- data/lib/shoulda/matchers/integrations/test_frameworks/test_unit.rb +36 -0
- data/lib/shoulda/matchers/rails_shim.rb +0 -40
- data/lib/shoulda/matchers/version.rb +1 -1
- data/script/SUPPORTED_VERSIONS +1 -1
- data/script/update_gems_in_all_appraisals +14 -0
- data/shoulda-matchers.gemspec +2 -2
- data/spec/acceptance/active_model_integration_spec.rb +4 -1
- data/spec/acceptance/independent_matchers_spec.rb +6 -6
- data/spec/acceptance/multiple_libraries_integration_spec.rb +52 -0
- data/spec/acceptance/rails_integration_spec.rb +15 -5
- data/spec/acceptance_spec_helper.rb +8 -0
- data/spec/doublespeak_spec_helper.rb +14 -0
- data/spec/support/acceptance/adds_shoulda_matchers_to_project.rb +110 -0
- data/spec/support/acceptance/helpers.rb +2 -0
- data/spec/support/acceptance/helpers/base_helpers.rb +6 -1
- data/spec/support/acceptance/helpers/command_helpers.rb +6 -2
- data/spec/support/acceptance/helpers/minitest_helpers.rb +0 -8
- data/spec/support/acceptance/helpers/n_unit_helpers.rb +25 -0
- data/spec/support/acceptance/helpers/rspec_helpers.rb +2 -0
- data/spec/support/acceptance/helpers/step_helpers.rb +13 -19
- data/spec/support/acceptance/matchers/have_output.rb +1 -1
- data/spec/support/tests/bundle.rb +1 -1
- data/spec/support/tests/command_runner.rb +25 -13
- data/spec/support/tests/current_bundle.rb +47 -0
- data/spec/support/tests/database.rb +28 -0
- data/spec/support/tests/database_adapters/postgresql.rb +25 -0
- data/spec/support/tests/database_adapters/sqlite3.rb +26 -0
- data/spec/support/tests/database_configuration.rb +33 -0
- data/spec/support/tests/database_configuration_registry.rb +28 -0
- data/spec/support/tests/filesystem.rb +25 -2
- data/spec/support/unit/helpers/active_record_versions.rb +12 -0
- data/spec/support/unit/helpers/class_builder.rb +6 -2
- data/spec/support/unit/helpers/column_type_helpers.rb +26 -0
- data/spec/support/unit/helpers/controller_builder.rb +0 -28
- data/spec/support/unit/helpers/database_helpers.rb +18 -0
- data/spec/support/unit/helpers/model_builder.rb +38 -6
- data/spec/support/unit/helpers/rails_versions.rb +2 -2
- data/spec/support/unit/matchers/fail_with_message_including_matcher.rb +9 -8
- data/spec/support/unit/matchers/fail_with_message_matcher.rb +1 -1
- data/spec/support/unit/rails_application.rb +29 -13
- data/spec/support/unit/record_validating_confirmation_builder.rb +1 -2
- data/spec/support/unit/shared_examples/set_session_or_flash.rb +355 -0
- data/spec/unit/shoulda/matchers/action_controller/permit_matcher_spec.rb +433 -0
- data/spec/unit/shoulda/matchers/action_controller/render_with_layout_matcher_spec.rb +1 -5
- data/spec/unit/shoulda/matchers/action_controller/route_matcher_spec.rb +37 -0
- data/spec/unit/shoulda/matchers/action_controller/set_flash_matcher_spec.rb +23 -147
- data/spec/unit/shoulda/matchers/action_controller/set_session_matcher_spec.rb +8 -285
- data/spec/unit/shoulda/matchers/action_controller/set_session_or_flash_matcher_spec.rb +562 -0
- data/spec/unit/shoulda/matchers/active_model/allow_value_matcher_spec.rb +81 -14
- data/spec/unit/shoulda/matchers/active_model/disallow_value_matcher_spec.rb +16 -8
- data/spec/unit/shoulda/matchers/active_model/numericality_matchers/comparison_matcher_spec.rb +101 -9
- data/spec/unit/shoulda/matchers/active_model/numericality_matchers/even_number_matcher_spec.rb +39 -1
- data/spec/unit/shoulda/matchers/active_model/numericality_matchers/odd_number_matcher_spec.rb +39 -1
- data/spec/unit/shoulda/matchers/active_model/numericality_matchers/only_integer_matcher_spec.rb +39 -0
- data/spec/unit/shoulda/matchers/active_model/validate_exclusion_of_matcher_spec.rb +0 -17
- data/spec/unit/shoulda/matchers/active_model/validate_inclusion_of_matcher_spec.rb +0 -17
- data/spec/unit/shoulda/matchers/active_model/validate_length_of_matcher_spec.rb +0 -17
- data/spec/unit/shoulda/matchers/active_model/validate_numericality_of_matcher_spec.rb +838 -271
- data/spec/unit/shoulda/matchers/active_model/validate_presence_of_matcher_spec.rb +0 -19
- data/spec/unit/shoulda/matchers/active_record/association_matcher_spec.rb +93 -0
- data/spec/unit/shoulda/matchers/active_record/association_matchers/model_reflection_spec.rb +3 -3
- data/spec/unit/shoulda/matchers/active_record/define_enum_for_matcher_spec.rb +25 -0
- data/spec/unit/shoulda/matchers/active_record/validate_uniqueness_of_matcher_spec.rb +905 -0
- data/spec/unit/shoulda/matchers/doublespeak/double_collection_spec.rb +17 -11
- data/spec/unit/shoulda/matchers/doublespeak/double_implementation_registry_spec.rb +1 -1
- data/spec/unit/shoulda/matchers/doublespeak/double_spec.rb +144 -43
- data/spec/unit/shoulda/matchers/doublespeak/object_double_spec.rb +1 -1
- data/spec/unit/shoulda/matchers/doublespeak/proxy_implementation_spec.rb +36 -11
- data/spec/unit/shoulda/matchers/doublespeak/stub_implementation_spec.rb +29 -16
- data/spec/unit/shoulda/matchers/doublespeak/world_spec.rb +8 -5
- data/spec/unit/shoulda/matchers/doublespeak_spec.rb +1 -1
- data/spec/unit_spec_helper.rb +15 -14
- data/spec/warnings_spy.rb +1 -1
- metadata +68 -29
- data/docs.watchr +0 -5
- data/gemfiles/3.0.gemfile +0 -26
- data/gemfiles/3.0.gemfile.lock +0 -173
- data/gemfiles/3.1.gemfile +0 -32
- data/gemfiles/3.1.gemfile.lock +0 -212
- data/gemfiles/3.1_1.9.2.gemfile +0 -32
- data/gemfiles/3.1_1.9.2.gemfile.lock +0 -212
- data/gemfiles/3.2.gemfile +0 -33
- data/gemfiles/3.2.gemfile.lock +0 -212
- data/gemfiles/3.2_1.9.2.gemfile +0 -31
- data/gemfiles/3.2_1.9.2.gemfile.lock +0 -207
- data/lib/shoulda/matchers/assertion_error.rb +0 -27
- data/lib/shoulda/matchers/doublespeak/structs.rb +0 -10
- data/lib/shoulda/matchers/integrations/nunit_test_case_detection.rb +0 -39
- data/lib/shoulda/matchers/integrations/rspec.rb +0 -19
- data/lib/shoulda/matchers/integrations/test_unit.rb +0 -34
- data/spec/unit/shoulda/matchers/action_controller/strong_parameters_matcher_spec.rb +0 -331
- data/spec/unit/shoulda/matchers/active_model/validate_uniqueness_of_matcher_spec.rb +0 -564
@@ -1,11 +1,11 @@
|
|
1
|
-
require '
|
1
|
+
require 'doublespeak_spec_helper'
|
2
2
|
|
3
3
|
module Shoulda::Matchers::Doublespeak
|
4
4
|
describe DoubleCollection do
|
5
5
|
describe '#register_stub' do
|
6
6
|
it 'calls DoubleImplementationRegistry.find correctly' do
|
7
7
|
allow(DoubleImplementationRegistry).to receive(:find)
|
8
|
-
double_collection = described_class.new(:klass)
|
8
|
+
double_collection = described_class.new(build_world, :klass)
|
9
9
|
|
10
10
|
double_collection.register_stub(:a_method)
|
11
11
|
|
@@ -13,24 +13,25 @@ module Shoulda::Matchers::Doublespeak
|
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'calls Double.new correctly' do
|
16
|
+
world = build_world
|
16
17
|
allow(DoubleImplementationRegistry).
|
17
18
|
to receive(:find).
|
18
19
|
and_return(:implementation)
|
19
20
|
allow(Double).to receive(:new)
|
20
|
-
double_collection = described_class.new(:klass)
|
21
|
+
double_collection = described_class.new(world, :klass)
|
21
22
|
|
22
23
|
double_collection.register_stub(:a_method)
|
23
24
|
|
24
25
|
expect(Double).
|
25
26
|
to have_received(:new).
|
26
|
-
with(:klass, :a_method, :implementation)
|
27
|
+
with(world, :klass, :a_method, :implementation)
|
27
28
|
end
|
28
29
|
end
|
29
30
|
|
30
31
|
describe '#register_proxy' do
|
31
32
|
it 'calls DoubleImplementationRegistry.find correctly' do
|
32
33
|
allow(DoubleImplementationRegistry).to receive(:find)
|
33
|
-
double_collection = described_class.new(:klass)
|
34
|
+
double_collection = described_class.new(build_world, :klass)
|
34
35
|
|
35
36
|
double_collection.register_proxy(:a_method)
|
36
37
|
|
@@ -40,24 +41,25 @@ module Shoulda::Matchers::Doublespeak
|
|
40
41
|
end
|
41
42
|
|
42
43
|
it 'calls Double.new correctly' do
|
44
|
+
world = build_world
|
43
45
|
allow(DoubleImplementationRegistry).
|
44
46
|
to receive(:find).
|
45
47
|
and_return(:implementation)
|
46
48
|
allow(Double).to receive(:new)
|
47
|
-
double_collection = described_class.new(:klass)
|
49
|
+
double_collection = described_class.new(world, :klass)
|
48
50
|
|
49
51
|
double_collection.register_proxy(:a_method)
|
50
52
|
|
51
53
|
expect(Double).
|
52
54
|
to have_received(:new).
|
53
|
-
with(:klass, :a_method, :implementation)
|
55
|
+
with(world, :klass, :a_method, :implementation)
|
54
56
|
end
|
55
57
|
end
|
56
58
|
|
57
59
|
describe '#activate' do
|
58
60
|
it 'replaces all registered methods with doubles' do
|
59
61
|
klass = create_class(first_method: 1, second_method: 2)
|
60
|
-
double_collection = described_class.new(klass)
|
62
|
+
double_collection = described_class.new(build_world, klass)
|
61
63
|
double_collection.register_stub(:first_method)
|
62
64
|
double_collection.register_stub(:second_method)
|
63
65
|
|
@@ -72,7 +74,7 @@ module Shoulda::Matchers::Doublespeak
|
|
72
74
|
describe '#deactivate' do
|
73
75
|
it 'restores the original methods that were doubled' do
|
74
76
|
klass = create_class(first_method: 1, second_method: 2)
|
75
|
-
double_collection = described_class.new(klass)
|
77
|
+
double_collection = described_class.new(build_world, klass)
|
76
78
|
double_collection.register_stub(:first_method)
|
77
79
|
double_collection.register_stub(:second_method)
|
78
80
|
|
@@ -88,7 +90,7 @@ module Shoulda::Matchers::Doublespeak
|
|
88
90
|
describe '#calls_to' do
|
89
91
|
it 'returns all calls to the given method' do
|
90
92
|
klass = create_class(a_method: nil)
|
91
|
-
double_collection = described_class.new(klass)
|
93
|
+
double_collection = described_class.new(build_world, klass)
|
92
94
|
double_collection.register_stub(:a_method)
|
93
95
|
double_collection.activate
|
94
96
|
|
@@ -108,7 +110,7 @@ module Shoulda::Matchers::Doublespeak
|
|
108
110
|
|
109
111
|
it 'returns an empty array if the method has never been doubled' do
|
110
112
|
klass = create_class
|
111
|
-
double_collection = described_class.new(klass)
|
113
|
+
double_collection = described_class.new(build_world, klass)
|
112
114
|
expect(double_collection.calls_to(:non_existent_method)).to eq []
|
113
115
|
end
|
114
116
|
end
|
@@ -120,5 +122,9 @@ module Shoulda::Matchers::Doublespeak
|
|
120
122
|
end
|
121
123
|
end
|
122
124
|
end
|
125
|
+
|
126
|
+
def build_world
|
127
|
+
Shoulda::Matchers::Doublespeak::World.new
|
128
|
+
end
|
123
129
|
end
|
124
130
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'doublespeak_spec_helper'
|
2
2
|
|
3
3
|
module Shoulda::Matchers::Doublespeak
|
4
4
|
describe Double do
|
@@ -11,14 +11,24 @@ module Shoulda::Matchers::Doublespeak
|
|
11
11
|
implementation.singleton_class.__send__(:define_method, :returns) do |&block|
|
12
12
|
actual_block = block
|
13
13
|
end
|
14
|
-
double = described_class.new(
|
14
|
+
double = described_class.new(
|
15
|
+
:a_world,
|
16
|
+
:klass,
|
17
|
+
:a_method,
|
18
|
+
implementation
|
19
|
+
)
|
15
20
|
double.to_return(&sent_block)
|
16
21
|
expect(actual_block).to eq sent_block
|
17
22
|
end
|
18
23
|
|
19
24
|
it 'tells its implementation to return the given value' do
|
20
25
|
implementation = build_implementation
|
21
|
-
double = described_class.new(
|
26
|
+
double = described_class.new(
|
27
|
+
:a_world,
|
28
|
+
:klass,
|
29
|
+
:a_method,
|
30
|
+
implementation
|
31
|
+
)
|
22
32
|
double.to_return(:implementation)
|
23
33
|
|
24
34
|
expect(implementation).to have_received(:returns).with(:implementation)
|
@@ -32,7 +42,12 @@ module Shoulda::Matchers::Doublespeak
|
|
32
42
|
implementation.singleton_class.__send__(:define_method, :returns) do |&block|
|
33
43
|
actual_block = block
|
34
44
|
end
|
35
|
-
double = described_class.new(
|
45
|
+
double = described_class.new(
|
46
|
+
:a_world,
|
47
|
+
:klass,
|
48
|
+
:a_method,
|
49
|
+
implementation
|
50
|
+
)
|
36
51
|
double.to_return(:value, &sent_block)
|
37
52
|
expect(actual_block).to eq sent_block
|
38
53
|
end
|
@@ -41,27 +56,47 @@ module Shoulda::Matchers::Doublespeak
|
|
41
56
|
describe '#activate' do
|
42
57
|
it 'replaces the method with an implementation' do
|
43
58
|
implementation = build_implementation
|
44
|
-
|
59
|
+
method_name = :a_method
|
60
|
+
klass = create_class(method_name => :some_return_value)
|
45
61
|
instance = klass.new
|
46
|
-
double = described_class.new(
|
62
|
+
double = described_class.new(
|
63
|
+
build_world,
|
64
|
+
klass,
|
65
|
+
method_name,
|
66
|
+
implementation
|
67
|
+
)
|
47
68
|
args = [:any, :args]
|
48
69
|
block = -> {}
|
70
|
+
call = MethodCall.new(
|
71
|
+
double: double,
|
72
|
+
object: instance,
|
73
|
+
method_name: method_name,
|
74
|
+
args: args,
|
75
|
+
block: block
|
76
|
+
)
|
49
77
|
|
50
78
|
double.activate
|
51
|
-
instance.
|
79
|
+
instance.__send__(method_name, *args, &block)
|
52
80
|
|
53
81
|
expect(implementation).
|
54
82
|
to have_received(:call).
|
55
|
-
with(
|
83
|
+
with(call)
|
56
84
|
end
|
57
85
|
end
|
58
86
|
|
59
87
|
describe '#deactivate' do
|
60
88
|
it 'restores the original method after being doubled' do
|
61
|
-
implementation = build_implementation
|
62
89
|
klass = create_class(a_method: 42)
|
90
|
+
world = build_world(
|
91
|
+
original_method_for: klass.instance_method(:a_method)
|
92
|
+
)
|
63
93
|
instance = klass.new
|
64
|
-
double = described_class.new(
|
94
|
+
double = described_class.new(
|
95
|
+
world,
|
96
|
+
klass,
|
97
|
+
:a_method,
|
98
|
+
build_implementation
|
99
|
+
)
|
65
100
|
|
66
101
|
double.activate
|
67
102
|
double.deactivate
|
@@ -69,10 +104,18 @@ module Shoulda::Matchers::Doublespeak
|
|
69
104
|
end
|
70
105
|
|
71
106
|
it 'still restores the original method if #activate was called twice' do
|
72
|
-
|
73
|
-
klass = create_class(
|
107
|
+
method_name = :a_method
|
108
|
+
klass = create_class(method_name => 42)
|
109
|
+
world = build_world(
|
110
|
+
original_method_for: klass.instance_method(:a_method)
|
111
|
+
)
|
74
112
|
instance = klass.new
|
75
|
-
double = described_class.new(
|
113
|
+
double = described_class.new(
|
114
|
+
world,
|
115
|
+
klass,
|
116
|
+
:a_method,
|
117
|
+
build_implementation
|
118
|
+
)
|
76
119
|
|
77
120
|
double.activate
|
78
121
|
double.activate
|
@@ -81,10 +124,14 @@ module Shoulda::Matchers::Doublespeak
|
|
81
124
|
end
|
82
125
|
|
83
126
|
it 'does nothing if the method has not been doubled' do
|
84
|
-
implementation = build_implementation
|
85
127
|
klass = create_class(a_method: 42)
|
86
128
|
instance = klass.new
|
87
|
-
double = described_class.new(
|
129
|
+
double = described_class.new(
|
130
|
+
:a_world,
|
131
|
+
klass,
|
132
|
+
:a_method,
|
133
|
+
build_implementation
|
134
|
+
)
|
88
135
|
|
89
136
|
double.deactivate
|
90
137
|
expect(instance.a_method).to eq 42
|
@@ -92,50 +139,96 @@ module Shoulda::Matchers::Doublespeak
|
|
92
139
|
end
|
93
140
|
|
94
141
|
describe '#record_call' do
|
95
|
-
it '
|
96
|
-
double = described_class.new(
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
double.record_call(
|
103
|
-
|
104
|
-
expect(double.calls[0].args).to eq calls[0][0]
|
105
|
-
expect(double.calls[0].block).to eq calls[0][1]
|
106
|
-
expect(double.calls[1].args).to eq calls[1][0]
|
142
|
+
it 'adds the given call to the list of calls' do
|
143
|
+
double = described_class.new(
|
144
|
+
:a_world,
|
145
|
+
:a_klass,
|
146
|
+
:a_method,
|
147
|
+
:an_implementation
|
148
|
+
)
|
149
|
+
double.record_call(:some_call)
|
150
|
+
expect(double.calls.last).to eq :some_call
|
107
151
|
end
|
108
152
|
end
|
109
153
|
|
110
154
|
describe '#call_original_method' do
|
111
|
-
it 'binds the stored method object to the
|
112
|
-
klass = create_class
|
113
|
-
instance = klass.new
|
114
|
-
actual_args = actual_block = method_called = nil
|
155
|
+
it 'binds the stored method object to the given object and calls it with the given args and block' do
|
115
156
|
expected_args = [:one, :two, :three]
|
116
157
|
expected_block = -> { }
|
117
|
-
|
118
|
-
|
119
|
-
klass
|
120
|
-
|
121
|
-
|
158
|
+
actual_args = actual_block = method_called = nil
|
159
|
+
method_name = :a_method
|
160
|
+
klass = create_class
|
161
|
+
klass.__send__(:define_method, method_name) do |*args, &block|
|
162
|
+
actual_args = args
|
163
|
+
actual_block = block
|
122
164
|
method_called = true
|
123
165
|
end
|
166
|
+
world = build_world(
|
167
|
+
original_method_for: klass.instance_method(method_name)
|
168
|
+
)
|
169
|
+
instance = klass.new
|
170
|
+
call = double('call',
|
171
|
+
object: instance,
|
172
|
+
method_name: method_name,
|
173
|
+
args: expected_args,
|
174
|
+
block: expected_block
|
175
|
+
)
|
176
|
+
double = described_class.new(
|
177
|
+
world,
|
178
|
+
klass,
|
179
|
+
method_name,
|
180
|
+
:an_implementation
|
181
|
+
)
|
124
182
|
|
125
183
|
double.activate
|
126
|
-
double.call_original_method(
|
184
|
+
double.call_original_method(call)
|
127
185
|
|
128
|
-
expect(
|
129
|
-
expect(
|
186
|
+
expect(actual_args).to eq expected_args
|
187
|
+
expect(actual_block).to eq expected_block
|
130
188
|
expect(method_called).to eq true
|
131
189
|
end
|
132
190
|
|
133
191
|
it 'does nothing if no method has been stored' do
|
134
|
-
|
192
|
+
method_name = :a_method
|
193
|
+
world = build_world(original_method_for: nil)
|
194
|
+
call = double('call', method_name: method_name)
|
195
|
+
double = described_class.new(
|
196
|
+
world,
|
197
|
+
:klass,
|
198
|
+
method_name,
|
199
|
+
:an_implementation
|
200
|
+
)
|
201
|
+
expect { double.call_original_method(call) }.not_to raise_error
|
202
|
+
end
|
203
|
+
|
204
|
+
it 'does not store the original method multiple times when a method is doubled multiple times' do
|
205
|
+
world = Shoulda::Matchers::Doublespeak::World.new
|
206
|
+
klass = create_class(a_method: :some_return_value)
|
207
|
+
method_name = :a_method
|
208
|
+
doubles = 2.times.map do
|
209
|
+
described_class.new(
|
210
|
+
world,
|
211
|
+
klass,
|
212
|
+
method_name,
|
213
|
+
build_implementation
|
214
|
+
)
|
215
|
+
end
|
216
|
+
instance = klass.new
|
217
|
+
|
218
|
+
doubles[0].activate
|
219
|
+
|
220
|
+
was_called = false
|
221
|
+
klass.__send__(:define_method, method_name) do
|
222
|
+
was_called = true
|
223
|
+
end
|
224
|
+
|
225
|
+
doubles[1].activate
|
226
|
+
|
227
|
+
doubles.each(&:deactivate)
|
135
228
|
|
136
|
-
|
137
|
-
|
138
|
-
|
229
|
+
instance.__send__(method_name)
|
230
|
+
|
231
|
+
expect(was_called).to be false
|
139
232
|
end
|
140
233
|
end
|
141
234
|
|
@@ -150,5 +243,13 @@ module Shoulda::Matchers::Doublespeak
|
|
150
243
|
def build_implementation
|
151
244
|
double('implementation', returns: nil, call: nil)
|
152
245
|
end
|
246
|
+
|
247
|
+
def build_world(methods = {})
|
248
|
+
defaults = {
|
249
|
+
original_method_for: nil,
|
250
|
+
store_original_method_for: nil
|
251
|
+
}
|
252
|
+
double('world', defaults.merge(methods))
|
253
|
+
end
|
153
254
|
end
|
154
255
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'doublespeak_spec_helper'
|
2
2
|
|
3
3
|
module Shoulda::Matchers::Doublespeak
|
4
4
|
describe ProxyImplementation do
|
@@ -13,26 +13,45 @@ module Shoulda::Matchers::Doublespeak
|
|
13
13
|
end
|
14
14
|
|
15
15
|
describe '#call' do
|
16
|
+
it 'calls #call_original_method on the double' do
|
17
|
+
stub_implementation = build_stub_implementation
|
18
|
+
double = build_double
|
19
|
+
call = build_call(double: double)
|
20
|
+
allow(double).to receive(:call_original_method)
|
21
|
+
implementation = described_class.new(stub_implementation)
|
22
|
+
|
23
|
+
implementation.call(call)
|
24
|
+
|
25
|
+
expect(double).
|
26
|
+
to have_received(:call_original_method).
|
27
|
+
with(call)
|
28
|
+
end
|
29
|
+
|
16
30
|
it 'delegates to its stub_implementation' do
|
17
31
|
stub_implementation = build_stub_implementation
|
18
32
|
double = build_double
|
33
|
+
call2 = build_call
|
34
|
+
call = build_call(double: double, with_return_value: call2)
|
35
|
+
allow(double).to receive(:call_original_method)
|
19
36
|
implementation = described_class.new(stub_implementation)
|
20
|
-
|
37
|
+
|
38
|
+
implementation.call(call)
|
21
39
|
|
22
40
|
expect(stub_implementation).
|
23
41
|
to have_received(:call).
|
24
|
-
with(
|
42
|
+
with(call2)
|
25
43
|
end
|
26
44
|
|
27
|
-
it '
|
45
|
+
it 'returns the return value of the original method' do
|
46
|
+
return_value = :some_return_value
|
28
47
|
stub_implementation = build_stub_implementation
|
48
|
+
double = build_double(call_original_method: return_value)
|
49
|
+
call = build_call(double: double)
|
29
50
|
implementation = described_class.new(stub_implementation)
|
30
|
-
double = build_double
|
31
|
-
implementation.call(double, :object, :args, :block)
|
32
51
|
|
33
|
-
|
34
|
-
|
35
|
-
|
52
|
+
return_value = implementation.call(call)
|
53
|
+
|
54
|
+
expect(return_value).to be return_value
|
36
55
|
end
|
37
56
|
end
|
38
57
|
|
@@ -40,8 +59,14 @@ module Shoulda::Matchers::Doublespeak
|
|
40
59
|
double('stub_implementation', returns: nil, call: nil)
|
41
60
|
end
|
42
61
|
|
43
|
-
def build_double
|
44
|
-
|
62
|
+
def build_double(methods = {})
|
63
|
+
defaults = { call_original_method: nil }
|
64
|
+
double('double', defaults.merge(methods))
|
65
|
+
end
|
66
|
+
|
67
|
+
def build_call(methods = {})
|
68
|
+
defaults = { double: build_double, with_return_value: nil }
|
69
|
+
double('call', defaults.merge(methods))
|
45
70
|
end
|
46
71
|
end
|
47
72
|
end
|