rr 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. data/CHANGES +1 -0
  2. data/README +45 -0
  3. data/Rakefile +60 -0
  4. data/examples/environment_fixture_setup.rb +7 -0
  5. data/examples/example_helper.rb +8 -0
  6. data/examples/example_suite.rb +45 -0
  7. data/examples/high_level_example.rb +132 -0
  8. data/examples/rr/do_not_allow_creator_example.rb +90 -0
  9. data/examples/rr/double_bind_example.rb +32 -0
  10. data/examples/rr/double_dispatching_example.rb +167 -0
  11. data/examples/rr/double_example.rb +67 -0
  12. data/examples/rr/double_register_scenario_example.rb +25 -0
  13. data/examples/rr/double_reset_example.rb +60 -0
  14. data/examples/rr/double_verify_example.rb +24 -0
  15. data/examples/rr/expectations/any_argument_expectation_example.rb +43 -0
  16. data/examples/rr/expectations/anything_argument_equality_expectation_example.rb +39 -0
  17. data/examples/rr/expectations/argument_equality_expectation_example.rb +53 -0
  18. data/examples/rr/expectations/boolean_argument_equality_expectation_example.rb +49 -0
  19. data/examples/rr/expectations/duck_type_argument_equality_expectation_example.rb +68 -0
  20. data/examples/rr/expectations/is_a_argument_equality_expectation_example.rb +51 -0
  21. data/examples/rr/expectations/numeric_argument_equality_expectation_example.rb +47 -0
  22. data/examples/rr/expectations/range_argument_equality_expectation_example.rb +60 -0
  23. data/examples/rr/expectations/regexp_argument_equality_expectation_example.rb +68 -0
  24. data/examples/rr/expectations/times_called_expectation_example.rb +176 -0
  25. data/examples/rr/extensions/double_methods_example.rb +130 -0
  26. data/examples/rr/mock_creator_example.rb +65 -0
  27. data/examples/rr/probe_creator_example.rb +83 -0
  28. data/examples/rr/rspec/rspec_adapter_example.rb +64 -0
  29. data/examples/rr/rspec/rspec_usage_example.rb +38 -0
  30. data/examples/rr/scenario_example.rb +399 -0
  31. data/examples/rr/space_create_example.rb +185 -0
  32. data/examples/rr/space_example.rb +30 -0
  33. data/examples/rr/space_helper.rb +7 -0
  34. data/examples/rr/space_register_example.rb +33 -0
  35. data/examples/rr/space_reset_example.rb +73 -0
  36. data/examples/rr/space_verify_example.rb +146 -0
  37. data/examples/rr/stub_creator_example.rb +74 -0
  38. data/examples/rr/test_unit/test_helper.rb +9 -0
  39. data/examples/rr/test_unit/test_unit_integration_test.rb +39 -0
  40. data/examples/rspec_example_suite.rb +25 -0
  41. data/examples/test_unit_example_suite.rb +21 -0
  42. data/lib/rr.rb +27 -0
  43. data/lib/rr/adapters/rspec.rb +19 -0
  44. data/lib/rr/adapters/test_unit.rb +27 -0
  45. data/lib/rr/do_not_allow_creator.rb +39 -0
  46. data/lib/rr/double.rb +91 -0
  47. data/lib/rr/expectations/any_argument_expectation.rb +17 -0
  48. data/lib/rr/expectations/argument_equality_expectation.rb +35 -0
  49. data/lib/rr/expectations/times_called_expectation.rb +39 -0
  50. data/lib/rr/expectations/wildcard_matchers/anything.rb +15 -0
  51. data/lib/rr/expectations/wildcard_matchers/boolean.rb +20 -0
  52. data/lib/rr/expectations/wildcard_matchers/duck_type.rb +26 -0
  53. data/lib/rr/expectations/wildcard_matchers/is_a.rb +22 -0
  54. data/lib/rr/expectations/wildcard_matchers/numeric.rb +11 -0
  55. data/lib/rr/expectations/wildcard_matchers/range.rb +7 -0
  56. data/lib/rr/expectations/wildcard_matchers/regexp.rb +7 -0
  57. data/lib/rr/extensions/double_methods.rb +81 -0
  58. data/lib/rr/mock_creator.rb +32 -0
  59. data/lib/rr/probe_creator.rb +31 -0
  60. data/lib/rr/scenario.rb +184 -0
  61. data/lib/rr/scenario_not_found_error.rb +4 -0
  62. data/lib/rr/scenario_order_error.rb +4 -0
  63. data/lib/rr/space.rb +111 -0
  64. data/lib/rr/stub_creator.rb +36 -0
  65. metadata +113 -0
