rr 0.3.11 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +8 -3
- data/README +130 -39
- data/Rakefile +6 -5
- data/lib/rr.rb +8 -8
- data/lib/rr/adapters/rr_methods.rb +228 -0
- data/lib/rr/adapters/rspec.rb +1 -1
- data/lib/rr/adapters/test_unit.rb +1 -1
- data/lib/rr/double.rb +294 -89
- data/lib/rr/{scenario_creator.rb → double_creator.rb} +65 -66
- data/lib/rr/{scenario_definition.rb → double_definition.rb} +36 -36
- data/lib/rr/{scenario_definition_builder.rb → double_definition_builder.rb} +3 -3
- data/lib/rr/double_insertion.rb +132 -0
- data/lib/rr/{scenario_matches.rb → double_matches.rb} +2 -2
- data/lib/rr/{scenario_method_proxy.rb → double_method_proxy.rb} +2 -2
- data/lib/rr/errors/argument_equality_error.rb +3 -3
- data/lib/rr/errors/rr_error.rb +13 -13
- data/lib/rr/errors/scenario_definition_error.rb +3 -3
- data/lib/rr/errors/scenario_not_found_error.rb +3 -3
- data/lib/rr/errors/scenario_order_error.rb +3 -3
- data/lib/rr/errors/times_called_error.rb +3 -3
- data/lib/rr/expectations/any_argument_expectation.rb +1 -1
- data/lib/rr/expectations/argument_equality_expectation.rb +1 -1
- data/lib/rr/expectations/times_called_expectation.rb +1 -1
- data/lib/rr/hash_with_object_id_key.rb +1 -1
- data/lib/rr/space.rb +40 -40
- data/lib/rr/times_called_matchers/any_times_matcher.rb +13 -13
- data/lib/rr/times_called_matchers/at_least_matcher.rb +11 -11
- data/lib/rr/times_called_matchers/at_most_matcher.rb +16 -16
- data/lib/rr/times_called_matchers/integer_matcher.rb +13 -13
- data/lib/rr/times_called_matchers/non_terminal.rb +21 -21
- data/lib/rr/times_called_matchers/proc_matcher.rb +7 -7
- data/lib/rr/times_called_matchers/range_matcher.rb +14 -14
- data/lib/rr/times_called_matchers/terminal.rb +16 -16
- data/lib/rr/times_called_matchers/times_called_matcher.rb +32 -32
- data/spec/core_spec_suite.rb +18 -0
- data/{examples → spec}/environment_fixture_setup.rb +0 -1
- data/{examples/high_level_example.rb → spec/high_level_spec.rb} +11 -11
- data/spec/rr/adapters/rr_methods_argument_matcher_spec.rb +67 -0
- data/spec/rr/adapters/rr_methods_creator_spec.rb +365 -0
- data/spec/rr/adapters/rr_methods_space_spec.rb +134 -0
- data/spec/rr/adapters/rr_methods_spec_helper.rb +11 -0
- data/{examples/rr/extensions/instance_methods_times_matcher_example.rb → spec/rr/adapters/rr_methods_times_matcher_spec.rb} +4 -4
- data/spec/rr/double/double_insertion_bind_spec.rb +78 -0
- data/spec/rr/double/double_insertion_dispatching_spec.rb +221 -0
- data/spec/rr/double/double_insertion_has_original_method_spec.rb +56 -0
- data/spec/rr/double/double_insertion_register_scenario_spec.rb +24 -0
- data/spec/rr/double/double_insertion_reset_spec.rb +89 -0
- data/spec/rr/double/double_insertion_spec.rb +66 -0
- data/spec/rr/double/double_insertion_verify_spec.rb +23 -0
- data/spec/rr/double_creator_spec.rb +454 -0
- data/{examples/rr/scenario_definition_example.rb → spec/rr/double_definition_spec.rb} +143 -143
- data/spec/rr/double_method_proxy_spec.rb +71 -0
- data/spec/rr/double_spec.rb +654 -0
- data/spec/rr/errors/rr_error_spec.rb +65 -0
- data/spec/rr/expectations/any_argument_expectation_spec.rb +47 -0
- data/spec/rr/expectations/anything_argument_equality_expectation_spec.rb +38 -0
- data/spec/rr/expectations/argument_equality_expectation_spec.rb +58 -0
- data/spec/rr/expectations/boolean_argument_equality_expectation_spec.rb +53 -0
- data/spec/rr/expectations/duck_type_argument_equality_expectation_spec.rb +71 -0
- data/spec/rr/expectations/is_a_argument_equality_expectation_spec.rb +51 -0
- data/spec/rr/expectations/numeric_argument_equality_expectation_spec.rb +47 -0
- data/spec/rr/expectations/range_argument_equality_expectation_spec.rb +59 -0
- data/spec/rr/expectations/regexp_argument_equality_expectation_spec.rb +72 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_any_times_spec.rb +43 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +67 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb +71 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +21 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb +103 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +79 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +81 -0
- data/spec/rr/expectations/times_called_expectation/times_called_expectation_spec.rb +40 -0
- data/spec/rr/rspec/rspec_adapter_spec.rb +65 -0
- data/spec/rr/rspec/rspec_backtrace_tweaking_spec.rb +52 -0
- data/spec/rr/rspec/rspec_usage_spec.rb +67 -0
- data/spec/rr/space/hash_with_object_id_key_spec.rb +88 -0
- data/spec/rr/space/space_create_spec.rb +278 -0
- data/spec/rr/space/space_helper.rb +7 -0
- data/spec/rr/space/space_register_spec.rb +32 -0
- data/spec/rr/space/space_reset_spec.rb +131 -0
- data/spec/rr/space/space_spec.rb +32 -0
- data/spec/rr/space/space_verify_spec.rb +181 -0
- data/{examples → spec}/rr/test_unit/test_helper.rb +1 -1
- data/{examples → spec}/rr/test_unit/test_unit_backtrace_test.rb +0 -0
- data/{examples → spec}/rr/test_unit/test_unit_integration_test.rb +4 -4
- data/spec/rr/times_called_matchers/any_times_matcher_spec.rb +47 -0
- data/spec/rr/times_called_matchers/at_least_matcher_spec.rb +55 -0
- data/spec/rr/times_called_matchers/at_most_matcher_spec.rb +70 -0
- data/spec/rr/times_called_matchers/integer_matcher_spec.rb +70 -0
- data/spec/rr/times_called_matchers/proc_matcher_spec.rb +55 -0
- data/spec/rr/times_called_matchers/range_matcher_spec.rb +76 -0
- data/spec/rr/times_called_matchers/times_called_matcher_spec.rb +118 -0
- data/spec/rspec_spec_suite.rb +16 -0
- data/spec/spec_helper.rb +9 -0
- data/{examples/example_suite.rb → spec/spec_suite.rb} +3 -3
- data/{examples/test_unit_example_suite.rb → spec/test_unit_spec_suite.rb} +0 -0
- metadata +93 -93
- data/examples/core_example_suite.rb +0 -31
- data/examples/example_helper.rb +0 -9
- data/examples/rr/double/double_bind_example.rb +0 -70
- data/examples/rr/double/double_dispatching_example.rb +0 -236
- data/examples/rr/double/double_example.rb +0 -66
- data/examples/rr/double/double_has_original_method_example.rb +0 -56
- data/examples/rr/double/double_register_scenario_example.rb +0 -24
- data/examples/rr/double/double_reset_example.rb +0 -89
- data/examples/rr/double/double_verify_example.rb +0 -23
- data/examples/rr/errors/rr_error_example.rb +0 -65
- data/examples/rr/expectations/any_argument_expectation_example.rb +0 -52
- data/examples/rr/expectations/anything_argument_equality_expectation_example.rb +0 -38
- data/examples/rr/expectations/argument_equality_expectation_example.rb +0 -62
- data/examples/rr/expectations/boolean_argument_equality_expectation_example.rb +0 -48
- data/examples/rr/expectations/duck_type_argument_equality_expectation_example.rb +0 -67
- data/examples/rr/expectations/is_a_argument_equality_expectation_example.rb +0 -50
- data/examples/rr/expectations/numeric_argument_equality_expectation_example.rb +0 -46
- data/examples/rr/expectations/range_argument_equality_expectation_example.rb +0 -59
- data/examples/rr/expectations/regexp_argument_equality_expectation_example.rb +0 -67
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_any_times_example.rb +0 -50
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_at_least_example.rb +0 -73
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_at_most_example.rb +0 -77
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_example.rb +0 -42
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +0 -20
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_integer_example.rb +0 -111
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_proc_example.rb +0 -88
- data/examples/rr/expectations/times_called_expectation/times_called_expectation_range_example.rb +0 -90
- data/examples/rr/extensions/instance_methods_argument_matcher_example.rb +0 -65
- data/examples/rr/extensions/instance_methods_creator_example.rb +0 -363
- data/examples/rr/extensions/instance_methods_example_helper.rb +0 -11
- data/examples/rr/extensions/instance_methods_space_example.rb +0 -122
- data/examples/rr/rspec/rspec_adapter_example.rb +0 -63
- data/examples/rr/rspec/rspec_backtrace_tweaking_example.rb +0 -36
- data/examples/rr/rspec/rspec_usage_example.rb +0 -65
- data/examples/rr/scenario_creator_example.rb +0 -459
- data/examples/rr/scenario_example.rb +0 -701
- data/examples/rr/scenario_method_proxy_example.rb +0 -71
- data/examples/rr/space/hash_with_object_id_key_example.rb +0 -86
- data/examples/rr/space/space_create_example.rb +0 -278
- data/examples/rr/space/space_example.rb +0 -29
- data/examples/rr/space/space_helper.rb +0 -7
- data/examples/rr/space/space_register_example.rb +0 -32
- data/examples/rr/space/space_reset_example.rb +0 -120
- data/examples/rr/space/space_verify_example.rb +0 -169
- data/examples/rr/times_called_matchers/any_times_matcher_example.rb +0 -63
- data/examples/rr/times_called_matchers/at_least_matcher_example.rb +0 -70
- data/examples/rr/times_called_matchers/at_most_matcher_example.rb +0 -85
- data/examples/rr/times_called_matchers/integer_matcher_example.rb +0 -91
- data/examples/rr/times_called_matchers/proc_matcher_example.rb +0 -77
- data/examples/rr/times_called_matchers/range_matcher_example.rb +0 -97
- data/examples/rr/times_called_matchers/times_called_matcher_example.rb +0 -53
- data/examples/rspec_example_suite.rb +0 -25
- data/lib/rr/extensions/instance_methods.rb +0 -228
- data/lib/rr/scenario.rb +0 -337
@@ -0,0 +1,65 @@
|
|
1
|
+
require "spec/spec_helper"
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module Errors
|
5
|
+
describe RRError, "#backtrace" do
|
6
|
+
before do
|
7
|
+
@original_trim_backtrace = RR::Space.trim_backtrace
|
8
|
+
end
|
9
|
+
after do
|
10
|
+
RR::Space.trim_backtrace = @original_trim_backtrace
|
11
|
+
end
|
12
|
+
|
13
|
+
it "does not include the rr library files when trim_backtrace is true" do
|
14
|
+
RR::Space.trim_backtrace = true
|
15
|
+
|
16
|
+
error = nil
|
17
|
+
begin
|
18
|
+
obj = Object.new
|
19
|
+
mock(obj).foobar
|
20
|
+
RR::Space.verify_double(obj, :foobar)
|
21
|
+
rescue RRError=> e
|
22
|
+
error = e
|
23
|
+
end
|
24
|
+
backtrace = error.backtrace.join("\n")
|
25
|
+
|
26
|
+
backtrace.should_not include("lib/rr")
|
27
|
+
end
|
28
|
+
|
29
|
+
it "includes the rr library files when trim_backtrace is false" do
|
30
|
+
RR::Space.trim_backtrace = false
|
31
|
+
|
32
|
+
error = nil
|
33
|
+
begin
|
34
|
+
obj = Object.new
|
35
|
+
mock(obj).foobar
|
36
|
+
RR::Space.verify_double(obj, :foobar)
|
37
|
+
rescue RRError=> e
|
38
|
+
error = e
|
39
|
+
end
|
40
|
+
backtrace = error.backtrace.join("\n")
|
41
|
+
|
42
|
+
backtrace.should include("lib/rr")
|
43
|
+
end
|
44
|
+
|
45
|
+
it "returns custom backtrace when backtrace is set" do
|
46
|
+
error = RRError.new
|
47
|
+
custom_backtrace = caller
|
48
|
+
error.backtrace = custom_backtrace
|
49
|
+
error.backtrace.should == custom_backtrace
|
50
|
+
end
|
51
|
+
|
52
|
+
it "returns normal backtrace when backtrace is not set" do
|
53
|
+
error = nil
|
54
|
+
expected_line = __LINE__ + 2
|
55
|
+
begin
|
56
|
+
raise RRError
|
57
|
+
rescue RRError => e
|
58
|
+
error = e
|
59
|
+
end
|
60
|
+
error.backtrace.first.should include(__FILE__)
|
61
|
+
error.backtrace.first.should include(expected_line.to_s)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require "spec/spec_helper"
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module Expectations
|
5
|
+
describe AnyArgumentExpectation do
|
6
|
+
attr_reader :expectation
|
7
|
+
before do
|
8
|
+
@expectation = AnyArgumentExpectation.new
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#expected_arguments" do
|
12
|
+
it "returns an empty array" do
|
13
|
+
expectation.expected_arguments.should == []
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "==" do
|
18
|
+
it "returns true when comparing with another AnyArgumentExpectation" do
|
19
|
+
expectation.should == AnyArgumentExpectation.new
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns false when comparing with ArgumentEqualityExpectation" do
|
23
|
+
expectation.should_not == ArgumentEqualityExpectation.new(1)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#exact_match?" do
|
28
|
+
it "returns false" do
|
29
|
+
expectation.should_not be_exact_match(1, 2, 3)
|
30
|
+
expectation.should_not be_exact_match(1, 2)
|
31
|
+
expectation.should_not be_exact_match(1)
|
32
|
+
expectation.should_not be_exact_match()
|
33
|
+
expectation.should_not be_exact_match("does not match")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "#wildcard_match?" do
|
38
|
+
it "returns true" do
|
39
|
+
expectation = AnyArgumentExpectation.new
|
40
|
+
expectation.should be_wildcard_match(1, 2, 3)
|
41
|
+
expectation.should be_wildcard_match("whatever")
|
42
|
+
expectation.should be_wildcard_match("whatever", "else")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require "spec/spec_helper"
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module Expectations
|
5
|
+
describe ArgumentEqualityExpectation, "matching anything" do
|
6
|
+
attr_reader :expectation
|
7
|
+
before do
|
8
|
+
@expectation = ArgumentEqualityExpectation.new(anything)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#exact_match? with anything argument" do
|
12
|
+
it "returns true when passed in an Anything module" do
|
13
|
+
expectation.should be_exact_match(WildcardMatchers::Anything.new)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns false otherwise" do
|
17
|
+
expectation.should_not be_exact_match("hello")
|
18
|
+
expectation.should_not be_exact_match(:hello)
|
19
|
+
expectation.should_not be_exact_match(1)
|
20
|
+
expectation.should_not be_exact_match(nil)
|
21
|
+
expectation.should_not be_exact_match()
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#wildcard_match? with is_a String argument" do
|
26
|
+
it "returns true when passed correct number of arguments" do
|
27
|
+
expectation.should be_wildcard_match(Object.new)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "returns false when not passed correct number of arguments" do
|
31
|
+
expectation.should_not be_wildcard_match()
|
32
|
+
expectation.should_not be_wildcard_match(Object.new, Object.new)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require "spec/spec_helper"
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module Expectations
|
5
|
+
describe ArgumentEqualityExpectation do
|
6
|
+
attr_reader :expectation
|
7
|
+
before do
|
8
|
+
@expectation = ArgumentEqualityExpectation.new(1, 2, 3)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#expected_arguments" do
|
12
|
+
it "returns the passed in expected_arguments" do
|
13
|
+
expectation.expected_arguments.should == [1, 2, 3]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "==" do
|
18
|
+
it "returns true when passed in expected_arguments are equal" do
|
19
|
+
expectation.should == ArgumentEqualityExpectation.new(1, 2, 3)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns false when passed in expected_arguments are not equal" do
|
23
|
+
expectation.should_not == ArgumentEqualityExpectation.new(1, 2)
|
24
|
+
expectation.should_not == ArgumentEqualityExpectation.new(1)
|
25
|
+
expectation.should_not == ArgumentEqualityExpectation.new(:something)
|
26
|
+
expectation.should_not == ArgumentEqualityExpectation.new()
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#exact_match?" do
|
31
|
+
it "returns true when all arguments exactly match" do
|
32
|
+
expectation.should be_exact_match(1, 2, 3)
|
33
|
+
expectation.should_not be_exact_match(1, 2)
|
34
|
+
expectation.should_not be_exact_match(1)
|
35
|
+
expectation.should_not be_exact_match()
|
36
|
+
expectation.should_not be_exact_match("does not match")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#wildcard_match?" do
|
41
|
+
it "returns false when not exact match" do
|
42
|
+
expectation = ArgumentEqualityExpectation.new(1)
|
43
|
+
expectation.should_not be_wildcard_match(1, 2, 3)
|
44
|
+
expectation.should_not be_wildcard_match("whatever")
|
45
|
+
expectation.should_not be_wildcard_match("whatever", "else")
|
46
|
+
end
|
47
|
+
|
48
|
+
it "returns true when exact match" do
|
49
|
+
expectation = ArgumentEqualityExpectation.new(1, 2)
|
50
|
+
expectation.should be_wildcard_match(1, 2)
|
51
|
+
expectation.should_not be_wildcard_match(1)
|
52
|
+
expectation.should_not be_wildcard_match("whatever", "else")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require "spec/spec_helper"
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module Expectations
|
5
|
+
describe ArgumentEqualityExpectation, "with boolean match" do
|
6
|
+
attr_reader :expectation
|
7
|
+
|
8
|
+
before do
|
9
|
+
@expectation = ArgumentEqualityExpectation.new(boolean)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#exact_match?" do
|
13
|
+
it "returns true when passed in an IsA module" do
|
14
|
+
expectation.should be_exact_match(WildcardMatchers::Boolean.new)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns false otherwise" do
|
18
|
+
expectation.should_not be_exact_match("hello")
|
19
|
+
expectation.should_not be_exact_match(:hello)
|
20
|
+
expectation.should_not be_exact_match(1)
|
21
|
+
expectation.should_not be_exact_match(nil)
|
22
|
+
expectation.should_not be_exact_match(true)
|
23
|
+
expectation.should_not be_exact_match()
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#wildcard_match?" do
|
28
|
+
before do
|
29
|
+
expectation = ArgumentEqualityExpectation.new(boolean)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "returns true when passed a Boolean" do
|
33
|
+
expectation.should be_wildcard_match(true)
|
34
|
+
expectation.should be_wildcard_match(false)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "returns false when not passed a Boolean" do
|
38
|
+
expectation.should_not be_wildcard_match(:not_a_boolean)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "returns true when an exact match" do
|
42
|
+
expectation.should be_wildcard_match(boolean)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "returns false when not passed correct number of arguments" do
|
46
|
+
expectation.should_not be_wildcard_match()
|
47
|
+
expectation.should_not be_wildcard_match(true, false)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require "spec/spec_helper"
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module Expectations
|
5
|
+
describe ArgumentEqualityExpectation, "with DuckType argument" do
|
6
|
+
attr_reader :expectation
|
7
|
+
|
8
|
+
describe "#exact_match?" do
|
9
|
+
before do
|
10
|
+
@expectation = ArgumentEqualityExpectation.new(duck_type(:to_s))
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns true when passed in an DuckType matcher with the same argument list" do
|
14
|
+
expectation.should be_exact_match(WildcardMatchers::DuckType.new(:to_s))
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns false when passed in an DuckType matcher with a different argument list" do
|
18
|
+
expectation.should_not be_exact_match(WildcardMatchers::DuckType.new(:to_s, :to_i))
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns false otherwise" do
|
22
|
+
expectation.should_not be_exact_match("hello")
|
23
|
+
expectation.should_not be_exact_match(:hello)
|
24
|
+
expectation.should_not be_exact_match(1)
|
25
|
+
expectation.should_not be_exact_match(nil)
|
26
|
+
expectation.should_not be_exact_match(true)
|
27
|
+
expectation.should_not be_exact_match()
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#wildcard_match?" do
|
32
|
+
before do
|
33
|
+
@matching_object = Object.new
|
34
|
+
def @matching_object.quack
|
35
|
+
end
|
36
|
+
def @matching_object.waddle
|
37
|
+
end
|
38
|
+
|
39
|
+
@partial_matching_object = Object.new
|
40
|
+
def @partial_matching_object.quack
|
41
|
+
end
|
42
|
+
|
43
|
+
@not_match_object = Object.new
|
44
|
+
|
45
|
+
@expectation = ArgumentEqualityExpectation.new(duck_type(:quack, :waddle))
|
46
|
+
end
|
47
|
+
|
48
|
+
it "returns true when object matches all required methods" do
|
49
|
+
expectation.should be_wildcard_match(@matching_object)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "returns false when object matches some required methods" do
|
53
|
+
expectation.should_not be_wildcard_match(@partial_matching_object)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "returns false when passed an object that matches no required methods" do
|
57
|
+
expectation.should_not be_wildcard_match(@not_match_object)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "returns true when an exact match" do
|
61
|
+
expectation.should be_wildcard_match(duck_type(:quack, :waddle))
|
62
|
+
end
|
63
|
+
|
64
|
+
it "returns false when not passed correct number of arguments" do
|
65
|
+
expectation.should_not be_wildcard_match()
|
66
|
+
expectation.should_not be_wildcard_match(@matching_object, @matching_object)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require "spec/spec_helper"
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module Expectations
|
5
|
+
describe ArgumentEqualityExpectation, "with is_a string matcher" do
|
6
|
+
attr_reader :expectation
|
7
|
+
|
8
|
+
before do
|
9
|
+
@expectation = ArgumentEqualityExpectation.new(is_a(String))
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#exact_match?" do
|
13
|
+
it "returns true when passed in an IsA module" do
|
14
|
+
expectation.should be_exact_match(WildcardMatchers::IsA.new(String))
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns false when passed in an IsA object with a different module" do
|
18
|
+
expectation.should_not be_exact_match(WildcardMatchers::IsA.new(Integer))
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns false otherwise" do
|
22
|
+
expectation.should_not be_exact_match("hello")
|
23
|
+
expectation.should_not be_exact_match(:hello)
|
24
|
+
expectation.should_not be_exact_match(1)
|
25
|
+
expectation.should_not be_exact_match(nil)
|
26
|
+
expectation.should_not be_exact_match()
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#wildcard_match?" do
|
31
|
+
it "returns true when passed a String" do
|
32
|
+
expectation.should be_wildcard_match("Hello")
|
33
|
+
end
|
34
|
+
|
35
|
+
it "returns false when not passed a String" do
|
36
|
+
expectation.should_not be_wildcard_match(:not_a_string)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "returns true when an exact match" do
|
40
|
+
expectation.should be_wildcard_match(is_a(String))
|
41
|
+
end
|
42
|
+
|
43
|
+
it "returns false when not passed correct number of arguments" do
|
44
|
+
expectation.should_not be_wildcard_match()
|
45
|
+
expectation.should_not be_wildcard_match("one", "two")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require "spec/spec_helper"
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module Expectations
|
5
|
+
describe ArgumentEqualityExpectation, "with numeric argument" do
|
6
|
+
attr_reader :expectation
|
7
|
+
|
8
|
+
before do
|
9
|
+
@expectation = ArgumentEqualityExpectation.new(numeric)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#exact_match?" do
|
13
|
+
it "returns true when passed in an IsA module" do
|
14
|
+
expectation.should be_exact_match(WildcardMatchers::Numeric.new)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns false otherwise" do
|
18
|
+
expectation.should_not be_exact_match("hello")
|
19
|
+
expectation.should_not be_exact_match(:hello)
|
20
|
+
expectation.should_not be_exact_match(1)
|
21
|
+
expectation.should_not be_exact_match(nil)
|
22
|
+
expectation.should_not be_exact_match()
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#wildcard_match?" do
|
27
|
+
it "returns true when passed a Numeric" do
|
28
|
+
expectation.should be_wildcard_match(99)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "returns false when not passed a Numeric" do
|
32
|
+
expectation.should_not be_wildcard_match(:not_a_numeric)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "returns true when an exact match" do
|
36
|
+
expectation.should be_wildcard_match(numeric)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "returns false when not passed correct number of arguments" do
|
40
|
+
expectation.should_not be_wildcard_match()
|
41
|
+
expectation.should_not be_wildcard_match(1, 2)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require "spec/spec_helper"
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module Expectations
|
5
|
+
describe ArgumentEqualityExpectation, "with range argument" do
|
6
|
+
attr_reader :expectation
|
7
|
+
before do
|
8
|
+
@expectation = ArgumentEqualityExpectation.new(2..5)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#exact_match?" do
|
12
|
+
it "returns true when passed in an Range matcher with the same argument list" do
|
13
|
+
expectation.should be_exact_match(2..5)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns false when passed in an Range matcher with a different argument list" do
|
17
|
+
expectation.should_not be_exact_match(3..6)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "returns false otherwise" do
|
21
|
+
expectation.should_not be_exact_match(2)
|
22
|
+
expectation.should_not be_exact_match(:hello)
|
23
|
+
expectation.should_not be_exact_match(3)
|
24
|
+
expectation.should_not be_exact_match(nil)
|
25
|
+
expectation.should_not be_exact_match(true)
|
26
|
+
expectation.should_not be_exact_match()
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#wildcard_match?" do
|
31
|
+
it "returns true when string matches the range" do
|
32
|
+
expectation.should be_wildcard_match(3)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "returns false when string does not match the range" do
|
36
|
+
expectation.should_not be_wildcard_match(7)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "returns true when an exact match" do
|
40
|
+
expectation.should be_wildcard_match(2..5)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "returns false when not an exact match" do
|
44
|
+
expectation.should_not be_wildcard_match(3..9)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "returns false when not a number" do
|
48
|
+
expectation.should_not be_wildcard_match("Not a number")
|
49
|
+
end
|
50
|
+
|
51
|
+
it "returns false when not passed correct number of arguments" do
|
52
|
+
expectation.should_not be_wildcard_match()
|
53
|
+
expectation.should_not be_wildcard_match(2, 3)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|