rr 0.2.5 → 0.3.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 (40) hide show
  1. data/CHANGES +5 -0
  2. data/README +20 -9
  3. data/Rakefile +1 -1
  4. data/examples/example_suite.rb +1 -1
  5. data/examples/high_level_example.rb +4 -4
  6. data/examples/rr/double/double_dispatching_example.rb +41 -41
  7. data/examples/rr/double/double_verify_example.rb +1 -1
  8. data/examples/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +2 -2
  9. data/examples/rr/extensions/instance_methods_creator_example.rb +48 -38
  10. data/examples/rr/extensions/instance_methods_space_example.rb +8 -8
  11. data/examples/rr/rspec/rspec_adapter_example.rb +9 -9
  12. data/examples/rr/rspec/rspec_usage_example.rb +16 -2
  13. data/examples/rr/scenario_creator_example.rb +400 -0
  14. data/examples/rr/scenario_example.rb +19 -4
  15. data/examples/rr/scenario_method_proxy_example.rb +71 -0
  16. data/examples/rr/space/space_create_example.rb +93 -106
  17. data/examples/rr/space/space_example.rb +2 -2
  18. data/examples/rr/space/space_register_example.rb +3 -3
  19. data/examples/rr/space/space_reset_example.rb +11 -11
  20. data/examples/rr/space/space_verify_example.rb +12 -12
  21. data/examples/rr/test_unit/test_unit_integration_test.rb +11 -2
  22. data/lib/rr.rb +10 -12
  23. data/lib/rr/errors/scenario_definition_error.rb +6 -0
  24. data/lib/rr/extensions/instance_methods.rb +84 -84
  25. data/lib/rr/scenario.rb +18 -3
  26. data/lib/rr/scenario_creator.rb +233 -0
  27. data/lib/rr/scenario_method_proxy.rb +19 -0
  28. data/lib/rr/space.rb +12 -32
  29. metadata +7 -13
  30. data/examples/rr/do_not_allow_creator_example.rb +0 -111
  31. data/examples/rr/mock_creator_example.rb +0 -87
  32. data/examples/rr/mock_probe_creator_example.rb +0 -120
  33. data/examples/rr/stub_creator_example.rb +0 -96
  34. data/examples/rr/stub_probe_creator_example.rb +0 -127
  35. data/lib/rr/creator.rb +0 -16
  36. data/lib/rr/do_not_allow_creator.rb +0 -33
  37. data/lib/rr/mock_creator.rb +0 -26
  38. data/lib/rr/mock_probe_creator.rb +0 -36
  39. data/lib/rr/stub_creator.rb +0 -30
  40. data/lib/rr/stub_probe_creator.rb +0 -42
