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,30 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module Expectations
|
5
|
+
describe ArgumentEqualityExpectation do
|
6
|
+
context "with a boolean matcher" do
|
7
|
+
attr_reader :expectation
|
8
|
+
|
9
|
+
before do
|
10
|
+
@expectation = ArgumentEqualityExpectation.new([boolean], {})
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#wildcard_match?" do
|
14
|
+
context "when passed a Boolean" do
|
15
|
+
it "returns true" do
|
16
|
+
expect(expectation).to be_wildcard_match([true], {})
|
17
|
+
expect(expectation).to be_wildcard_match([false], {})
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "when not passed a Boolean" do
|
22
|
+
it "returns false" do
|
23
|
+
expectation.should_not be_wildcard_match([:not_a_boolean], {})
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/spec/suites/rspec_2/unit/expectations/hash_including_argument_equality_expectation_spec.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module Expectations
|
5
|
+
describe ArgumentEqualityExpectation, "with HashIncluding argument" do
|
6
|
+
attr_reader :expectation, :expected_hash
|
7
|
+
|
8
|
+
before do
|
9
|
+
@expected_hash = {:texas => "Austin", :maine => "Augusta"}
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#exact_match?" do
|
13
|
+
before do
|
14
|
+
@expectation = ArgumentEqualityExpectation.new([hash_including(expected_hash)], {})
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns true when passed in a HashIncluding matcher with the same hash" do
|
18
|
+
expect(expectation).to be_exact_match([RR::WildcardMatchers::HashIncluding.new(expected_hash)],
|
19
|
+
{})
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns false when passed in a HashIncluding matcher with a different argument list" do
|
23
|
+
expectation.should_not be_exact_match([RR::WildcardMatchers::HashIncluding.new(:foo => 1)],
|
24
|
+
{})
|
25
|
+
end
|
26
|
+
|
27
|
+
it "returns false otherwise" do
|
28
|
+
expectation.should_not be_exact_match(["hello"], {})
|
29
|
+
expectation.should_not be_exact_match([:hello], {})
|
30
|
+
expectation.should_not be_exact_match([1], {})
|
31
|
+
expectation.should_not be_exact_match([nil], {})
|
32
|
+
expectation.should_not be_exact_match([true], {})
|
33
|
+
expectation.should_not be_exact_match([], {})
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "#wildcard_match?" do
|
38
|
+
before do
|
39
|
+
@expectation = ArgumentEqualityExpectation.new([hash_including(expected_hash)],
|
40
|
+
{})
|
41
|
+
end
|
42
|
+
|
43
|
+
it "returns true when hash contains same key/values as the expectation" do
|
44
|
+
expect(expectation).to be_wildcard_match([expected_hash], {})
|
45
|
+
end
|
46
|
+
|
47
|
+
it "returns true when hash contains at least expectation's key/values" do
|
48
|
+
expect(expectation).to be_wildcard_match([expected_hash.merge(:oregon => "Salem")],
|
49
|
+
{})
|
50
|
+
end
|
51
|
+
|
52
|
+
it "returns true when passed the same hash, even after the original is modified" do
|
53
|
+
original_expected_hash = expected_hash.clone
|
54
|
+
expected_hash[:texas] = nil
|
55
|
+
expect(expectation).to be_wildcard_match([original_expected_hash], {})
|
56
|
+
end
|
57
|
+
|
58
|
+
it "returns true even if one of the expectation's values is nil" do
|
59
|
+
expectation = ArgumentEqualityExpectation.new([hash_including(:foo => nil)],
|
60
|
+
{})
|
61
|
+
expect(expectation).to be_wildcard_match([{:foo => nil}],
|
62
|
+
{})
|
63
|
+
end
|
64
|
+
|
65
|
+
it "returns false when hash matches only some required key/values" do
|
66
|
+
expectation.should_not be_wildcard_match([{:texas => "Austin"}],
|
67
|
+
{})
|
68
|
+
end
|
69
|
+
|
70
|
+
it "returns false when hash matches all the keys but not all the values" do
|
71
|
+
expectation.should_not be_wildcard_match([{:texas => "Austin", :maine => "Portland"}],
|
72
|
+
{})
|
73
|
+
end
|
74
|
+
|
75
|
+
it "returns false when passed a hash that matches all values but not all keys" do
|
76
|
+
expectation.should_not be_wildcard_match([{:texas => "Austin", :georgia => "Augusta"}],
|
77
|
+
{})
|
78
|
+
end
|
79
|
+
|
80
|
+
it "returns true when an exact match" do
|
81
|
+
expect(expectation).to be_wildcard_match([hash_including(expected_hash)],
|
82
|
+
{})
|
83
|
+
end
|
84
|
+
|
85
|
+
it "returns false when not passed correct number of arguments" do
|
86
|
+
expectation.should_not be_wildcard_match([], {})
|
87
|
+
expectation.should_not be_wildcard_match([:a, :b], {})
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper")
|
2
|
+
|
3
|
+
=begin
|
4
|
+
module RR
|
5
|
+
module Expectations
|
6
|
+
describe ArgumentEqualityExpectation, "with Satisfy argument" do
|
7
|
+
attr_reader :expectation, :expectation_proc, :expected_value, :satisfy_matcher
|
8
|
+
|
9
|
+
before do
|
10
|
+
@expected_value = :foo
|
11
|
+
@expectation_proc = lambda {|argument| puts 'called'; argument == expected_value}
|
12
|
+
@satisfy_matcher = satisfy(&expectation_proc)
|
13
|
+
@expectation = ArgumentEqualityExpectation.new(satisfy_matcher)
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#exact_match?" do
|
17
|
+
before do
|
18
|
+
end
|
19
|
+
|
20
|
+
it "returns true when passed a Satisfy matcher with the same proc" do
|
21
|
+
expect(expectation).to be_exact_match(RR::WildcardMatchers::Satisfy.new(expectation_proc))
|
22
|
+
end
|
23
|
+
|
24
|
+
it "returns false when passed a Satisfy matcher with another proc" do
|
25
|
+
expectation.should_not be_exact_match(RR::WildcardMatchers::Satisfy.new(lambda {}))
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns false otherwise" do
|
29
|
+
expectation.should_not be_exact_match("hello")
|
30
|
+
expectation.should_not be_exact_match(:hello)
|
31
|
+
expectation.should_not be_exact_match(1)
|
32
|
+
expectation.should_not be_exact_match(nil)
|
33
|
+
expectation.should_not be_exact_match(true)
|
34
|
+
expectation.should_not be_exact_match()
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#wildcard_match?" do
|
39
|
+
it "returns true when the proc returns a truthy value" do
|
40
|
+
expect((!!expectation_proc.call(expected_value))).to be_true
|
41
|
+
expect(expectation).to be_wildcard_match(expected_value)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "returns false when the proc returns a falsey value" do
|
45
|
+
expect((!!expectation_proc.call(:bar))).to be_false
|
46
|
+
expectation.should_not be_wildcard_match(:bar)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "returns true when an exact match" do
|
50
|
+
expect(expectation).to be_wildcard_match(satisfy_matcher)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "returns false when not passed correct number of arguments" do
|
54
|
+
expectation.should_not be_wildcard_match()
|
55
|
+
expectation.should_not be_wildcard_match(:a, :b)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
=end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../../spec_helper")
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module Expectations
|
5
|
+
describe TimesCalledExpectation do
|
6
|
+
context "when using an AnyTimesMatcher" do
|
7
|
+
include_examples "RR::Expectations::TimesCalledExpectation"
|
8
|
+
|
9
|
+
describe "#verify!" do
|
10
|
+
it "always passes" do
|
11
|
+
stub(subject).foobar.any_number_of_times
|
12
|
+
RR.verify
|
13
|
+
|
14
|
+
stub(subject).foobar.any_number_of_times
|
15
|
+
10.times {subject.foobar}
|
16
|
+
RR.verify
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../../spec_helper")
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module Expectations
|
5
|
+
describe TimesCalledExpectation do
|
6
|
+
context "when using an AtLeastMatcher" do
|
7
|
+
include_examples "RR::Expectations::TimesCalledExpectation"
|
8
|
+
|
9
|
+
before do
|
10
|
+
mock(subject).foobar.at_least(3)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#verify!" do
|
14
|
+
it "passes when times called > times" do
|
15
|
+
4.times {subject.foobar}
|
16
|
+
RR.verify
|
17
|
+
end
|
18
|
+
|
19
|
+
it "passes when times called == times" do
|
20
|
+
3.times {subject.foobar}
|
21
|
+
RR.verify
|
22
|
+
end
|
23
|
+
|
24
|
+
it "raises error when times called < times" do
|
25
|
+
subject.foobar
|
26
|
+
expect {
|
27
|
+
RR.verify
|
28
|
+
}.to raise_error(
|
29
|
+
RR::Errors::TimesCalledError,
|
30
|
+
"foobar()\nCalled 1 time.\nExpected at least 3 times."
|
31
|
+
)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../../spec_helper")
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module Expectations
|
5
|
+
describe TimesCalledExpectation do
|
6
|
+
context "when using an AtMostMatcher" do
|
7
|
+
include_examples "RR::Expectations::TimesCalledExpectation"
|
8
|
+
|
9
|
+
before do
|
10
|
+
stub(subject).foobar.at_most(3)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#verify!" do
|
14
|
+
it "passes when times called == times" do
|
15
|
+
3.times {subject.foobar}
|
16
|
+
RR.verify
|
17
|
+
end
|
18
|
+
|
19
|
+
it "passes when times called < times" do
|
20
|
+
2.times {subject.foobar}
|
21
|
+
RR.verify
|
22
|
+
end
|
23
|
+
|
24
|
+
it "raises error when times called > times" do
|
25
|
+
expect {
|
26
|
+
4.times {subject.foobar}
|
27
|
+
}.to raise_error(
|
28
|
+
RR::Errors::TimesCalledError,
|
29
|
+
"foobar()\nCalled 4 times.\nExpected at most 3 times."
|
30
|
+
)
|
31
|
+
|
32
|
+
expect {
|
33
|
+
RR.verify
|
34
|
+
}.to raise_error(
|
35
|
+
RR::Errors::TimesCalledError,
|
36
|
+
"foobar()\nCalled 4 times.\nExpected at most 3 times."
|
37
|
+
)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../../spec_helper")
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module Expectations
|
5
|
+
describe TimesCalledExpectation do
|
6
|
+
context "when using an IntegerMatcher" do
|
7
|
+
include_examples "RR::Expectations::TimesCalledExpectation"
|
8
|
+
|
9
|
+
before do
|
10
|
+
stub(subject).foobar.times(2)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "verify" do
|
14
|
+
it "passes after attempt! called 2 times" do
|
15
|
+
subject.foobar
|
16
|
+
subject.foobar
|
17
|
+
RR.verify
|
18
|
+
end
|
19
|
+
|
20
|
+
it "fails after attempt! called 1 time" do
|
21
|
+
subject.foobar
|
22
|
+
expect { RR.verify }.to raise_error(
|
23
|
+
RR::Errors::TimesCalledError,
|
24
|
+
"foobar()\nCalled 1 time.\nExpected 2 times."
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "can't be called when attempt! is called 3 times" do
|
29
|
+
subject.foobar
|
30
|
+
subject.foobar
|
31
|
+
expect {
|
32
|
+
subject.foobar
|
33
|
+
}.to raise_error(RR::Errors::TimesCalledError, "foobar()\nCalled 3 times.\nExpected 2 times.")
|
34
|
+
expect {
|
35
|
+
RR.verify
|
36
|
+
}.to raise_error(RR::Errors::TimesCalledError, "foobar()\nCalled 3 times.\nExpected 2 times.")
|
37
|
+
end
|
38
|
+
|
39
|
+
it "has a backtrace to where the TimesCalledExpectation was instantiated on failure" do
|
40
|
+
error = nil
|
41
|
+
begin
|
42
|
+
RR.verify
|
43
|
+
rescue RR::Errors::TimesCalledError => e
|
44
|
+
error = e
|
45
|
+
end
|
46
|
+
expect(e.backtrace.join("\n")).to include(__FILE__)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "has an error message that includes the number of times called and expected number of times" do
|
50
|
+
expect {
|
51
|
+
RR.verify
|
52
|
+
}.to raise_error(RR::Errors::TimesCalledError, "foobar()\nCalled 0 times.\nExpected 2 times.")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../../spec_helper")
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module Expectations
|
5
|
+
describe TimesCalledExpectation do
|
6
|
+
context "when using a ProcMatcher" do
|
7
|
+
include_examples "RR::Expectations::TimesCalledExpectation"
|
8
|
+
|
9
|
+
before do
|
10
|
+
stub(subject).foobar.times(lambda {|value| value == 2})
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#verify" do
|
14
|
+
it "passes after attempt! called 2 times" do
|
15
|
+
subject.foobar
|
16
|
+
subject.foobar
|
17
|
+
RR.verify
|
18
|
+
end
|
19
|
+
|
20
|
+
it "fails after attempt! called 1 time" do
|
21
|
+
subject.foobar
|
22
|
+
expect { RR.verify }.to raise_error(RR::Errors::TimesCalledError)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "fails after attempt! called 3 times" do
|
26
|
+
subject.foobar
|
27
|
+
subject.foobar
|
28
|
+
subject.foobar
|
29
|
+
expect { RR.verify }.to raise_error(RR::Errors::TimesCalledError)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../../../spec_helper")
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module Expectations
|
5
|
+
describe TimesCalledExpectation do
|
6
|
+
context "when using a RangeMatcher" do
|
7
|
+
include_examples "RR::Expectations::TimesCalledExpectation"
|
8
|
+
|
9
|
+
before do
|
10
|
+
stub(subject).foobar.times(1..2)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#verify" do
|
14
|
+
it "passes after attempt! called 1 time" do
|
15
|
+
subject.foobar
|
16
|
+
RR.verify
|
17
|
+
end
|
18
|
+
|
19
|
+
it "passes after attempt! called 2 times" do
|
20
|
+
subject.foobar
|
21
|
+
subject.foobar
|
22
|
+
RR.verify
|
23
|
+
end
|
24
|
+
|
25
|
+
it "can't be called when attempt! is called 3 times" do
|
26
|
+
subject.foobar
|
27
|
+
subject.foobar
|
28
|
+
expect {
|
29
|
+
subject.foobar
|
30
|
+
}.to raise_error(RR::Errors::TimesCalledError, "foobar()\nCalled 3 times.\nExpected 1..2 times.")
|
31
|
+
expect {
|
32
|
+
RR.verify
|
33
|
+
}.to raise_error(RR::Errors::TimesCalledError, "foobar()\nCalled 3 times.\nExpected 1..2 times.")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
|
2
|
+
|
3
|
+
module RR
|
4
|
+
describe HashWithObjectIdKey do
|
5
|
+
describe "#[] and #[]=" do
|
6
|
+
it "stores object via object id" do
|
7
|
+
hash = HashWithObjectIdKey.new
|
8
|
+
array_1 = []
|
9
|
+
hash[array_1] = 1
|
10
|
+
array_2 = []
|
11
|
+
hash[array_2] = 2
|
12
|
+
|
13
|
+
expect(hash[array_1]).to_not eq hash[array_2]
|
14
|
+
end
|
15
|
+
|
16
|
+
it "stores the passed in object" do
|
17
|
+
hash = HashWithObjectIdKey.new
|
18
|
+
obj = Object.new
|
19
|
+
hash[obj] = 1
|
20
|
+
expect(hash.instance_eval {@keys}).to eq({obj.__id__ => obj})
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#each" do
|
25
|
+
it "iterates through the items in the hash" do
|
26
|
+
hash = HashWithObjectIdKey.new
|
27
|
+
hash['one'] = 1
|
28
|
+
hash['two'] = 2
|
29
|
+
|
30
|
+
keys = []
|
31
|
+
values = []
|
32
|
+
hash.each do |key, value|
|
33
|
+
keys << key
|
34
|
+
values << value
|
35
|
+
end
|
36
|
+
|
37
|
+
expect(keys.sort).to eq ['one', 'two']
|
38
|
+
expect(values.sort).to eq [1, 2]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#delete" do
|
43
|
+
before do
|
44
|
+
@hash = HashWithObjectIdKey.new
|
45
|
+
@key = Object.new
|
46
|
+
@hash[@key] = 1
|
47
|
+
end
|
48
|
+
|
49
|
+
it "removes the object from the hash" do
|
50
|
+
@hash.delete(@key)
|
51
|
+
expect(@hash[@key]).to be_nil
|
52
|
+
end
|
53
|
+
|
54
|
+
it "removes the object from the keys hash" do
|
55
|
+
@hash.delete(@key)
|
56
|
+
expect(@hash.instance_eval { @keys }).to eq({})
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "#keys" do
|
61
|
+
before do
|
62
|
+
@hash = HashWithObjectIdKey.new
|
63
|
+
@key = Object.new
|
64
|
+
@hash[@key] = 1
|
65
|
+
end
|
66
|
+
|
67
|
+
it "returns an array of the keys" do
|
68
|
+
expect(@hash.keys).to eq [@key]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "#include?" do
|
73
|
+
before do
|
74
|
+
@hash = HashWithObjectIdKey.new
|
75
|
+
@key = Object.new
|
76
|
+
@hash[@key] = 1
|
77
|
+
end
|
78
|
+
|
79
|
+
it "returns true when the key is in the Hash" do
|
80
|
+
expect(@hash.include?(@key)).to be_true
|
81
|
+
end
|
82
|
+
|
83
|
+
it "returns false when the key is not in the Hash" do
|
84
|
+
expect(@hash.include?(Object.new)).to be_false
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|