@@ -0,0 +1,67 @@
1
+ dir = File.dirname(__FILE__)
2
+ require "#{dir}/../example_helper"
3
+
4
+ module RR
5
+ describe Double, :shared => true do
6
+ it "sets up object and method_name" do
7
+ @double.object.should === @object
8
+ @double.method_name.should == @method_name.to_sym
9
+ end
10
+ end
11
+
12
+ describe Double, "#initialize where method_name is a symbol" do
13
+ it_should_behave_like "RR::Double"
14
+
15
+ before do
16
+ @space = Space.new
17
+ @object = Object.new
18
+ @method_name = :foobar
19
+ @object.methods.should_not include(@method_name.to_s)
20
+ @double = Double.new(@space, @object, @method_name)
21
+ end
22
+ end
23
+
24
+ describe Double, "#initialize where method_name is a string" do
25
+ it_should_behave_like "RR::Double"
26
+
27
+ before do
28
+ @space = Space.new
29
+ @object = Object.new
30
+ @method_name = 'foobar'
31
+ @object.methods.should_not include(@method_name)
32
+ @double = Double.new(@space, @object, @method_name)
33
+ end
34
+ end
35
+
36
+ describe Double, "#initialize where method does not exist on object" do
37
+ it_should_behave_like "RR::Double"
38
+
39
+ before do
40
+ @space = Space.new
41
+ @object = Object.new
42
+ @method_name = :foobar
43
+ @object.methods.should_not include(@method_name.to_s)
44
+ @double = Double.new(@space, @object, @method_name)
45
+ end
46
+
47
+ it "has a nil original_method" do
48
+ @double.original_method.should be_nil
49
+ end
50
+ end
51
+
52
+ describe Double, "#initialize where method exists on object" do
53
+ it_should_behave_like "RR::Double"
54
+
55
+ before do
56
+ @space = Space.new
57
+ @object = Object.new
58
+ @method_name = :to_s
59
+ @object.methods.should include(@method_name.to_s)
60
+ @double = Double.new(@space, @object, @method_name)
61
+ end
62
+
63
+ it "has a nil original_method" do
64
+ @double.original_method.should == @object.method(@method_name)
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,25 @@
1
+ dir = File.dirname(__FILE__)
2
+ require "#{dir}/../example_helper"
3
+
4
+ module RR
5
+ describe Double, "#register_scenario" do
6
+ before do
7
+ @space = Space.new
8
+ @object = Object.new
9
+ @method_name = :foobar
10
+ @object.methods.should_not include(@method_name.to_s)
11
+ @double = Double.new(@space, @object, @method_name)
12
+ def @double.scenarios
13
+ @scenarios
14
+ end
15
+ end
16
+
17
+ it "adds the scenario to the scenarios list" do
18
+ scenario = Scenario.new(@space)
19
+
20
+ @double.scenarios.should_not include(scenario)
21
+ @double.register_scenario scenario
22
+ @double.scenarios.should include(scenario)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,60 @@
1
+ dir = File.dirname(__FILE__)
2
+ require "#{dir}/../example_helper"
3
+
4
+ module RR
5
+ describe Double, "#reset", :shared => true do
6
+ it "cleans up by removing the __rr__ method" do
7
+ @double.bind
8
+ @object.methods.should include("__rr__foobar__rr__")
9
+
10
+ @double.reset
11
+ @object.methods.should_not include("__rr__foobar__rr__")
12
+ end
13
+ end
14
+
15
+ describe Double, "#reset when method does not exist" do
16
+ it_should_behave_like "RR::Double#reset"
17
+
18
+ before do
19
+ @space = Space.new
20
+ @object = Object.new
21
+ @method_name = :foobar
22
+ @object.methods.should_not include(@method_name.to_s)
23
+ @double = Double.new(@space, @object, @method_name)
24
+ end
25
+
26
+ it "removes the method" do
27
+ @double.bind
28
+ @object.methods.should include(@method_name.to_s)
29
+
30
+ @double.reset
31
+ @object.methods.should_not include(@method_name.to_s)
32
+ proc {@object.foobar}.should raise_error(NoMethodError)
33
+ end
34
+ end
35
+
36
+ describe Double, "#reset when method exists" do
37
+ it_should_behave_like "RR::Double#reset"
38
+
39
+ before do
40
+ @space = Space.new
41
+ @object = Object.new
42
+ @method_name = :foobar
43
+ def @object.foobar
44
+ :original_foobar
45
+ end
46
+ @object.methods.should include(@method_name.to_s)
47
+ @original_method = @object.method(@method_name)
48
+ @double = Double.new(@space, @object, @method_name)
49
+ end
50
+
51
+ it "removes the method" do
52
+ @double.bind
53
+ @object.methods.should include(@method_name.to_s)
54
+
55
+ @double.reset
56
+ @object.methods.should include(@method_name.to_s)
57
+ @object.foobar.should == :original_foobar
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,24 @@
1
+ dir = File.dirname(__FILE__)
2
+ require "#{dir}/../example_helper"
3
+
4
+ module RR
5
+ describe Double, "#verify" do
6
+ before do
7
+ @space = Space.new
8
+ @object = Object.new
9
+ @method_name = :foobar
10
+ @object.methods.should_not include(@method_name.to_s)
11
+ @double = @space.create_double(@object, @method_name)
12
+ end
13
+
14
+ it "verifies each scenario was met" do
15
+ scenario = Scenario.new(@space)
16
+ @double.register_scenario scenario
17
+
18
+ scenario.with(1).once.returns {nil}
19
+ proc {@double.verify}.should raise_error(Expectations::TimesCalledExpectationError)
20
+ @object.foobar(1)
21
+ proc {@double.verify}.should_not raise_error
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,43 @@
1
+ dir = File.dirname(__FILE__)
2
+ require "#{dir}/../../example_helper"
3
+
4
+ module RR
5
+ module Expectations
6
+ describe AnyArgumentExpectation, "==" do
7
+ before do
8
+ @expectation = AnyArgumentExpectation.new
9
+ end
10
+
11
+ it "returns true when comparing with another AnyArgumentExpectation" do
12
+ @expectation.should == AnyArgumentExpectation.new
13
+ end
14
+
15
+ it "returns false when comparing with ArgumentEqualityExpectation" do
16
+ @expectation.should_not == ArgumentEqualityExpectation.new(1)
17
+ end
18
+ end
19
+
20
+ describe AnyArgumentExpectation, "#exact_match?" do
21
+ before do
22
+ @expectation = AnyArgumentExpectation.new
23
+ end
24
+
25
+ it "returns false" do
26
+ @expectation.should_not be_exact_match(1, 2, 3)
27
+ @expectation.should_not be_exact_match(1, 2)
28
+ @expectation.should_not be_exact_match(1)
29
+ @expectation.should_not be_exact_match()
30
+ @expectation.should_not be_exact_match("does not match")
31
+ end
32
+ end
33
+
34
+ describe AnyArgumentExpectation, "#wildcard_match?" do
35
+ it "returns true" do
36
+ @expectation = AnyArgumentExpectation.new
37
+ @expectation.should be_wildcard_match(1, 2, 3)
38
+ @expectation.should be_wildcard_match("whatever")
39
+ @expectation.should be_wildcard_match("whatever", "else")
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,39 @@
1
+ dir = File.dirname(__FILE__)
2
+ require "#{dir}/../../example_helper"
3
+
4
+ module RR
5
+ module Expectations
6
+ describe ArgumentEqualityExpectation, "#exact_match? with anything argument" do
7
+ before do
8
+ @expectation = ArgumentEqualityExpectation.new(anything)
9
+ end
10
+
11
+ it "returns true when passed in an Anything module" do
12
+ @expectation.should be_exact_match(WildcardMatchers::Anything.new)
13
+ end
14
+
15
+ it "returns false otherwise" do
16
+ @expectation.should_not be_exact_match("hello")
17
+ @expectation.should_not be_exact_match(:hello)
18
+ @expectation.should_not be_exact_match(1)
19
+ @expectation.should_not be_exact_match(nil)
20
+ @expectation.should_not be_exact_match()
21
+ end
22
+ end
23
+
24
+ describe ArgumentEqualityExpectation, "#wildcard_match? with is_a String argument" do
25
+ before do
26
+ @expectation = ArgumentEqualityExpectation.new(anything)
27
+ end
28
+
29
+ it "returns true when passed correct number of arguments" do
30
+ @expectation.should be_wildcard_match(Object.new)
31
+ end
32
+
33
+ it "returns false when not passed correct number of arguments" do
34
+ @expectation.should_not be_wildcard_match()
35
+ @expectation.should_not be_wildcard_match(Object.new, Object.new)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,53 @@
1
+ dir = File.dirname(__FILE__)
2
+ require "#{dir}/../../example_helper"
3
+
4
+ module RR
5
+ module Expectations
6
+ describe ArgumentEqualityExpectation, "==" do
7
+ before do
8
+ @expectation = ArgumentEqualityExpectation.new(1, 2, 3)
9
+ end
10
+
11
+ it "returns true when passed in expected_arguments are equal" do
12
+ @expectation.should == ArgumentEqualityExpectation.new(1, 2, 3)
13
+ end
14
+
15
+ it "returns false when passed in expected_arguments are not equal" do
16
+ @expectation.should_not == ArgumentEqualityExpectation.new(1, 2)
17
+ @expectation.should_not == ArgumentEqualityExpectation.new(1)
18
+ @expectation.should_not == ArgumentEqualityExpectation.new(:something)
19
+ @expectation.should_not == ArgumentEqualityExpectation.new()
20
+ end
21
+ end
22
+
23
+ describe ArgumentEqualityExpectation, "#exact_match?" do
24
+ before do
25
+ @expectation = ArgumentEqualityExpectation.new(1, 2, 3)
26
+ end
27
+
28
+ it "returns true when all arguments exactly match" do
29
+ @expectation.should 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 ArgumentEqualityExpectation, "#wildcard_match?" do
38
+ it "returns false when not exact match" do
39
+ @expectation = ArgumentEqualityExpectation.new(1)
40
+ @expectation.should_not be_wildcard_match(1, 2, 3)
41
+ @expectation.should_not be_wildcard_match("whatever")
42
+ @expectation.should_not be_wildcard_match("whatever", "else")
43
+ end
44
+
45
+ it "returns true when exact match" do
46
+ @expectation = ArgumentEqualityExpectation.new(1, 2)
47
+ @expectation.should be_wildcard_match(1, 2)
48
+ @expectation.should_not be_wildcard_match(1)
49
+ @expectation.should_not be_wildcard_match("whatever", "else")
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,49 @@
1
+ dir = File.dirname(__FILE__)
2
+ require "#{dir}/../../example_helper"
3
+
4
+ module RR
5
+ module Expectations
6
+ describe ArgumentEqualityExpectation, "#exact_match? with is_a argument" do
7
+ before do
8
+ @expectation = ArgumentEqualityExpectation.new(boolean)
9
+ end
10
+
11
+ it "returns true when passed in an IsA module" do
12
+ @expectation.should be_exact_match(WildcardMatchers::Boolean.new)
13
+ end
14
+
15
+ it "returns false otherwise" do
16
+ @expectation.should_not be_exact_match("hello")
17
+ @expectation.should_not be_exact_match(:hello)
18
+ @expectation.should_not be_exact_match(1)
19
+ @expectation.should_not be_exact_match(nil)
20
+ @expectation.should_not be_exact_match(true)
21
+ @expectation.should_not be_exact_match()
22
+ end
23
+ end
24
+
25
+ describe ArgumentEqualityExpectation, "#wildcard_match? with is_a Boolean argument" do
26
+ before do
27
+ @expectation = ArgumentEqualityExpectation.new(boolean)
28
+ end
29
+
30
+ it "returns true when passed a Boolean" do
31
+ @expectation.should be_wildcard_match(true)
32
+ @expectation.should be_wildcard_match(false)
33
+ end
34
+
35
+ it "returns false when not passed a Boolean" do
36
+ @expectation.should_not be_wildcard_match(:not_a_boolean)
37
+ end
38
+
39
+ it "returns true when an exact match" do
40
+ @expectation.should be_wildcard_match(boolean)
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(true, false)
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,68 @@
1
+ dir = File.dirname(__FILE__)
2
+ require "#{dir}/../../example_helper"
3
+
4
+ module RR
5
+ module Expectations
6
+ describe ArgumentEqualityExpectation, "#exact_match? with duck_type argument" do
7
+ before do
8
+ @expectation = ArgumentEqualityExpectation.new(duck_type(:to_s))
9
+ end
10
+
11
+ it "returns true when passed in an DuckType matcher with the same argument list" do
12
+ @expectation.should be_exact_match(WildcardMatchers::DuckType.new(:to_s))
13
+ end
14
+
15
+ it "returns false when passed in an DuckType matcher with a different argument list" do
16
+ @expectation.should_not be_exact_match(WildcardMatchers::DuckType.new(:to_s, :to_i))
17
+ end
18
+
19
+ it "returns false otherwise" do
20
+ @expectation.should_not be_exact_match("hello")
21
+ @expectation.should_not be_exact_match(:hello)
22
+ @expectation.should_not be_exact_match(1)
23
+ @expectation.should_not be_exact_match(nil)
24
+ @expectation.should_not be_exact_match(true)
25
+ @expectation.should_not be_exact_match()
26
+ end
27
+ end
28
+
29
+ describe ArgumentEqualityExpectation, "#wildcard_match? with DuckType argument" do
30
+ before do
31
+ @matching_object = Object.new
32
+ def @matching_object.quack
33
+ end
34
+ def @matching_object.waddle
35
+ end
36
+
37
+ @partial_matching_object = Object.new
38
+ def @partial_matching_object.quack
39
+ end
40
+
41
+ @not_match_object = Object.new
42
+
43
+ @expectation = ArgumentEqualityExpectation.new(duck_type(:quack, :waddle))
44
+ end
45
+
46
+ it "returns true when object matches all required methods" do
47
+ @expectation.should be_wildcard_match(@matching_object)
48
+ end
49
+
50
+ it "returns false when object matches some required methods" do
51
+ @expectation.should_not be_wildcard_match(@partial_matching_object)
52
+ end
53
+
54
+ it "returns false when passed an object that matches no required methods" do
55
+ @expectation.should_not be_wildcard_match(@not_match_object)
56
+ end
57
+
58
+ it "returns true when an exact match" do
59
+ @expectation.should be_wildcard_match(duck_type(:quack, :waddle))
60
+ end
61
+
62
+ it "returns false when not passed correct number of arguments" do
63
+ @expectation.should_not be_wildcard_match()
64
+ @expectation.should_not be_wildcard_match(@matching_object, @matching_object)
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,51 @@
1
+ dir = File.dirname(__FILE__)
2
+ require "#{dir}/../../example_helper"
3
+
4
+ module RR
5
+ module Expectations
6
+ describe ArgumentEqualityExpectation, "#exact_match? with is_a argument" do
7
+ before do
8
+ @expectation = ArgumentEqualityExpectation.new(is_a(String))
9
+ end
10
+
11
+ it "returns true when passed in an IsA module" do
12
+ @expectation.should be_exact_match(WildcardMatchers::IsA.new(String))
13
+ end
14
+
15
+ it "returns false when passed in an IsA object with a different module" do
16
+ @expectation.should_not be_exact_match(WildcardMatchers::IsA.new(Integer))
17
+ end
18
+
19
+ it "returns false otherwise" do
20
+ @expectation.should_not be_exact_match("hello")
21
+ @expectation.should_not be_exact_match(:hello)
22
+ @expectation.should_not be_exact_match(1)
23
+ @expectation.should_not be_exact_match(nil)
24
+ @expectation.should_not be_exact_match()
25
+ end
26
+ end
27
+
28
+ describe ArgumentEqualityExpectation, "#wildcard_match? with is_a String argument" do
29
+ before do
30
+ @expectation = ArgumentEqualityExpectation.new(is_a(String))
31
+ end
32
+
33
+ it "returns true when passed a String" do
34
+ @expectation.should be_wildcard_match("Hello")
35
+ end
36
+
37
+ it "returns false when not passed a String" do
38
+ @expectation.should_not be_wildcard_match(:not_a_string)
39
+ end
40
+
41
+ it "returns true when an exact match" do
42
+ @expectation.should be_wildcard_match(is_a(String))
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("one", "two")
48
+ end
49
+ end
50
+ end
51
+ end