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,14 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
permutations =
|
4
|
+
%w(mock strong).permutation.map { |parts| parts.join('.') }
|
5
|
+
|
6
|
+
permutations.each do |permutation|
|
7
|
+
describe permutation, is_mock: true, is_strong: true do
|
8
|
+
include_context 'mock + strong'
|
9
|
+
|
10
|
+
define_method(:double_definition_creator_for) do |object, &block|
|
11
|
+
eval(permutation + '(object, &block)')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe 'received' do
|
4
|
+
it "doesn't throw an error if the invocation occurred" do
|
5
|
+
stub(subject).pig_rabbit
|
6
|
+
subject.pig_rabbit('bacon', 'bunny meat')
|
7
|
+
received(subject).pig_rabbit('bacon', 'bunny meat').call
|
8
|
+
end
|
9
|
+
|
10
|
+
it "throws a SpyVerificationError if the invocation did not occur" do
|
11
|
+
stub(subject).pig_rabbit
|
12
|
+
expect {
|
13
|
+
received(subject).pig_rabbit('bacon', 'bunny meat').call
|
14
|
+
}.to raise_error(RR::Errors::SpyVerificationErrors::SpyVerificationError)
|
15
|
+
end
|
16
|
+
end
|
@@ -1,41 +1,102 @@
|
|
1
1
|
require File.expand_path('../../spec_helper', __FILE__)
|
2
2
|
|
3
|
-
describe '
|
4
|
-
|
3
|
+
describe 'spy' do
|
4
|
+
it "records invocations of most methods on a given object" do
|
5
|
+
subject = String.new
|
6
|
+
def subject.some_method; end
|
5
7
|
|
6
|
-
|
8
|
+
spy(subject)
|
9
|
+
|
10
|
+
subject.some_method
|
11
|
+
subject.reverse
|
12
|
+
subject.chomp
|
13
|
+
|
14
|
+
subject.should have_received.some_method
|
15
|
+
subject.should have_received.reverse
|
16
|
+
subject.should have_received.chomp
|
17
|
+
end
|
18
|
+
|
19
|
+
it "excludes #methods from the list of recorded methods" do
|
20
|
+
subject = Object.new
|
21
|
+
spy(subject)
|
22
|
+
subject.methods
|
23
|
+
subject.should_not have_received.methods
|
24
|
+
end
|
25
|
+
|
26
|
+
it "excludes #== from the list of recorded methods" do
|
27
|
+
subject = Object.new
|
28
|
+
spy(subject)
|
29
|
+
subject == 5
|
30
|
+
subject.should_not have_received(:==)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "excludes #__send__ from the list of recorded methods" do
|
34
|
+
subject = Object.new
|
35
|
+
spy(subject)
|
36
|
+
subject.__send__('to_s')
|
37
|
+
subject.should_not have_received(:__send__)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "excludes #__id__ from the list of recorded methods" do
|
7
41
|
subject = Object.new
|
42
|
+
spy(subject)
|
43
|
+
subject.__id__
|
44
|
+
subject.should_not have_received(:__id__)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "excludes #object_id from the list of recorded methods" do
|
48
|
+
subject = Object.new
|
49
|
+
spy(subject)
|
50
|
+
subject.object_id
|
51
|
+
subject.should_not have_received(:object_id)
|
52
|
+
end
|
8
53
|
|
9
|
-
|
10
|
-
|
54
|
+
it "excludes #class from the list of recorded methods" do
|
55
|
+
subject = Object.new
|
56
|
+
spy(subject)
|
57
|
+
subject.class
|
58
|
+
subject.should_not have_received.class
|
59
|
+
end
|
11
60
|
|
12
|
-
|
13
|
-
|
61
|
+
it "excludes #respond_to? from the list of recorded methods" do
|
62
|
+
subject = Object.new
|
63
|
+
spy(subject)
|
64
|
+
subject.respond_to?(:foo)
|
65
|
+
subject.should_not have_received(:respond_to?)
|
66
|
+
end
|
14
67
|
|
68
|
+
it "excludes #respond_to? from the list of recorded methods" do
|
69
|
+
subject = Object.new
|
15
70
|
spy(subject)
|
71
|
+
subject.inspect
|
72
|
+
subject.should_not have_received.inspect
|
73
|
+
end
|
16
74
|
|
17
|
-
|
18
|
-
subject.
|
75
|
+
it "excludes #respond_to? from the list of recorded methods" do
|
76
|
+
subject = Object.new
|
77
|
+
spy(subject)
|
19
78
|
subject.to_s
|
79
|
+
subject.should_not have_received.to_s
|
80
|
+
end
|
81
|
+
|
82
|
+
it "excludes #respond_to_missing? from the list of recorded methods" do
|
83
|
+
subject = Object.new
|
84
|
+
spy(subject)
|
85
|
+
subject.__send__(:respond_to_missing?, :foo, [])
|
86
|
+
subject.should_not have_received(:respond_to_missing?)
|
87
|
+
end
|
20
88
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
it "should verify method calls after the fact" do
|
35
|
-
stub(subject).pig_rabbit
|
36
|
-
expect {
|
37
|
-
received(subject).pig_rabbit("bacon", "bunny meat").call
|
38
|
-
}.to raise_error(RR::Errors::SpyVerificationErrors::SpyVerificationError)
|
39
|
-
end
|
89
|
+
it "excludes #instance_eval from the list of recorded methods" do
|
90
|
+
subject = Object.new
|
91
|
+
spy(subject)
|
92
|
+
subject.instance_eval {}
|
93
|
+
subject.should_not have_received(:instance_eval)
|
94
|
+
end
|
95
|
+
|
96
|
+
it "excludes #instance_exec from the list of recorded methods" do
|
97
|
+
subject = Object.new
|
98
|
+
spy(subject)
|
99
|
+
subject.instance_exec {}
|
100
|
+
subject.should_not have_received(:instance_exec)
|
40
101
|
end
|
41
102
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe 'stub!' do
|
4
|
+
it "is a terser way of creating an object and stubbing it" do
|
5
|
+
object = stub!.some_method { 'value' }.subject
|
6
|
+
expect(object.some_method).to eq 'value'
|
7
|
+
end
|
8
|
+
|
9
|
+
it "can be used inside the implementation block of a double" do
|
10
|
+
object = Object.new
|
11
|
+
stub(object).some_method { stub!.another_method { 'value' } }
|
12
|
+
expect(object.some_method.another_method).to eq 'value'
|
13
|
+
end
|
14
|
+
|
15
|
+
it "can be called on a double" do
|
16
|
+
object = Object.new
|
17
|
+
stub(object).some_method.stub!.another_method { 'value' }
|
18
|
+
expect(object.some_method.another_method).to eq 'value'
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
permutations =
|
4
|
+
%w(stub instance_of).permutation.map { |parts| parts.join('.') } +
|
5
|
+
%w(instance_of)
|
6
|
+
|
7
|
+
permutations.each do |permutation|
|
8
|
+
describe permutation, is_instance_of: true do
|
9
|
+
include_context 'stub + instance_of'
|
10
|
+
|
11
|
+
define_method(:double_definition_creator_for) do |object, &block|
|
12
|
+
eval(permutation + '(object, &block)')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
permutations =
|
4
|
+
(%w(stub instance_of strong).permutation.to_a + %w(instance_of strong).permutation.to_a).
|
5
|
+
map { |parts| parts.join('.') }
|
6
|
+
|
7
|
+
permutations.each do |permutation|
|
8
|
+
describe permutation, is_instance_of: true, is_strong: true do
|
9
|
+
include_context 'stub + instance_of + strong'
|
10
|
+
|
11
|
+
define_method(:double_definition_creator_for) do |object, &block|
|
12
|
+
eval(permutation + '(object, &block)')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
permutations =
|
4
|
+
%w(stub proxy instance_of).permutation.map { |parts| parts.join('.') } +
|
5
|
+
%w(proxy instance_of).permutation.map { |parts| parts.join('.') }
|
6
|
+
|
7
|
+
permutations.each do |permutation|
|
8
|
+
describe permutation, is_proxy: true, is_instance_of: true do
|
9
|
+
include_context 'stub + instance_of'
|
10
|
+
include ProxyDefinitionCreatorHelpers
|
11
|
+
|
12
|
+
define_method(:double_definition_creator_for) do |object, &block|
|
13
|
+
eval(permutation + '(object, &block)')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
permutations =
|
4
|
+
%w(stub proxy).permutation.map { |parts| parts.join('.') } +
|
5
|
+
%w(proxy)
|
6
|
+
|
7
|
+
permutations.each do |permutation|
|
8
|
+
describe permutation, is_proxy: true do
|
9
|
+
include_context 'stub + proxy'
|
10
|
+
|
11
|
+
define_method(:double_definition_creator_for) do |object, &block|
|
12
|
+
eval(permutation + '(object, &block)')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def expect_that_double_can_be_defined_without_block
|
17
|
+
_, _, return_value =
|
18
|
+
build_object_with_doubled_method_which_is_called('value', nil)
|
19
|
+
expect(return_value).to eq 'value'
|
20
|
+
end
|
21
|
+
|
22
|
+
def expect_that_double_sets_implementation(&block)
|
23
|
+
_, _, return_value =
|
24
|
+
build_object_with_doubled_method_which_is_called('value', ->(v) { v.upcase }, &block)
|
25
|
+
expect(return_value).to eq 'VALUE'
|
26
|
+
end
|
27
|
+
|
28
|
+
def expect_that_double_sets_implementation_and_resets(&block)
|
29
|
+
_, _, return_value =
|
30
|
+
build_object_with_doubled_method_which_is_reset_and_called('value', ->(v) { v.upcase }, &block)
|
31
|
+
expect(return_value).to eq 'value'
|
32
|
+
end
|
33
|
+
|
34
|
+
def expect_that_double_sets_value(&block)
|
35
|
+
_, _, return_value =
|
36
|
+
build_object_with_doubled_method_which_is_called('old value', 'new value', &block)
|
37
|
+
expect(return_value).to eq 'new value'
|
38
|
+
end
|
39
|
+
|
40
|
+
def expect_that_double_sets_value_and_resets(&block)
|
41
|
+
_, _, return_value =
|
42
|
+
build_object_with_doubled_method_which_is_reset_and_called('old value', 'new value', &block)
|
43
|
+
expect(return_value).to eq 'old value'
|
44
|
+
end
|
45
|
+
end
|
@@ -1,190 +1,71 @@
|
|
1
1
|
require File.expand_path('../../spec_helper', __FILE__)
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
describe 'stub' do
|
4
|
+
include StubDefinitionCreatorHelpers
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
method_run_in_initialize
|
10
|
-
end
|
11
|
-
|
12
|
-
def method_run_in_initialize
|
13
|
-
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe '#stub' do
|
18
|
-
subject { Object.new }
|
19
|
-
|
20
|
-
it "creates a stub DoubleInjection Double" do
|
21
|
-
stub(subject).foobar {:baz}
|
22
|
-
expect(subject.foobar("any", "thing")).to eq :baz
|
23
|
-
end
|
24
|
-
|
25
|
-
it "stubs via inline call" do
|
26
|
-
stub(subject).to_s {"a value"}
|
27
|
-
expect(subject.to_s).to eq "a value"
|
28
|
-
end
|
29
|
-
|
30
|
-
describe ".once.ordered" do
|
31
|
-
it "returns the values in the ordered called" do
|
32
|
-
stub(subject).to_s {"value 1"}.once.ordered
|
33
|
-
stub(subject).to_s {"value 2"}.once.ordered
|
34
|
-
|
35
|
-
expect(subject.to_s).to eq "value 1"
|
36
|
-
expect(subject.to_s).to eq "value 2"
|
6
|
+
context 'against instance methods', method_type: :instance do
|
7
|
+
context 'that exist', methods_exist: true do
|
8
|
+
include_context 'tests for a double definition creator method that supports stubbing'
|
37
9
|
end
|
38
|
-
end
|
39
|
-
|
40
|
-
context "when the subject is a proxy for the object with the defined method" do
|
41
|
-
it "stubs the method on the proxy object" do
|
42
|
-
proxy_target = Class.new {def foobar; :original_foobar; end}.new
|
43
|
-
proxy = Class.new do
|
44
|
-
def initialize(target)
|
45
|
-
@target = target
|
46
|
-
end
|
47
|
-
|
48
|
-
instance_methods.each do |m|
|
49
|
-
unless m =~ /^_/ || m.to_s == 'object_id' || m.to_s == 'method_missing'
|
50
|
-
alias_method "__blank_slated_#{m}", m
|
51
|
-
undef_method m
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def method_missing(method_name, *args, &block)
|
56
|
-
@target.send(method_name, *args, &block)
|
57
|
-
end
|
58
|
-
end.new(proxy_target)
|
59
|
-
expect(proxy.methods).to match_array(proxy_target.methods)
|
60
10
|
|
61
|
-
|
62
|
-
|
11
|
+
context 'that do not exist', methods_exist: false do
|
12
|
+
include_context 'tests for a double definition creator method that supports stubbing'
|
63
13
|
end
|
64
14
|
end
|
65
15
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
d.to_sym {:crazy}
|
16
|
+
context 'against class methods', method_type: :class do
|
17
|
+
context 'that exist', methods_exist: true do
|
18
|
+
include_context 'tests for a double definition creator method that supports stubbing'
|
70
19
|
end
|
71
|
-
expect(subject.to_s).to eq "a value"
|
72
|
-
expect(subject.to_sym).to eq :crazy
|
73
|
-
end
|
74
20
|
|
75
|
-
|
76
|
-
|
77
|
-
to_s {"a value"}
|
78
|
-
to_sym {:crazy}
|
21
|
+
context 'that do not exist', methods_exist: false do
|
22
|
+
include_context 'tests for a double definition creator method that supports stubbing'
|
79
23
|
end
|
80
|
-
expect(subject.to_s).to eq "a value"
|
81
|
-
expect(subject.to_sym).to eq :crazy
|
82
24
|
end
|
83
25
|
|
84
|
-
|
85
|
-
stub
|
86
|
-
o.to_s {"High Level Spec"}
|
87
|
-
end
|
88
|
-
expect(StubSpecFixture.new.to_s).to eq "High Level Spec"
|
26
|
+
def double_definition_creator_for(object, &block)
|
27
|
+
stub(object, &block)
|
89
28
|
end
|
90
29
|
|
91
|
-
|
92
|
-
|
93
|
-
|
30
|
+
def expect_that_double_can_be_defined_without_block
|
31
|
+
_, _, return_value =
|
32
|
+
build_object_with_doubled_method_which_is_called('value', nil)
|
33
|
+
expect(return_value).to eq nil
|
94
34
|
end
|
95
35
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
end
|
101
|
-
StubSpecFixture.new
|
102
|
-
expect(method_run_in_initialize_stubbed).to be_true
|
36
|
+
def expect_that_double_sets_implementation(&block)
|
37
|
+
_, _, return_value =
|
38
|
+
build_object_with_doubled_method_which_is_called('old value', -> { 'new value' }, &block)
|
39
|
+
expect(return_value).to eq 'new value'
|
103
40
|
end
|
104
41
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
o.method_run_in_initialize
|
109
|
-
end
|
110
|
-
instance = StubSpecFixture.new(1, 2) {block_called = true}
|
111
|
-
expect(instance.initialize_arguments).to eq [1, 2]
|
112
|
-
expect(block_called).to be_true
|
113
|
-
end
|
42
|
+
def expect_that_double_sets_implementation_and_resets(&block)
|
43
|
+
object, method_name, return_value =
|
44
|
+
build_object_with_doubled_method_which_is_reset_and_called('old value', -> { 'new value' }, &block)
|
114
45
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
expect(
|
120
|
-
expect(subject.foobar(4)).to eq :baz
|
46
|
+
if methods_being_doubled_exist_already?
|
47
|
+
# This doesn't work quite yet - see btakita#44
|
48
|
+
#expect(object).not_to respond_to(method_name)
|
49
|
+
else
|
50
|
+
expect(return_value).to eq 'old value'
|
121
51
|
end
|
122
52
|
end
|
123
53
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
block_caller = stub!.bar.yields.subject
|
129
|
-
block_caller.bar { called_from_block.foo }
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
context "when yields called with an argument" do
|
134
|
-
it "yields only once" do
|
135
|
-
called_from_block = mock!.foo(1).once.subject
|
136
|
-
block_caller = stub!.bar.yields(1).subject
|
137
|
-
block_caller.bar { |argument| called_from_block.foo(argument) }
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
context "when yields calls are chained" do
|
142
|
-
it "yields several times" do
|
143
|
-
pending "This test is failing with a TimesCalledError"
|
144
|
-
|
145
|
-
called_from_block = mock!.foo(1).once.then.foo(2).once.subject
|
146
|
-
block_caller = stub!.bar.yields(1).yields(2).subject
|
147
|
-
block_caller.bar { |argument| called_from_block.foo(argument) }
|
148
|
-
end
|
149
|
-
end
|
54
|
+
def expect_that_double_sets_value(&block)
|
55
|
+
_, _, return_value =
|
56
|
+
build_object_with_doubled_method_which_is_called('old value', 'new value', &block)
|
57
|
+
expect(return_value).to eq 'new value'
|
150
58
|
end
|
151
59
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
it "does not raise an error" do
|
156
|
-
stub(subject).foo
|
157
|
-
expect([subject].flatten).to eq [subject]
|
158
|
-
end
|
159
|
-
|
160
|
-
it "honors a #to_ary that already exists" do
|
161
|
-
subject.instance_eval do
|
162
|
-
def to_ary; []; end
|
163
|
-
end
|
164
|
-
stub(subject).foo
|
165
|
-
expect([subject].flatten).to eq []
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
context 'when the method being stubbed is defined' do
|
170
|
-
before do
|
171
|
-
subject.instance_eval do
|
172
|
-
def foo; end
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
it "does not raise an error" do
|
177
|
-
stub(subject).foo
|
178
|
-
expect([subject].flatten).to eq [subject]
|
179
|
-
end
|
60
|
+
def expect_that_double_sets_value_and_resets(&block)
|
61
|
+
_, _, return_value =
|
62
|
+
build_object_with_doubled_method_which_is_reset_and_called('old value', 'new value', &block)
|
180
63
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
expect([subject].flatten).to eq []
|
187
|
-
end
|
64
|
+
if methods_being_doubled_exist_already?
|
65
|
+
# This doesn't work quite yet - see btakita#44
|
66
|
+
#expect(object).not_to respond_to(method_name)
|
67
|
+
else
|
68
|
+
expect(return_value).to eq 'old value'
|
188
69
|
end
|
189
70
|
end
|
190
71
|
end
|