rr 1.1.1 → 1.1.2.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Appraisals +46 -0
- data/CHANGES.md +21 -1
- data/Gemfile +19 -0
- data/README.md +91 -106
- data/Rakefile +55 -0
- data/gemfiles/ruby_18_rspec_1.gemfile +14 -0
- data/gemfiles/ruby_18_rspec_1.gemfile.lock +38 -0
- data/gemfiles/ruby_18_rspec_1_rails_2.gemfile +18 -0
- data/gemfiles/ruby_18_rspec_1_rails_2.gemfile.lock +64 -0
- data/gemfiles/ruby_19_rspec_2.gemfile +14 -0
- data/gemfiles/ruby_19_rspec_2.gemfile.lock +49 -0
- data/gemfiles/ruby_19_rspec_2_rails_3.gemfile +15 -0
- data/gemfiles/ruby_19_rspec_2_rails_3.gemfile.lock +123 -0
- data/gemfiles/ruby_19_rspec_2_rails_4.gemfile +15 -0
- data/gemfiles/ruby_19_rspec_2_rails_4.gemfile.lock +119 -0
- data/lib/rr/adapters.rb +4 -14
- data/lib/rr/integrations.rb +13 -12
- data/lib/rr/integrations/decorator.rb +4 -1
- data/lib/rr/integrations/rspec_2.rb +6 -1
- data/lib/rr/integrations/test_unit_1.rb +2 -2
- data/lib/rr/integrations/test_unit_2.rb +3 -1
- data/lib/rr/version.rb +1 -2
- data/lib/rr/without_autohook.rb +1 -1
- data/rr.gemspec +6 -2
- data/spec/custom_formatter_for_rspec.rb +18 -0
- data/spec/custom_formatter_for_rspec_2.rb +40 -0
- data/spec/defines_spec_suite_tasks.rb +45 -0
- data/spec/fixtures/rubygems_patch_for_187.rb +598 -0
- data/spec/global_helper.rb +33 -0
- data/spec/spec.opts +3 -0
- data/spec/spec_suite_configuration.rb +132 -0
- data/spec/spec_suite_runner.rb +47 -0
- data/spec/suites.yml +24 -0
- data/spec/suites/rspec_1/helper.rb +24 -0
- data/spec/suites/rspec_1/integration/rspec_1_spec.rb +93 -0
- data/spec/suites/rspec_1/integration/test_unit_1_spec.rb +102 -0
- data/spec/suites/rspec_1/integration/test_unit_2_spec.rb +109 -0
- data/spec/suites/rspec_1/spec_helper.rb +3 -0
- data/spec/suites/rspec_1_rails_2/integration/astc_rails_2_spec.rb +141 -0
- data/spec/suites/rspec_1_rails_2/integration/rspec_1_rails_2_spec.rb +132 -0
- data/spec/suites/rspec_1_rails_2/integration/test_unit_1_rails_2_spec.rb +141 -0
- data/spec/suites/rspec_1_rails_2/integration/test_unit_2_rails_2_spec.rb +148 -0
- data/spec/suites/rspec_1_rails_2/spec_helper.rb +3 -0
- data/spec/suites/rspec_2/functional/any_instance_of_spec.rb +47 -0
- data/spec/suites/rspec_2/functional/dont_allow_spec.rb +12 -0
- data/spec/suites/rspec_2/functional/dsl_spec.rb +13 -0
- data/spec/suites/rspec_2/functional/instance_of_spec.rb +14 -0
- data/spec/suites/rspec_2/functional/mock_spec.rb +241 -0
- data/spec/suites/rspec_2/functional/proxy_spec.rb +136 -0
- data/spec/suites/rspec_2/functional/spy_spec.rb +41 -0
- data/spec/suites/rspec_2/functional/strong_spec.rb +79 -0
- data/spec/suites/rspec_2/functional/stub_spec.rb +190 -0
- data/spec/suites/rspec_2/functional/wildcard_matchers_spec.rb +128 -0
- data/spec/suites/rspec_2/helper.rb +28 -0
- data/spec/suites/rspec_2/integration/minitest_4_spec.rb +109 -0
- data/spec/suites/rspec_2/integration/minitest_spec.rb +109 -0
- data/spec/suites/rspec_2/integration/rspec_2_spec.rb +133 -0
- data/spec/suites/rspec_2/integration/test_unit_200_spec.rb +102 -0
- data/spec/suites/rspec_2/integration/test_unit_2_spec.rb +109 -0
- data/spec/suites/rspec_2/spec_helper.rb +3 -0
- data/spec/suites/rspec_2/support/matchers/wildcard_matcher_matchers.rb +32 -0
- data/spec/suites/rspec_2/support/shared_examples/space.rb +13 -0
- data/spec/suites/rspec_2/support/shared_examples/times_called_expectation.rb +9 -0
- data/spec/suites/rspec_2/unit/adapters/rr_methods/double_creators_spec.rb +135 -0
- data/spec/suites/rspec_2/unit/adapters/rr_methods/space_spec.rb +101 -0
- data/spec/suites/rspec_2/unit/adapters/rr_methods/wildcard_matchers_spec.rb +69 -0
- data/spec/suites/rspec_2/unit/core_ext/array_spec.rb +39 -0
- data/spec/suites/rspec_2/unit/core_ext/enumerable_spec.rb +81 -0
- data/spec/suites/rspec_2/unit/core_ext/hash_spec.rb +55 -0
- data/spec/suites/rspec_2/unit/core_ext/range_spec.rb +41 -0
- data/spec/suites/rspec_2/unit/core_ext/regexp_spec.rb +41 -0
- data/spec/suites/rspec_2/unit/double_definitions/child_double_definition_create_spec.rb +114 -0
- data/spec/suites/rspec_2/unit/double_definitions/double_definition_create_blank_slate_spec.rb +93 -0
- data/spec/suites/rspec_2/unit/double_definitions/double_definition_create_spec.rb +446 -0
- data/spec/suites/rspec_2/unit/errors/rr_error_spec.rb +67 -0
- data/spec/suites/rspec_2/unit/expectations/any_argument_expectation_spec.rb +48 -0
- data/spec/suites/rspec_2/unit/expectations/anything_argument_equality_expectation_spec.rb +14 -0
- data/spec/suites/rspec_2/unit/expectations/argument_equality_expectation_spec.rb +135 -0
- data/spec/suites/rspec_2/unit/expectations/boolean_argument_equality_expectation_spec.rb +30 -0
- data/spec/suites/rspec_2/unit/expectations/hash_including_argument_equality_expectation_spec.rb +82 -0
- data/spec/suites/rspec_2/unit/expectations/satisfy_argument_equality_expectation_spec.rb +61 -0
- data/spec/suites/rspec_2/unit/expectations/times_called_expectation/any_times_matcher_spec.rb +22 -0
- data/spec/suites/rspec_2/unit/expectations/times_called_expectation/at_least_matcher_spec.rb +37 -0
- data/spec/suites/rspec_2/unit/expectations/times_called_expectation/at_most_matcher_spec.rb +43 -0
- data/spec/suites/rspec_2/unit/expectations/times_called_expectation/integer_matcher_spec.rb +58 -0
- data/spec/suites/rspec_2/unit/expectations/times_called_expectation/proc_matcher_spec.rb +35 -0
- data/spec/suites/rspec_2/unit/expectations/times_called_expectation/range_matcher_spec.rb +39 -0
- data/spec/suites/rspec_2/unit/hash_with_object_id_key_spec.rb +88 -0
- data/spec/suites/rspec_2/unit/injections/double_injection/double_injection_spec.rb +545 -0
- data/spec/suites/rspec_2/unit/injections/double_injection/double_injection_verify_spec.rb +32 -0
- data/spec/suites/rspec_2/unit/integrations/rspec/invocation_matcher_spec.rb +297 -0
- data/spec/suites/rspec_2/unit/integrations/rspec_spec.rb +85 -0
- data/spec/suites/rspec_2/unit/proc_from_block_spec.rb +14 -0
- data/spec/suites/rspec_2/unit/rr_spec.rb +28 -0
- data/spec/suites/rspec_2/unit/space_spec.rb +595 -0
- data/spec/suites/rspec_2/unit/spy_verification_spec.rb +133 -0
- data/spec/suites/rspec_2/unit/times_called_matchers/any_times_matcher_spec.rb +46 -0
- data/spec/suites/rspec_2/unit/times_called_matchers/at_least_matcher_spec.rb +54 -0
- data/spec/suites/rspec_2/unit/times_called_matchers/at_most_matcher_spec.rb +69 -0
- data/spec/suites/rspec_2/unit/times_called_matchers/integer_matcher_spec.rb +69 -0
- data/spec/suites/rspec_2/unit/times_called_matchers/proc_matcher_spec.rb +54 -0
- data/spec/suites/rspec_2/unit/times_called_matchers/range_matcher_spec.rb +75 -0
- data/spec/suites/rspec_2/unit/times_called_matchers/times_called_matcher_spec.rb +117 -0
- data/spec/suites/rspec_2/unit/wildcard_matchers/anything_spec.rb +33 -0
- data/spec/suites/rspec_2/unit/wildcard_matchers/boolean_spec.rb +45 -0
- data/spec/suites/rspec_2/unit/wildcard_matchers/duck_type_spec.rb +64 -0
- data/spec/suites/rspec_2/unit/wildcard_matchers/hash_including_spec.rb +64 -0
- data/spec/suites/rspec_2/unit/wildcard_matchers/is_a_spec.rb +55 -0
- data/spec/suites/rspec_2/unit/wildcard_matchers/numeric_spec.rb +46 -0
- data/spec/suites/rspec_2/unit/wildcard_matchers/satisfy_spec.rb +57 -0
- data/spec/suites/rspec_2_rails_3/integration/astc_rails_3_spec.rb +141 -0
- data/spec/suites/rspec_2_rails_3/integration/minitest_4_rails_3_spec.rb +148 -0
- data/spec/suites/rspec_2_rails_3/integration/rspec_2_rails_3_spec.rb +172 -0
- data/spec/suites/rspec_2_rails_3/integration/test_unit_200_rails_3_spec.rb +141 -0
- data/spec/suites/rspec_2_rails_3/integration/test_unit_2_rails_3_spec.rb +148 -0
- data/spec/suites/rspec_2_rails_3/spec_helper.rb +3 -0
- data/spec/suites/rspec_2_rails_4/integration/astc_rails_4_spec.rb +142 -0
- data/spec/suites/rspec_2_rails_4/integration/minitest_4_rails_4_spec.rb +149 -0
- data/spec/suites/rspec_2_rails_4/integration/rspec_2_rails_4_spec.rb +173 -0
- data/spec/suites/rspec_2_rails_4/integration/test_unit_200_rails_4_spec.rb +142 -0
- data/spec/suites/rspec_2_rails_4/integration/test_unit_2_rails_4_spec.rb +149 -0
- data/spec/suites/rspec_2_rails_4/spec_helper.rb +3 -0
- data/spec/support/adapter.rb +22 -0
- data/spec/support/adapter_tests/base.rb +45 -0
- data/spec/support/adapter_tests/minitest.rb +7 -0
- data/spec/support/adapter_tests/rspec.rb +66 -0
- data/spec/support/adapter_tests/test_unit.rb +47 -0
- data/spec/support/command_runner.rb +105 -0
- data/spec/support/generator.rb +56 -0
- data/spec/support/integration_tests/base.rb +64 -0
- data/spec/support/integration_tests/rails.rb +60 -0
- data/spec/support/integration_tests/rails_minitest.rb +13 -0
- data/spec/support/integration_tests/rails_rspec.rb +13 -0
- data/spec/support/integration_tests/rails_test_unit.rb +13 -0
- data/spec/support/integration_tests/rails_test_unit_like.rb +13 -0
- data/spec/support/integration_tests/ruby.rb +7 -0
- data/spec/support/integration_tests/ruby_minitest.rb +13 -0
- data/spec/support/integration_tests/ruby_rspec.rb +13 -0
- data/spec/support/integration_tests/ruby_test_unit.rb +13 -0
- data/spec/support/matchers/be_a_subset_of_matcher.rb +24 -0
- data/spec/support/project/cucumber.rb +50 -0
- data/spec/support/project/generator.rb +352 -0
- data/spec/support/project/minitest.rb +39 -0
- data/spec/support/project/rails.rb +199 -0
- data/spec/support/project/rails_minitest.rb +17 -0
- data/spec/support/project/rails_rspec.rb +50 -0
- data/spec/support/project/rails_test_unit.rb +17 -0
- data/spec/support/project/rails_test_unit_like.rb +17 -0
- data/spec/support/project/rspec.rb +69 -0
- data/spec/support/project/ruby.rb +34 -0
- data/spec/support/project/ruby_minitest.rb +11 -0
- data/spec/support/project/ruby_rspec.rb +29 -0
- data/spec/support/project/ruby_test_unit.rb +11 -0
- data/spec/support/project/ruby_test_unit_like.rb +21 -0
- data/spec/support/project/test_unit.rb +29 -0
- data/spec/support/project/test_unit_like.rb +7 -0
- data/spec/support/project/tests_runner.rb +22 -0
- data/spec/support/test.sqlite3 +0 -0
- data/spec/support/test_case/generator.rb +53 -0
- data/spec/support/test_case/minitest.rb +13 -0
- data/spec/support/test_case/rspec.rb +19 -0
- data/spec/support/test_case/test_unit.rb +21 -0
- data/spec/support/test_file/generator.rb +120 -0
- data/spec/support/test_file/minitest.rb +19 -0
- data/spec/support/test_file/rails_minitest.rb +7 -0
- data/spec/support/test_file/rails_rspec.rb +12 -0
- data/spec/support/test_file/rails_test_unit.rb +25 -0
- data/spec/support/test_file/rspec.rb +33 -0
- data/spec/support/test_file/test_unit.rb +36 -0
- data/spec/support/test_helper/generator.rb +27 -0
- data/spec/support/test_helper/minitest.rb +7 -0
- data/spec/support/test_helper/rails.rb +31 -0
- data/spec/support/test_helper/rails_minitest.rb +7 -0
- data/spec/support/test_helper/rails_rspec.rb +25 -0
- data/spec/support/test_helper/rails_test_unit.rb +23 -0
- data/spec/support/test_helper/rspec.rb +7 -0
- data/spec/support/test_helper/ruby.rb +31 -0
- data/spec/support/test_helper/test_unit.rb +7 -0
- metadata +172 -6
- data/VERSION +0 -1
@@ -0,0 +1,446 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module DoubleDefinitions
|
5
|
+
describe DoubleDefinitionCreate do
|
6
|
+
subject { Object.new }
|
7
|
+
|
8
|
+
attr_reader :double_definition_create, :strategy_method_name
|
9
|
+
|
10
|
+
include_examples "Swapped Space"
|
11
|
+
|
12
|
+
before(:each) do
|
13
|
+
@double_definition_create = DoubleDefinitionCreate.new
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#root_subject" do
|
17
|
+
it "returns #subject" do
|
18
|
+
double_definition_create.stub(subject).foobar
|
19
|
+
expect(double_definition_create.root_subject).to eq subject
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "StrategySetupMethods" do
|
24
|
+
describe "normal strategy definitions" do
|
25
|
+
def call_strategy(*args, &block)
|
26
|
+
double_definition_create.__send__(strategy_method_name, *args, &block)
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#mock" do
|
30
|
+
before do
|
31
|
+
@strategy_method_name = :mock
|
32
|
+
end
|
33
|
+
|
34
|
+
context "when passing no args" do
|
35
|
+
it "returns self" do
|
36
|
+
expect(call_strategy).to equal double_definition_create
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when passed a subject and a method_name argument" do
|
41
|
+
it "creates a mock Double for method" do
|
42
|
+
double_definition = double_definition_create.mock(subject, :foobar).returns {:baz}
|
43
|
+
expect(double_definition.times_matcher).to eq RR::TimesCalledMatchers::IntegerMatcher.new(1)
|
44
|
+
expect(double_definition.argument_expectation.class).to eq RR::Expectations::ArgumentEqualityExpectation
|
45
|
+
expect(double_definition.argument_expectation.expected_arguments).to eq []
|
46
|
+
expect(subject.foobar).to eq :baz
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "#stub" do
|
52
|
+
before do
|
53
|
+
@strategy_method_name = :stub
|
54
|
+
end
|
55
|
+
|
56
|
+
context "when passing no args" do
|
57
|
+
it "returns self" do
|
58
|
+
expect(call_strategy).to equal double_definition_create
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "when passed subject and a method_name argument" do
|
63
|
+
it "creates a stub Double for method when passed a method_name argument" do
|
64
|
+
double_definition = double_definition_create.stub(subject, :foobar).returns {:baz}
|
65
|
+
expect(double_definition.times_matcher).to eq RR::TimesCalledMatchers::AnyTimesMatcher.new
|
66
|
+
expect(double_definition.argument_expectation.class).to eq RR::Expectations::AnyArgumentExpectation
|
67
|
+
expect(subject.foobar).to eq :baz
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "#dont_allow" do
|
73
|
+
before do
|
74
|
+
@strategy_method_name = :dont_allow
|
75
|
+
end
|
76
|
+
|
77
|
+
context "when passing no args" do
|
78
|
+
it "returns self" do
|
79
|
+
expect(call_strategy).to equal double_definition_create
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context "when passed a subject and a method_name argument_expectation" do
|
84
|
+
it "creates a mock Double for method" do
|
85
|
+
double_definition = double_definition_create.dont_allow(subject, :foobar)
|
86
|
+
expect(double_definition.times_matcher).to eq RR::TimesCalledMatchers::NeverMatcher.new
|
87
|
+
expect(double_definition.argument_expectation.class).to eq RR::Expectations::AnyArgumentExpectation
|
88
|
+
|
89
|
+
expect {
|
90
|
+
subject.foobar
|
91
|
+
}.to raise_error(RR::Errors::TimesCalledError)
|
92
|
+
RR.reset
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "! strategy definitions" do
|
99
|
+
attr_reader :strategy_method_name
|
100
|
+
def call_strategy(*args, &definition_eval_block)
|
101
|
+
double_definition_create.__send__(strategy_method_name, *args, &definition_eval_block)
|
102
|
+
end
|
103
|
+
|
104
|
+
describe "#mock!" do
|
105
|
+
before do
|
106
|
+
@strategy_method_name = :mock!
|
107
|
+
end
|
108
|
+
|
109
|
+
context "when passed a method_name argument" do
|
110
|
+
it "sets #verification_strategy to Mock" do
|
111
|
+
double_definition_create.mock!(:foobar)
|
112
|
+
expect(double_definition_create.verification_strategy.class).to eq Strategies::Verification::Mock
|
113
|
+
expect { RR.verify }.to raise_error(::RR::Errors::TimesCalledError)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe "#stub!" do
|
119
|
+
before do
|
120
|
+
@strategy_method_name = :stub!
|
121
|
+
end
|
122
|
+
|
123
|
+
context "when passed a method_name argument" do
|
124
|
+
it "sets #verification_strategy to Stub" do
|
125
|
+
double_definition_create.stub!(:foobar)
|
126
|
+
expect(double_definition_create.verification_strategy.class).to eq Strategies::Verification::Stub
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe "#dont_allow!" do
|
132
|
+
before do
|
133
|
+
@strategy_method_name = :dont_allow!
|
134
|
+
end
|
135
|
+
|
136
|
+
context "when passed a method_name argument" do
|
137
|
+
it "sets #verification_strategy to DontAllow" do
|
138
|
+
double_definition_create.dont_allow!(:foobar)
|
139
|
+
expect(double_definition_create.verification_strategy.class).to eq Strategies::Verification::DontAllow
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
describe "#stub.proxy" do
|
146
|
+
before do
|
147
|
+
class << subject
|
148
|
+
def foobar(*args)
|
149
|
+
:original_foobar
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
context "when passed a method_name argument" do
|
155
|
+
it "creates a proxy Double for method" do
|
156
|
+
double_definition = double_definition_create.stub.proxy(subject, :foobar).after_call {:baz}
|
157
|
+
expect(double_definition.times_matcher).to eq RR::TimesCalledMatchers::AnyTimesMatcher.new
|
158
|
+
expect(double_definition.argument_expectation.class).to eq RR::Expectations::AnyArgumentExpectation
|
159
|
+
expect(subject.foobar).to eq :baz
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
describe "#instance_of" do
|
165
|
+
context "when not passed a class" do
|
166
|
+
it "raises an ArgumentError" do
|
167
|
+
expect {
|
168
|
+
double_definition_create.instance_of(Object.new).foobar
|
169
|
+
}.to raise_error(ArgumentError, "instance_of only accepts class objects")
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
context "when passed a method_name argument" do
|
174
|
+
it "creates a proxy Double for method" do
|
175
|
+
klass = Class.new
|
176
|
+
double_definition = double_definition_create.stub.instance_of(klass, :foobar).returns {:baz}
|
177
|
+
expect(double_definition.times_matcher).to eq RR::TimesCalledMatchers::AnyTimesMatcher.new
|
178
|
+
expect(double_definition.argument_expectation.class).to eq RR::Expectations::AnyArgumentExpectation
|
179
|
+
expect(klass.new.foobar).to eq :baz
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
describe "#instance_of.mock" do
|
185
|
+
before do
|
186
|
+
@klass = Class.new
|
187
|
+
end
|
188
|
+
|
189
|
+
# context "when passed no arguments" do
|
190
|
+
# it "returns a DoubleDefinitiondouble_definition_create" do
|
191
|
+
# expect(instance_of.instance_of).to be_instance_of(DoubleDefinitionCreate)
|
192
|
+
# end
|
193
|
+
# end
|
194
|
+
|
195
|
+
context "when passed a method_name argument" do
|
196
|
+
it "creates a instance_of Double for method" do
|
197
|
+
double_definition = instance_of.mock(@klass, :foobar)
|
198
|
+
double_definition.with(1, 2) {:baz}
|
199
|
+
expect(double_definition.times_matcher).to eq RR::TimesCalledMatchers::IntegerMatcher.new(1)
|
200
|
+
expect(double_definition.argument_expectation.class).to eq RR::Expectations::ArgumentEqualityExpectation
|
201
|
+
expect(double_definition.argument_expectation.expected_arguments).to eq [1, 2]
|
202
|
+
|
203
|
+
expect(@klass.new.foobar(1, 2)).to eq :baz
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
describe "StrategyExecutionMethods" do
|
210
|
+
describe "#create" do
|
211
|
+
context "when #verification_strategy is a Mock" do
|
212
|
+
context "when #implementation_strategy is a Reimplementation" do
|
213
|
+
before do
|
214
|
+
double_definition_create.mock(subject)
|
215
|
+
end
|
216
|
+
|
217
|
+
it "sets expectation on the #subject that it will be sent the method_name once with the passed-in arguments" do
|
218
|
+
mock(subject).foobar(1, 2)
|
219
|
+
subject.foobar(1, 2)
|
220
|
+
expect { subject.foobar(1, 2) }.to raise_error(RR::Errors::TimesCalledError)
|
221
|
+
expect { RR.verify }.to raise_error(RR::Errors::TimesCalledError)
|
222
|
+
end
|
223
|
+
|
224
|
+
describe "#subject.method_name being called" do
|
225
|
+
it "returns the return value of the Double#returns block" do
|
226
|
+
double_definition_create.call(:foobar, 1, 2) {:baz}
|
227
|
+
expect(subject.foobar(1, 2)).to eq :baz
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
context "when #implementation_strategy is a Proxy" do
|
233
|
+
before do
|
234
|
+
double_definition_create.mock
|
235
|
+
double_definition_create.proxy(subject)
|
236
|
+
end
|
237
|
+
|
238
|
+
it "sets expectation on the #subject that it will be sent the method_name once with the passed-in arguments" do
|
239
|
+
def subject.foobar(*args)
|
240
|
+
:baz
|
241
|
+
end
|
242
|
+
mock(subject).foobar(1, 2)
|
243
|
+
|
244
|
+
subject.foobar(1, 2)
|
245
|
+
expect { subject.foobar(1, 2) }.to raise_error(RR::Errors::TimesCalledError)
|
246
|
+
expect { RR.verify }.to raise_error(RR::Errors::TimesCalledError)
|
247
|
+
end
|
248
|
+
|
249
|
+
describe "#subject.method_name being called" do
|
250
|
+
it "calls the original method" do
|
251
|
+
original_method_called = false
|
252
|
+
(class << subject; self; end).class_eval do
|
253
|
+
define_method(:foobar) do |*args|
|
254
|
+
original_method_called = true
|
255
|
+
end
|
256
|
+
end
|
257
|
+
double_definition_create.call(:foobar, 1, 2)
|
258
|
+
subject.foobar(1, 2)
|
259
|
+
expect(original_method_called).to be_true
|
260
|
+
end
|
261
|
+
|
262
|
+
context "when not passed a block" do
|
263
|
+
it "returns the value of the original method" do
|
264
|
+
def subject.foobar(*args)
|
265
|
+
:baz;
|
266
|
+
end
|
267
|
+
double_definition_create.call(:foobar, 1, 2)
|
268
|
+
expect(subject.foobar(1, 2)).to eq :baz
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
context "when passed a block" do
|
273
|
+
attr_reader :real_value
|
274
|
+
before do
|
275
|
+
@real_value = real_value = Object.new
|
276
|
+
(class << subject; self; end).class_eval do
|
277
|
+
define_method(:foobar) {|arg1, arg2| real_value}
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
it "calls the block with the return value of the original method" do
|
282
|
+
double_definition_create.call(:foobar, 1, 2) do |value|
|
283
|
+
mock(value).a_method {99}
|
284
|
+
value
|
285
|
+
end
|
286
|
+
subject.foobar(1, 2)
|
287
|
+
expect(real_value.a_method).to eq 99
|
288
|
+
end
|
289
|
+
|
290
|
+
it "returns the return value of the block" do
|
291
|
+
double_definition_create.call(:foobar, 1, 2) do |value|
|
292
|
+
:something_else
|
293
|
+
end
|
294
|
+
expect(subject.foobar(1, 2)).to eq :something_else
|
295
|
+
end
|
296
|
+
end
|
297
|
+
end
|
298
|
+
end
|
299
|
+
end
|
300
|
+
|
301
|
+
context "when #verification_strategy is a Stub" do
|
302
|
+
context "when #implementation_strategy is a Reimplementation" do
|
303
|
+
before do
|
304
|
+
double_definition_create.stub(subject)
|
305
|
+
end
|
306
|
+
|
307
|
+
context "when not passed a block" do
|
308
|
+
it "returns nil" do
|
309
|
+
double_definition_create.call(:foobar)
|
310
|
+
expect(subject.foobar).to be_nil
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
context "when passed a block" do
|
315
|
+
describe "#subject.method_name being called" do
|
316
|
+
it "returns the return value of the block" do
|
317
|
+
double_definition_create.call(:foobar) {:baz}
|
318
|
+
expect(subject.foobar).to eq :baz
|
319
|
+
end
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
context "when not passed args" do
|
324
|
+
describe "#subject.method_name being called with any arguments" do
|
325
|
+
it "invokes the implementation of the Stub" do
|
326
|
+
double_definition_create.call(:foobar) {:baz}
|
327
|
+
expect(subject.foobar(1, 2)).to eq :baz
|
328
|
+
expect(subject.foobar()).to eq :baz
|
329
|
+
expect(subject.foobar([])).to eq :baz
|
330
|
+
end
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
context "when passed args" do
|
335
|
+
describe "#subject.method_name being called with the passed-in arguments" do
|
336
|
+
it "invokes the implementation of the Stub" do
|
337
|
+
double_definition_create.call(:foobar, 1, 2) {:baz}
|
338
|
+
expect(subject.foobar(1, 2)).to eq :baz
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
describe "#subject.method_name being called with different arguments" do
|
343
|
+
it "raises a DoubleNotFoundError" do
|
344
|
+
double_definition_create.call(:foobar, 1, 2) {:baz}
|
345
|
+
expect {
|
346
|
+
subject.foobar
|
347
|
+
}.to raise_error(RR::Errors::DoubleNotFoundError)
|
348
|
+
end
|
349
|
+
end
|
350
|
+
end
|
351
|
+
end
|
352
|
+
|
353
|
+
context "when #implementation_strategy is a Proxy" do
|
354
|
+
before do
|
355
|
+
def subject.foobar(*args)
|
356
|
+
:original_return_value
|
357
|
+
end
|
358
|
+
double_definition_create.stub
|
359
|
+
double_definition_create.proxy(subject)
|
360
|
+
end
|
361
|
+
|
362
|
+
context "when not passed a block" do
|
363
|
+
describe "#subject.method_name being called" do
|
364
|
+
it "invokes the original implementanion" do
|
365
|
+
double_definition_create.call(:foobar)
|
366
|
+
expect(subject.foobar).to eq :original_return_value
|
367
|
+
end
|
368
|
+
end
|
369
|
+
end
|
370
|
+
|
371
|
+
context "when passed a block" do
|
372
|
+
describe "#subject.method_name being called" do
|
373
|
+
it "invokes the original implementanion and invokes the block with the return value of the original implementanion" do
|
374
|
+
passed_in_value = nil
|
375
|
+
double_definition_create.call(:foobar) do |original_return_value|
|
376
|
+
passed_in_value = original_return_value
|
377
|
+
end
|
378
|
+
subject.foobar
|
379
|
+
expect(passed_in_value).to eq :original_return_value
|
380
|
+
end
|
381
|
+
|
382
|
+
it "returns the return value of the block" do
|
383
|
+
double_definition_create.call(:foobar) do |original_return_value|
|
384
|
+
:new_return_value
|
385
|
+
end
|
386
|
+
expect(subject.foobar).to eq :new_return_value
|
387
|
+
end
|
388
|
+
end
|
389
|
+
end
|
390
|
+
|
391
|
+
context "when passed args" do
|
392
|
+
describe "#subject.method_name being called with the passed-in arguments" do
|
393
|
+
it "invokes the implementation of the Stub" do
|
394
|
+
double_definition_create.call(:foobar, 1, 2) {:baz}
|
395
|
+
expect(subject.foobar(1, 2)).to eq :baz
|
396
|
+
end
|
397
|
+
end
|
398
|
+
|
399
|
+
describe "#subject.method_name being called with different arguments" do
|
400
|
+
it "raises a DoubleNotFoundError" do
|
401
|
+
double_definition_create.call(:foobar, 1, 2) {:baz}
|
402
|
+
expect {
|
403
|
+
subject.foobar
|
404
|
+
}.to raise_error(RR::Errors::DoubleNotFoundError)
|
405
|
+
end
|
406
|
+
end
|
407
|
+
end
|
408
|
+
end
|
409
|
+
end
|
410
|
+
|
411
|
+
context "when #verification_strategy is a DontAllow" do
|
412
|
+
before do
|
413
|
+
double_definition_create.dont_allow(subject)
|
414
|
+
end
|
415
|
+
|
416
|
+
context "when not passed args" do
|
417
|
+
describe "#subject.method_name being called with any arguments" do
|
418
|
+
it "raises a TimesCalledError" do
|
419
|
+
double_definition_create.call(:foobar)
|
420
|
+
expect { subject.foobar }.to raise_error(RR::Errors::TimesCalledError)
|
421
|
+
expect { subject.foobar(1, 2) }.to raise_error(RR::Errors::TimesCalledError)
|
422
|
+
end
|
423
|
+
end
|
424
|
+
end
|
425
|
+
|
426
|
+
context "when passed args" do
|
427
|
+
describe "#subject.method_name being called with the passed-in arguments" do
|
428
|
+
it "raises a TimesCalledError" do
|
429
|
+
double_definition_create.call(:foobar, 1, 2)
|
430
|
+
expect { subject.foobar(1, 2) }.to raise_error(RR::Errors::TimesCalledError)
|
431
|
+
end
|
432
|
+
end
|
433
|
+
|
434
|
+
describe "#subject.method_name being called with different arguments" do
|
435
|
+
it "raises a DoubleNotFoundError" do
|
436
|
+
double_definition_create.call(:foobar, 1, 2)
|
437
|
+
expect { subject.foobar() }.to raise_error(RR::Errors::DoubleNotFoundError)
|
438
|
+
end
|
439
|
+
end
|
440
|
+
end
|
441
|
+
end
|
442
|
+
end
|
443
|
+
end
|
444
|
+
end
|
445
|
+
end
|
446
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module Errors
|
5
|
+
describe RRError do
|
6
|
+
describe "#backtrace" do
|
7
|
+
before do
|
8
|
+
@original_trim_backtrace = RR.trim_backtrace
|
9
|
+
end
|
10
|
+
after do
|
11
|
+
RR.trim_backtrace = @original_trim_backtrace
|
12
|
+
end
|
13
|
+
|
14
|
+
it "does not include the rr library files when trim_backtrace is true" do
|
15
|
+
RR.trim_backtrace = true
|
16
|
+
|
17
|
+
error = nil
|
18
|
+
begin
|
19
|
+
obj = Object.new
|
20
|
+
mock(obj).foobar
|
21
|
+
RR.verify_double(obj, :foobar)
|
22
|
+
rescue RRError=> e
|
23
|
+
error = e
|
24
|
+
end
|
25
|
+
backtrace = error.backtrace.join("\n")
|
26
|
+
|
27
|
+
backtrace.should_not include("lib/rr")
|
28
|
+
end
|
29
|
+
|
30
|
+
it "includes the rr library files when trim_backtrace is false" do
|
31
|
+
RR.trim_backtrace = false
|
32
|
+
|
33
|
+
error = nil
|
34
|
+
begin
|
35
|
+
obj = Object.new
|
36
|
+
mock(obj).foobar
|
37
|
+
RR.verify_double(obj, :foobar)
|
38
|
+
rescue RRError=> e
|
39
|
+
error = e
|
40
|
+
end
|
41
|
+
backtrace = error.backtrace.join("\n")
|
42
|
+
|
43
|
+
expect(backtrace).to include("lib/rr")
|
44
|
+
end
|
45
|
+
|
46
|
+
it "returns custom backtrace when backtrace is set" do
|
47
|
+
error = RRError.new
|
48
|
+
custom_backtrace = caller
|
49
|
+
error.backtrace = custom_backtrace
|
50
|
+
expect(error.backtrace).to eq custom_backtrace
|
51
|
+
end
|
52
|
+
|
53
|
+
it "returns normal backtrace when backtrace is not set" do
|
54
|
+
error = nil
|
55
|
+
expected_line = __LINE__ + 2
|
56
|
+
begin
|
57
|
+
raise RRError
|
58
|
+
rescue RRError => e
|
59
|
+
error = e
|
60
|
+
end
|
61
|
+
expect(error.backtrace.first).to include(__FILE__)
|
62
|
+
expect(error.backtrace.first).to include(expected_line.to_s)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|