rr 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
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,4 @@
1
+ module RR
2
+ class ScenarioNotFoundError < RuntimeError
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module RR
2
+ class ScenarioOrderError < RuntimeError
3
+ end
4
+ end
@@ -0,0 +1,111 @@
1
+ module RR
2
+ # RR::Space is a Dependency Injection http://en.wikipedia.org/wiki/Dependency_injection
3
+ # and global state object for the RR framework. The RR::Space.instance
4
+ # is a singleton that holds the state.
5
+ class Space
6
+ class << self
7
+ def instance
8
+ @instance ||= new
9
+ end
10
+ attr_writer :instance
11
+
12
+ protected
13
+ def method_missing(method_name, *args, &block)
14
+ instance.__send__(method_name, *args, &block)
15
+ end
16
+ end
17
+
18
+ attr_reader :doubles, :ordered_scenarios
19
+ def initialize
20
+ @doubles = Hash.new {|hash, subject_object| hash[subject_object] = Hash.new}
21
+ @ordered_scenarios = []
22
+ end
23
+
24
+ # Creates a MockCreator.
25
+ def create_mock_creator(subject, &definition)
26
+ MockCreator.new(self, subject, &definition)
27
+ end
28
+
29
+ # Creates a StubCreator.
30
+ def create_stub_creator(subject, &definition)
31
+ StubCreator.new(self, subject, &definition)
32
+ end
33
+
34
+ # Creates a ProbeCreator.
35
+ def create_probe_creator(subject, &definition)
36
+ ProbeCreator.new(self, subject, &definition)
37
+ end
38
+
39
+ # Creates a DoNotAllowCreator.
40
+ def create_do_not_allow_creator(subject, &definition)
41
+ DoNotAllowCreator.new(self, subject, &definition)
42
+ end
43
+
44
+ # Creates and registers a Scenario to be verified.
45
+ def create_scenario(double)
46
+ scenario = Scenario.new(self)
47
+ double.register_scenario scenario
48
+ scenario
49
+ end
50
+
51
+ # Reuses or creates, if none exists, a Double for the passed
52
+ # in object and method_name.
53
+ # When a Double is created, it binds the dispatcher to the
54
+ # object.
55
+ def create_double(object, method_name)
56
+ double = @doubles[object][method_name.to_sym]
57
+ return double if double
58
+
59
+ double = Double.new(self, object, method_name.to_sym)
60
+ @doubles[object][method_name.to_sym] = double
61
+ double.bind
62
+ double
63
+ end
64
+
65
+ # Registers the ordered Scenario to be verified.
66
+ def register_ordered_scenario(scenario)
67
+ @ordered_scenarios << scenario
68
+ end
69
+
70
+ # Verifies that the passed in ordered Scenario is being called
71
+ # in the correct position.
72
+ def verify_ordered_scenario(scenario)
73
+ raise ::RR::ScenarioOrderError unless @ordered_scenarios.first == scenario
74
+ @ordered_scenarios.shift if scenario.times_called_verified?
75
+ scenario
76
+ end
77
+
78
+ # Verifies all the Double objects have met their
79
+ # TimesCalledExpectations.
80
+ def verify_doubles
81
+ @doubles.each do |object, method_double_map|
82
+ method_double_map.keys.each do |method_name|
83
+ verify_double(object, method_name)
84
+ end
85
+ end
86
+ end
87
+
88
+ # Resets the registered Doubles for the next test run.
89
+ def reset_doubles
90
+ @doubles.each do |object, method_double_map|
91
+ method_double_map.keys.each do |method_name|
92
+ reset_double(object, method_name)
93
+ end
94
+ end
95
+ end
96
+
97
+ # Verifies the Double for the passed in object and method_name.
98
+ def verify_double(object, method_name)
99
+ @doubles[object][method_name].verify
100
+ ensure
101
+ reset_double object, method_name
102
+ end
103
+
104
+ # Resets the Double for the passed in object and method_name.
105
+ def reset_double(object, method_name)
106
+ double = @doubles[object].delete(method_name)
107
+ @doubles.delete(object) if @doubles[object].empty?
108
+ double.reset
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,36 @@
1
+ module RR
2
+ # RR::StubCreator uses RR::StubCreator#method_missing to create
3
+ # a Scenario that acts like a stub.
4
+ #
5
+ # The following example stubs method_name with arg1 and arg2
6
+ # returning return_value.
7
+ #
8
+ # stub(subject).method_name(arg1, arg2) { return_value }
9
+ #
10
+ # The StubCreator also supports a block sytnax.
11
+ #
12
+ # stub(subject) do |m|
13
+ # m.method_name(arg1, arg2) { return_value }
14
+ # end
15
+ class StubCreator
16
+ instance_methods.each { |m| undef_method m unless m =~ /^__/ }
17
+
18
+ def initialize(space, subject)
19
+ @space = space
20
+ @subject = subject
21
+ yield(self) if block_given?
22
+ end
23
+
24
+ protected
25
+ def method_missing(method_name, *args, &returns)
26
+ double = @space.create_double(@subject, method_name)
27
+ scenario = @space.create_scenario(double)
28
+ scenario.returns(&returns)
29
+ if args.empty?
30
+ scenario.with_any_args
31
+ else
32
+ scenario.with(*args)
33
+ end
34
+ end
35
+ end
36
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.3
3
+ specification_version: 1
4
+ name: rr
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.1.0
7
+ date: 2007-07-07 00:00:00 -07:00
8
+ summary: RR (Double Ruby) is a double framework that features a rich selection of double techniques and a terse syntax. http://xunitpatterns.com/Test%20Double.html
9
+ require_paths:
10
+ - lib
11
+ email: brian@pivotallabs.com
12
+ homepage: http://pivotallabs.com
13
+ rubyforge_project: pivotalrb
14
+ description: RR (Double Ruby) is a double framework that features a rich selection of double techniques and a terse syntax. http://xunitpatterns.com/Test%20Double.html
15
+ autorequire: rr
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Brian Takita
31
+ files:
32
+ - Rakefile
33
+ - CHANGES
34
+ - README
35
+ - lib/rr.rb
36
+ - lib/rr/scenario.rb
37
+ - lib/rr/scenario_not_found_error.rb
38
+ - lib/rr/scenario_order_error.rb
39
+ - lib/rr/stub_creator.rb
40
+ - lib/rr/space.rb
41
+ - lib/rr/double.rb
42
+ - lib/rr/do_not_allow_creator.rb
43
+ - lib/rr/mock_creator.rb
44
+ - lib/rr/probe_creator.rb
45
+ - lib/rr/expectations/argument_equality_expectation.rb
46
+ - lib/rr/expectations/times_called_expectation.rb
47
+ - lib/rr/expectations/any_argument_expectation.rb
48
+ - lib/rr/expectations/wildcard_matchers/boolean.rb
49
+ - lib/rr/expectations/wildcard_matchers/duck_type.rb
50
+ - lib/rr/expectations/wildcard_matchers/range.rb
51
+ - lib/rr/expectations/wildcard_matchers/regexp.rb
52
+ - lib/rr/expectations/wildcard_matchers/numeric.rb
53
+ - lib/rr/expectations/wildcard_matchers/is_a.rb
54
+ - lib/rr/expectations/wildcard_matchers/anything.rb
55
+ - lib/rr/adapters/test_unit.rb
56
+ - lib/rr/adapters/rspec.rb
57
+ - lib/rr/extensions/double_methods.rb
58
+ - examples/environment_fixture_setup.rb
59
+ - examples/rspec_example_suite.rb
60
+ - examples/example_suite.rb
61
+ - examples/example_helper.rb
62
+ - examples/test_unit_example_suite.rb
63
+ - examples/high_level_example.rb
64
+ - examples/rr/space_verify_example.rb
65
+ - examples/rr/probe_creator_example.rb
66
+ - examples/rr/double_reset_example.rb
67
+ - examples/rr/mock_creator_example.rb
68
+ - examples/rr/stub_creator_example.rb
69
+ - examples/rr/scenario_example.rb
70
+ - examples/rr/space_reset_example.rb
71
+ - examples/rr/double_bind_example.rb
72
+ - examples/rr/double_register_scenario_example.rb
73
+ - examples/rr/space_create_example.rb
74
+ - examples/rr/do_not_allow_creator_example.rb
75
+ - examples/rr/double_example.rb
76
+ - examples/rr/space_helper.rb
77
+ - examples/rr/space_example.rb
78
+ - examples/rr/double_dispatching_example.rb
79
+ - examples/rr/space_register_example.rb
80
+ - examples/rr/double_verify_example.rb
81
+ - examples/rr/rspec/rspec_adapter_example.rb
82
+ - examples/rr/rspec/rspec_usage_example.rb
83
+ - examples/rr/expectations/is_a_argument_equality_expectation_example.rb
84
+ - examples/rr/expectations/any_argument_expectation_example.rb
85
+ - examples/rr/expectations/regexp_argument_equality_expectation_example.rb
86
+ - examples/rr/expectations/boolean_argument_equality_expectation_example.rb
87
+ - examples/rr/expectations/times_called_expectation_example.rb
88
+ - examples/rr/expectations/duck_type_argument_equality_expectation_example.rb
89
+ - examples/rr/expectations/numeric_argument_equality_expectation_example.rb
90
+ - examples/rr/expectations/range_argument_equality_expectation_example.rb
91
+ - examples/rr/expectations/argument_equality_expectation_example.rb
92
+ - examples/rr/expectations/anything_argument_equality_expectation_example.rb
93
+ - examples/rr/test_unit/test_helper.rb
94
+ - examples/rr/test_unit/test_unit_integration_test.rb
95
+ - examples/rr/extensions/double_methods_example.rb
96
+ test_files: []
97
+
98
+ rdoc_options:
99
+ - --main
100
+ - README
101
+ - --inline-source
102
+ - --line-numbers
103
+ extra_rdoc_files:
104
+ - README
105
+ - CHANGES
106
+ executables: []
107
+
108
+ extensions: []
109
+
110
+ requirements: []
111
+
112
+ dependencies: []
113
+