rr 1.1.1 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Appraisals +6 -0
- data/CHANGES.md +102 -1
- data/CREDITS.md +5 -0
- data/Gemfile +3 -0
- data/README.md +91 -110
- data/Rakefile +43 -0
- data/doc/02_syntax_comparison.md +1 -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_4.gemfile +15 -0
- data/gemfiles/ruby_19_rspec_2_rails_4.gemfile.lock +119 -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 +67 -19
- data/lib/rr/injections/method_missing_injection.rb +37 -6
- data/lib/rr/integrations.rb +13 -12
- data/lib/rr/integrations/decorator.rb +4 -1
- 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 +28 -3
- 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 -2
- data/lib/rr/wildcard_matchers.rb +10 -10
- data/lib/rr/without_autohook.rb +7 -14
- data/rr.gemspec +14 -5
- 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 +57 -0
- data/spec/fixtures/rubygems_patch_for_187.rb +598 -0
- data/spec/global_helper.rb +38 -0
- data/spec/spec.opts +3 -0
- data/spec/spec_suite_configuration.rb +126 -0
- data/spec/spec_suite_runner.rb +47 -0
- data/spec/suites.yml +10 -0
- data/spec/suites/rspec_2/functional/any_instance_of_spec.rb +147 -0
- data/spec/suites/rspec_2/functional/dont_allow_spec.rb +17 -0
- 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 +17 -0
- 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 +102 -0
- 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 +71 -0
- data/spec/suites/rspec_2/functional/stub_strong_spec.rb +15 -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/spec_helper.rb +3 -0
- data/spec/suites/rspec_2/support/matchers/wildcard_matcher_matchers.rb +32 -0
- 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/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/core_ext/array_spec.rb +39 -0
- data/spec/suites/rspec_2/unit/core_ext/enumerable_spec.rb +53 -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/deprecations_spec.rb +27 -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/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/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 +92 -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 +533 -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 +70 -0
- data/spec/suites/rspec_2/unit/rr_spec.rb +28 -0
- data/spec/suites/rspec_2/unit/space_spec.rb +598 -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/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 +70 -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 +348 -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 +240 -19
- data/VERSION +0 -1
- data/lib/rr/adapters.rb +0 -44
- 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 -15
- 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
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
permutations =
|
4
|
+
%w(mock proxy instance_of).permutation.map { |parts| parts.join('.') }
|
5
|
+
|
6
|
+
permutations.each do |permutation|
|
7
|
+
describe permutation, is_mock: true, is_proxy: true, is_instance_of: true do
|
8
|
+
include_context 'mock + instance_of'
|
9
|
+
include ProxyDefinitionCreatorHelpers
|
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,14 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
permutations =
|
4
|
+
%w(mock proxy).permutation.map { |parts| parts.join('.') }
|
5
|
+
|
6
|
+
permutations.each do |permutation|
|
7
|
+
describe permutation, is_mock: true, is_proxy: true do
|
8
|
+
include_context 'mock + proxy'
|
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,17 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe 'mock', is_mock: true do
|
4
|
+
include MockDefinitionCreatorHelpers
|
5
|
+
|
6
|
+
context 'against instance methods', method_type: :instance do
|
7
|
+
include_context 'tests for a double definition creator method that supports mocking'
|
8
|
+
end
|
9
|
+
|
10
|
+
context 'against class methods', method_type: :class do
|
11
|
+
include_context 'tests for a double definition creator method that supports mocking'
|
12
|
+
end
|
13
|
+
|
14
|
+
def double_definition_creator_for(object, &block)
|
15
|
+
mock(object, &block)
|
16
|
+
end
|
17
|
+
end
|
@@ -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
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
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
|
7
|
+
|
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
|
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
|
53
|
+
|
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
|
60
|
+
|
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
|
67
|
+
|
68
|
+
it "excludes #respond_to? from the list of recorded methods" do
|
69
|
+
subject = Object.new
|
70
|
+
spy(subject)
|
71
|
+
subject.inspect
|
72
|
+
subject.should_not have_received.inspect
|
73
|
+
end
|
74
|
+
|
75
|
+
it "excludes #respond_to? from the list of recorded methods" do
|
76
|
+
subject = Object.new
|
77
|
+
spy(subject)
|
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
|
88
|
+
|
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)
|
101
|
+
end
|
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
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe 'stub' do
|
4
|
+
include StubDefinitionCreatorHelpers
|
5
|
+
|
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'
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'that do not exist', methods_exist: false do
|
12
|
+
include_context 'tests for a double definition creator method that supports stubbing'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
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'
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'that do not exist', methods_exist: false do
|
22
|
+
include_context 'tests for a double definition creator method that supports stubbing'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def double_definition_creator_for(object, &block)
|
27
|
+
stub(object, &block)
|
28
|
+
end
|
29
|
+
|
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
|
34
|
+
end
|
35
|
+
|
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'
|
40
|
+
end
|
41
|
+
|
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)
|
45
|
+
|
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'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
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'
|
58
|
+
end
|
59
|
+
|
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)
|
63
|
+
|
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'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
permutations =
|
4
|
+
%w(stub strong).permutation.map { |parts| parts.join('.') } +
|
5
|
+
%w(strong)
|
6
|
+
|
7
|
+
permutations.each do |permutation|
|
8
|
+
describe permutation, is_strong: true do
|
9
|
+
include_context 'stub + 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,128 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
describe 'wildcard matchers' do
|
5
|
+
subject { Object.new }
|
6
|
+
|
7
|
+
describe '#anything' do
|
8
|
+
it "works outside a container" do
|
9
|
+
mock(subject).foo(anything)
|
10
|
+
subject.foo(:whatever)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "works within a container too" do
|
14
|
+
mock(subject).foo([anything])
|
15
|
+
subject.foo([:whatever])
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#boolean' do
|
20
|
+
it "works outside a container" do
|
21
|
+
mock(subject).foo(boolean)
|
22
|
+
subject.foo(false)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "works within a container too" do
|
26
|
+
mock(subject).foo([boolean])
|
27
|
+
subject.foo([false])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#duck_type' do
|
32
|
+
it "works outside a container" do
|
33
|
+
mock(subject).foo(duck_type(:bar))
|
34
|
+
subject.foo(OpenStruct.new(:bar => 3))
|
35
|
+
end
|
36
|
+
|
37
|
+
it "works within a container too" do
|
38
|
+
mock(subject).foo([duck_type(:bar)])
|
39
|
+
subject.foo([OpenStruct.new(:bar => 3)])
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#hash_including' do
|
44
|
+
it "works outside a container" do
|
45
|
+
mock(subject).foo(hash_including(:c => 'd'))
|
46
|
+
subject.foo(:a => 'b', :c => 'd')
|
47
|
+
end
|
48
|
+
|
49
|
+
it "works within a container too" do
|
50
|
+
mock(subject).foo([hash_including(:c => 'd')])
|
51
|
+
subject.foo([{:a => 'b', :c => 'd'}])
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#is_a' do
|
56
|
+
context 'when outside a container' do
|
57
|
+
it "matches a simple value" do
|
58
|
+
mock(subject).foo(is_a(Symbol))
|
59
|
+
subject.foo(:symbol)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "matches a container value" do
|
63
|
+
mock(subject).foo(is_a(Array))
|
64
|
+
subject.foo(['x', 'y'])
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'within a container' do
|
69
|
+
it "matches a simple value" do
|
70
|
+
mock(subject).foo([is_a(Symbol)])
|
71
|
+
subject.foo([:symbol])
|
72
|
+
end
|
73
|
+
|
74
|
+
it "matches a container" do
|
75
|
+
mock(subject).foo([is_a(Hash)])
|
76
|
+
subject.foo([{:x => 'y'}])
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe '#numeric' do
|
82
|
+
it "works outside a container" do
|
83
|
+
mock(subject).foo(numeric)
|
84
|
+
subject.foo(3)
|
85
|
+
end
|
86
|
+
|
87
|
+
it "works within a container too" do
|
88
|
+
mock(subject).foo([numeric])
|
89
|
+
subject.foo([3])
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe 'range' do
|
94
|
+
it "works outside a container" do
|
95
|
+
mock(subject).foo(1..5)
|
96
|
+
subject.foo(3)
|
97
|
+
end
|
98
|
+
|
99
|
+
it "works within a container too" do
|
100
|
+
mock(subject).foo([1..5])
|
101
|
+
subject.foo([3])
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe 'regexp' do
|
106
|
+
it "works outside a container" do
|
107
|
+
mock(subject).foo(/foo/)
|
108
|
+
subject.foo('foobar')
|
109
|
+
end
|
110
|
+
|
111
|
+
it "works within a container too" do
|
112
|
+
mock(subject).foo([/foo/])
|
113
|
+
subject.foo(['foobar'])
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe '#satisfy' do
|
118
|
+
it "works outside a container" do
|
119
|
+
mock(subject).foo(satisfy {|x| x == 'x' })
|
120
|
+
subject.foo('x')
|
121
|
+
end
|
122
|
+
|
123
|
+
it "works within a container too" do
|
124
|
+
mock(subject).foo([satisfy {|x| x == 'x' }])
|
125
|
+
subject.foo(['x'])
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|