@@ -1,33 +0,0 @@
1
- module RR
2
- # RR::DoNotAllowCreator uses RR::DoNotAllowCreator#method_missing to create
3
- # a Scenario that expects never to be called.
4
- #
5
- # The following example mocks method_name with arg1 and arg2
6
- # returning return_value.
7
- #
8
- # do_not_allow(subject).method_name(arg1, arg2) { return_value }
9
- #
10
- # The DoNotAllowCreator also supports a block sytnax.
11
- #
12
- # do_not_allow(subject) do |m|
13
- # m.method1 # Do not allow method1 with any arguments
14
- # m.method2(arg1, arg2) # Do not allow method2 with arguments arg1 and arg2
15
- # m.method3.with_no_args # Do not allow method3 with no arguments
16
- # end
17
- class DoNotAllowCreator < Creator
18
- module InstanceMethods
19
- protected
20
- def method_missing(method_name, *args, &returns)
21
- double = @space.create_double(@subject, method_name)
22
- scenario = @space.create_scenario(double)
23
- if args.empty?
24
- scenario.with_any_args
25
- else
26
- scenario.with(*args)
27
- end
28
- scenario.never.returns(&returns)
29
- scenario
30
- end
31
- end
32
- end
33
- end
@@ -1,26 +0,0 @@
1
- module RR
2
- # RR::MockCreator uses RR::MockCreator#method_missing to create
3
- # a Scenario that acts like a mock.
4
- #
5
- # The following example mocks method_name with arg1 and arg2
6
- # returning return_value.
7
- #
8
- # mock(subject).method_name(arg1, arg2) { return_value }
9
- #
10
- # The MockCreator also supports a block sytnax.
11
- #
12
- # mock(subject) do |m|
13
- # m.method_name(arg1, arg2) { return_value }
14
- # end
15
- class MockCreator < Creator
16
- module InstanceMethods
17
- protected
18
- def method_missing(method_name, *args, &returns)
19
- double = @space.create_double(@subject, method_name)
20
- scenario = @space.create_scenario(double)
21
- scenario.with(*args).once.returns(&returns)
22
- scenario
23
- end
24
- end
25
- end
26
- end
@@ -1,36 +0,0 @@
1
- module RR
2
- # RR::MockProbeCreator uses RR::MockProbeCreator#method_missing to create
3
- # a Scenario that acts like a mock with probing capabilities.
4
- #
5
- # Passing a block allows you to intercept the return value.
6
- # The return value can be modified, validated, and/or overridden by
7
- # passing in a block. The return value of the block will replace
8
- # the actual return value.
9
- #
10
- # probe(subject).method_name(arg1, arg2) do |return_value|
11
- # return_value.method_name.should == :return_value
12
- # my_return_value
13
- # end
14
- #
15
- # probe(User) do |m|
16
- # m.find('4') do |user|
17
- # mock(user).valid? {false}
18
- # user
19
- # end
20
- # end
21
- #
22
- # user = User.find('4')
23
- # user.valid? # false
24
- class MockProbeCreator < Creator
25
- module InstanceMethods
26
- protected
27
- def method_missing(method_name, *args, &after_call)
28
- double = @space.create_double(@subject, method_name)
29
- scenario = @space.create_scenario(double)
30
- scenario.with(*args).once.implemented_by(double.original_method)
31
- scenario.after_call(&after_call) if after_call
32
- scenario
33
- end
34
- end
35
- end
36
- end
@@ -1,30 +0,0 @@
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 < Creator
16
- module InstanceMethods
17
- protected
18
- def method_missing(method_name, *args, &returns)
19
- double = @space.create_double(@subject, method_name)
20
- scenario = @space.create_scenario(double)
21
- scenario.returns(&returns).any_number_of_times
22
- if args.empty?
23
- scenario.with_any_args
24
- else
25
- scenario.with(*args)
26
- end
27
- end
28
- end
29
- end
30
- end
@@ -1,42 +0,0 @@
1
- module RR
2
- # RR::StubProbeCreator uses RR::StubProbeCreator#method_missing to create
3
- # a Scenario that acts like a stub with probing capabilities.
4
- #
5
- # Passing a block allows you to intercept the return value.
6
- # The return value can be modified, validated, and/or overridden by
7
- # passing in a block. The return value of the block will replace
8
- # the actual return value.
9
- #
10
- # probe_stub(subject).method_name(arg1, arg2) do |return_value|
11
- # return_value.method_name.should == :return_value
12
- # my_return_value
13
- # end
14
- #
15
- # probe_stub(User) do |m|
16
- # m.find do |user|
17
- # mock(user).valid? {false}
18
- # user
19
- # end
20
- # end
21
- #
22
- # user = User.find('4')
23
- # user.valid? # false
24
- class StubProbeCreator < Creator
25
- module InstanceMethods
26
- protected
27
- def method_missing(method_name, *args, &after_call)
28
- double = @space.create_double(@subject, method_name)
29
- scenario = @space.create_scenario(double)
30
- scenario.implemented_by(double.original_method)
31
- scenario.any_number_of_times
32
- if args.empty?
33
- scenario.with_any_args
34
- else
35
- scenario.with(*args)
36
- end
37
- scenario.after_call(&after_call) if after_call
38
- scenario
39
- end
40
- end
41
- end
42
- end