rr 0.2.5 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
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,87 +0,0 @@
1
- require "examples/example_helper"
2
-
3
- module RR
4
- describe MockCreator, :shared => true do
5
- before(:each) do
6
- @space = Space.new
7
- @subject = Object.new
8
- end
9
-
10
- it "initializes creator with passed in object" do
11
- class << @creator
12
- attr_reader :subject
13
- end
14
- @creator.subject.should === @subject
15
- end
16
- end
17
-
18
- describe MockCreator, ".new without block" do
19
- it_should_behave_like "RR::MockCreator"
20
-
21
- before do
22
- @creator = MockCreator.new(@space, @subject)
23
- end
24
-
25
- it "clears out all methods from creator" do
26
- creator_subclass = Class.new(MockCreator) do
27
- def i_should_be_a_scenario
28
- end
29
- end
30
- creator_subclass.instance_methods.should include('i_should_be_a_scenario')
31
-
32
- creator = creator_subclass.new(@space, @subject)
33
- creator.i_should_be_a_scenario.should be_instance_of(Scenario)
34
- end
35
- end
36
-
37
- describe MockCreator, ".new with block" do
38
- it_should_behave_like "RR::MockCreator"
39
-
40
- before do
41
- @creator = MockCreator.new(@space, @subject) do |c|
42
- c.foobar(1, 2) {:one_two}
43
- c.foobar(1) {:one}
44
- c.foobar.with_any_args {:default}
45
- c.baz() {:baz_result}
46
- end
47
- end
48
-
49
- it "creates doubles" do
50
- @subject.foobar(1, 2).should == :one_two
51
- @subject.foobar(1).should == :one
52
- @subject.foobar(:something).should == :default
53
- @subject.baz.should == :baz_result
54
- end
55
-
56
- it "clears out all methods from creator" do
57
- creator_subclass = Class.new(MockCreator) do
58
- def i_should_be_a_scenario
59
- end
60
- end
61
- creator_subclass.instance_methods.should include('i_should_be_a_scenario')
62
-
63
- creator_subclass.new(@space, @subject) do |m|
64
- m.i_should_be_a_scenario.should be_instance_of(Scenario)
65
- end
66
- end
67
- end
68
-
69
-
70
- describe MockCreator, "#method_missing" do
71
- it_should_behave_like "RR::MockCreator"
72
-
73
- before do
74
- @subject = Object.new
75
- @creator = MockCreator.new(@space, @subject)
76
- end
77
-
78
- it "sets expectations on the subject" do
79
- @creator.foobar(1, 2) {:baz}.twice
80
-
81
- @subject.foobar(1, 2).should == :baz
82
- @subject.foobar(1, 2).should == :baz
83
- proc {@subject.foobar(1, 2)}.should raise_error(Errors::TimesCalledError)
84
- end
85
- end
86
-
87
- end
@@ -1,120 +0,0 @@
1
- require "examples/example_helper"
2
-
3
- module RR
4
- describe MockProbeCreator, :shared => true do
5
- before(:each) do
6
- @space = Space.new
7
- @subject = Object.new
8
- end
9
-
10
- it "initializes creator with passed in object" do
11
- class << @creator
12
- attr_reader :subject
13
- end
14
- @creator.subject.should === @subject
15
- end
16
- end
17
-
18
- describe MockProbeCreator, ".new without block" do
19
- it_should_behave_like "RR::MockProbeCreator"
20
-
21
- before do
22
- @creator = MockProbeCreator.new(@space, @subject)
23
- end
24
-
25
- it "clears out all methods from creator" do
26
- creator_subclass = Class.new(MockProbeCreator) do
27
- def i_should_be_a_scenario
28
- end
29
- end
30
- creator_subclass.instance_methods.should include('i_should_be_a_scenario')
31
-
32
- creator = creator_subclass.new(@space, @subject)
33
- creator.i_should_be_a_scenario.should be_instance_of(Scenario)
34
- end
35
- end
36
-
37
- describe MockProbeCreator, ".new with block" do
38
- it_should_behave_like "RR::MockProbeCreator"
39
-
40
- before do
41
- def @subject.foobar(*args)
42
- :original_foobar
43
- end
44
- @creator = MockProbeCreator.new(@space, @subject) do |c|
45
- c.foobar(1, 2)
46
- c.foobar(1)
47
- c.foobar.with_any_args
48
- end
49
- end
50
-
51
- it "creates doubles" do
52
- @subject.foobar(1, 2).should == :original_foobar
53
- @subject.foobar(1).should == :original_foobar
54
- @subject.foobar(:something).should == :original_foobar
55
- proc {@subject.foobar(:nasty)}.should raise_error
56
- end
57
-
58
- it "clears out all methods from creator" do
59
- creator_subclass = Class.new(MockProbeCreator) do
60
- def i_should_be_a_scenario
61
- end
62
- end
63
- creator_subclass.instance_methods.should include('i_should_be_a_scenario')
64
-
65
- creator_subclass.new(@space, @subject) do |m|
66
- m.i_should_be_a_scenario.should be_instance_of(Scenario)
67
- end
68
- end
69
- end
70
-
71
- describe MockProbeCreator, ".new where method takes a block" do
72
- it_should_behave_like "RR::MockProbeCreator"
73
-
74
- before do
75
- def @subject.foobar(*args, &block)
76
- yield(*args)
77
- end
78
- @creator = MockProbeCreator.new(@space, @subject)
79
- end
80
-
81
- it "calls the block" do
82
- @creator.foobar(1, 2)
83
- @subject.foobar(1, 2) {|arg1, arg2| [arg2, arg1]}.should == [2, 1]
84
- end
85
- end
86
-
87
-
88
- describe MockProbeCreator, "#method_missing" do
89
- it_should_behave_like "RR::MockProbeCreator"
90
-
91
- before do
92
- @subject = Object.new
93
- @creator = MockProbeCreator.new(@space, @subject)
94
- end
95
-
96
- it "sets expectations on the subject while calling the original method" do
97
- def @subject.foobar(*args); :baz; end
98
- @creator.foobar(1, 2).twice
99
- @subject.foobar(1, 2).should == :baz
100
- @subject.foobar(1, 2).should == :baz
101
- proc {@subject.foobar(1, 2)}.should raise_error(Errors::TimesCalledError)
102
- end
103
-
104
- it "sets after_call on the scenario when passed a block" do
105
- real_value = Object.new
106
- (class << @subject; self; end).class_eval do
107
- define_method(:foobar) {real_value}
108
- end
109
- @creator.foobar(1, 2) do |value|
110
- mock(value).a_method {99}
111
- value
112
- end
113
-
114
- return_value = @subject.foobar(1, 2)
115
- return_value.should === return_value
116
- return_value.a_method.should == 99
117
- end
118
- end
119
-
120
- end
@@ -1,96 +0,0 @@
1
- require "examples/example_helper"
2
-
3
- module RR
4
- describe StubCreator, :shared => true do
5
- before(:each) do
6
- @space = Space.new
7
- @subject = Object.new
8
- end
9
-
10
- it "initializes creator with passed in object" do
11
- class << @creator
12
- attr_reader :subject
13
- end
14
- @creator.subject.should === @subject
15
- end
16
- end
17
-
18
- describe StubCreator, ".new without block" do
19
- it_should_behave_like "RR::StubCreator"
20
-
21
- before do
22
- @creator = StubCreator.new(@space, @subject)
23
- end
24
-
25
- it "clears out all methods from creator" do
26
- creator_subclass = Class.new(StubCreator) do
27
- def i_should_be_a_scenario
28
- end
29
- end
30
- creator_subclass.instance_methods.should include('i_should_be_a_scenario')
31
-
32
- creator = creator_subclass.new(@space, @subject)
33
- creator.i_should_be_a_scenario.should be_instance_of(Scenario)
34
- end
35
- end
36
-
37
- describe StubCreator, ".new with block" do
38
- it_should_behave_like "RR::StubCreator"
39
-
40
- before do
41
- @creator = StubCreator.new(@space, @subject) do |c|
42
- c.foobar(1, 2) {:one_two}
43
- c.foobar(1) {:one}
44
- c.foobar.with_any_args {:default}
45
- c.baz() {:baz_result}
46
- end
47
- end
48
-
49
- it "creates doubles" do
50
- @subject.foobar(1, 2).should == :one_two
51
- @subject.foobar(1, 2).should == :one_two
52
- @subject.foobar(1).should == :one
53
- @subject.foobar(1).should == :one
54
- @subject.foobar(:something).should == :default
55
- @subject.foobar(:something).should == :default
56
- @subject.baz.should == :baz_result
57
- @subject.baz.should == :baz_result
58
- end
59
-
60
- it "clears out all methods from creator" do
61
- creator_subclass = Class.new(StubCreator) do
62
- def i_should_be_a_scenario
63
- end
64
- end
65
- creator_subclass.instance_methods.should include('i_should_be_a_scenario')
66
-
67
- creator_subclass.new(@space, @subject) do |m|
68
- m.i_should_be_a_scenario.should be_instance_of(Scenario)
69
- end
70
- end
71
- end
72
-
73
- describe StubCreator, "#method_missing" do
74
- it_should_behave_like "RR::StubCreator"
75
-
76
- before do
77
- @subject = Object.new
78
- @creator = StubCreator.new(@space, @subject)
79
- end
80
-
81
- it "stubs the subject without any args" do
82
- @creator.foobar {:baz}
83
- @subject.foobar.should == :baz
84
- end
85
-
86
- it "stubs the subject mapping passed in args with the output" do
87
- @creator.foobar(1, 2) {:one_two}
88
- @creator.foobar(1) {:one}
89
- @creator.foobar() {:nothing}
90
- @subject.foobar.should == :nothing
91
- @subject.foobar(1).should == :one
92
- @subject.foobar(1, 2).should == :one_two
93
- end
94
- end
95
-
96
- end
@@ -1,127 +0,0 @@
1
- require "examples/example_helper"
2
-
3
- module RR
4
- describe StubProbeCreator, :shared => true do
5
- before(:each) do
6
- @space = Space.new
7
- @subject = Object.new
8
- end
9
-
10
- it "initializes creator with passed in object" do
11
- class << @creator
12
- attr_reader :subject
13
- end
14
- @creator.subject.should === @subject
15
- end
16
- end
17
-
18
- describe StubProbeCreator, ".new without block" do
19
- it_should_behave_like "RR::StubProbeCreator"
20
-
21
- before do
22
- @creator = StubProbeCreator.new(@space, @subject)
23
- end
24
-
25
- it "clears out all methods from creator" do
26
- creator_subclass = Class.new(StubProbeCreator) do
27
- def i_should_be_a_scenario
28
- end
29
- end
30
- creator_subclass.instance_methods.should include('i_should_be_a_scenario')
31
-
32
- creator = creator_subclass.new(@space, @subject)
33
- creator.i_should_be_a_scenario.should be_instance_of(Scenario)
34
- end
35
- end
36
-
37
- describe StubProbeCreator, ".new with block" do
38
- it_should_behave_like "RR::StubProbeCreator"
39
-
40
- before do
41
- def @subject.foobar(*args)
42
- :original_foobar
43
- end
44
- @creator = StubProbeCreator.new(@space, @subject) do |c|
45
- c.foobar
46
- end
47
- end
48
-
49
- it "creates doubles" do
50
- @subject.foobar(1, 2).should == :original_foobar
51
- @subject.foobar(1, 2).should == :original_foobar
52
- @subject.foobar(1).should == :original_foobar
53
- @subject.foobar(1).should == :original_foobar
54
- @subject.foobar(:something).should == :original_foobar
55
- @subject.foobar(:something).should == :original_foobar
56
- end
57
-
58
- it "clears out all methods from creator" do
59
- creator_subclass = Class.new(StubProbeCreator) do
60
- def i_should_be_a_scenario
61
- end
62
- end
63
- creator_subclass.instance_methods.should include('i_should_be_a_scenario')
64
-
65
- creator_subclass.new(@space, @subject) do |m|
66
- m.i_should_be_a_scenario.should be_instance_of(Scenario)
67
- end
68
- end
69
- end
70
-
71
- describe StubProbeCreator, ".new where method takes a block" do
72
- it_should_behave_like "RR::StubProbeCreator"
73
-
74
- before do
75
- def @subject.foobar(*args, &block)
76
- yield(*args)
77
- end
78
- @creator = StubProbeCreator.new(@space, @subject)
79
- end
80
-
81
- it "calls the block" do
82
- @creator.foobar(1, 2)
83
- @subject.foobar(1, 2) {|arg1, arg2| [arg2, arg1]}.should == [2, 1]
84
- end
85
- end
86
-
87
- describe StubProbeCreator, "#method_missing" do
88
- it_should_behave_like "RR::StubProbeCreator"
89
-
90
- before do
91
- @subject = Object.new
92
- @creator = StubProbeCreator.new(@space, @subject)
93
- end
94
-
95
- it "sets up a scenario with passed in arguments" do
96
- def @subject.foobar(*args); :baz; end
97
- @creator.foobar(1, 2)
98
- proc do
99
- @subject.foobar
100
- end.should raise_error(Errors::ScenarioNotFoundError)
101
- end
102
-
103
- it "sets expectations on the subject while calling the original method" do
104
- def @subject.foobar(*args); :baz; end
105
- @creator.foobar(1, 2) {:new_value}
106
- 10.times do
107
- @subject.foobar(1, 2).should == :new_value
108
- end
109
- end
110
-
111
- it "sets after_call on the scenario when passed a block" do
112
- real_value = Object.new
113
- (class << @subject; self; end).class_eval do
114
- define_method(:foobar) {real_value}
115
- end
116
- @creator.foobar(1, 2) do |value|
117
- mock(value).a_method {99}
118
- value
119
- end
120
-
121
- return_value = @subject.foobar(1, 2)
122
- return_value.should === return_value
123
- return_value.a_method.should == 99
124
- end
125
- end
126
-
127
- end
@@ -1,16 +0,0 @@
1
- module RR
2
- # RR::Creator is the superclass for all creators.
3
- class Creator
4
- def initialize(space, subject, &block)
5
- @space = space
6
- @subject = subject
7
- class << self
8
- instance_methods.each do |m|
9
- undef_method m unless m =~ /^__/
10
- end
11
- include self::InstanceMethods
12
- end
13
- yield(self) if block_given?
14
- end
15
- end
16
- end