rr 0.2.2 → 0.2.3
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.
- data/CHANGES +3 -0
- data/README +19 -3
- data/Rakefile +1 -1
- data/examples/rr/extensions/instance_methods_space_example.rb +122 -0
- data/lib/rr/adapters/rspec.rb +3 -3
- data/lib/rr/adapters/test_unit.rb +2 -2
- data/lib/rr/extensions/instance_methods.rb +11 -0
- metadata +84 -83
data/CHANGES
CHANGED
data/README
CHANGED
@@ -18,21 +18,37 @@ http://xunitpatterns.com/Test%20Stub.html
|
|
18
18
|
stub(User).find('42') {jane}
|
19
19
|
mock(jane).valid? {true}
|
20
20
|
|
21
|
-
== Probing
|
21
|
+
== Mock Probing
|
22
22
|
Add verifications that a method was called while actually calling it.
|
23
23
|
The following example verifies render partial will be called and
|
24
24
|
renders the partial.
|
25
25
|
|
26
26
|
view = controller.template
|
27
27
|
probe(view).render(:partial => "user_info")
|
28
|
+
# or mock_probe.render(:partial => "user_info")
|
28
29
|
|
29
30
|
Probes also support after_call callbacks. This is useful for Stubbing out
|
30
|
-
a class method and getting its return value.
|
31
|
+
a class method and getting its return value. You can also change the return value.
|
32
|
+
This technique is also useful for verifying that you are mocking exists and
|
33
|
+
functions proberly, thereby testing you interface.
|
34
|
+
For example, using ActiveRecord:
|
31
35
|
|
32
36
|
probe(User).find('5') do |user|
|
33
37
|
mock(user).valid? {false}
|
38
|
+
user
|
34
39
|
end
|
35
|
-
|
40
|
+
|
41
|
+
== Mock Stubbing
|
42
|
+
Intercept the return value of a method call.
|
43
|
+
The following example verifies render partial will be called and
|
44
|
+
renders the partial.
|
45
|
+
|
46
|
+
view = controller.template
|
47
|
+
stub_probe(view).render(:partial => "user_info") do |html|
|
48
|
+
html.should include("Joe Smith")
|
49
|
+
html
|
50
|
+
end
|
51
|
+
|
36
52
|
== Block Syntax
|
37
53
|
script = MyScript.new
|
38
54
|
mock(script) do |m|
|
data/Rakefile
CHANGED
@@ -0,0 +1,122 @@
|
|
1
|
+
require "examples/example_helper"
|
2
|
+
|
3
|
+
module RR
|
4
|
+
module Extensions
|
5
|
+
describe InstanceMethods, " space example", :shared => true do
|
6
|
+
it_should_behave_like "RR::Extensions::InstanceMethods"
|
7
|
+
before do
|
8
|
+
@old_space = Space.instance
|
9
|
+
|
10
|
+
@space = Space.new
|
11
|
+
Space.instance = @space
|
12
|
+
@object1 = Object.new
|
13
|
+
@object2 = Object.new
|
14
|
+
@method_name = :foobar
|
15
|
+
end
|
16
|
+
|
17
|
+
after do
|
18
|
+
Space.instance = @old_space
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe InstanceMethods, "#verify" do
|
23
|
+
it_should_behave_like "RR::Extensions::InstanceMethods space example"
|
24
|
+
|
25
|
+
it "#verify verifies and deletes the doubles" do
|
26
|
+
should verify_all_doubles {verify}
|
27
|
+
end
|
28
|
+
|
29
|
+
it "#rr_verify verifies and deletes the doubles" do
|
30
|
+
should verify_all_doubles {rr_verify}
|
31
|
+
end
|
32
|
+
|
33
|
+
def verify_all_doubles
|
34
|
+
double1 = @space.create_double(@object1, @method_name)
|
35
|
+
double1_verify_calls = 0
|
36
|
+
double1_reset_calls = 0
|
37
|
+
(class << double1; self; end).class_eval do
|
38
|
+
define_method(:verify) do ||
|
39
|
+
double1_verify_calls += 1
|
40
|
+
end
|
41
|
+
define_method(:reset) do ||
|
42
|
+
double1_reset_calls += 1
|
43
|
+
end
|
44
|
+
end
|
45
|
+
double2 = @space.create_double(@object2, @method_name)
|
46
|
+
double2_verify_calls = 0
|
47
|
+
double2_reset_calls = 0
|
48
|
+
(class << double2; self; end).class_eval do
|
49
|
+
define_method(:verify) do ||
|
50
|
+
double2_verify_calls += 1
|
51
|
+
end
|
52
|
+
define_method(:reset) do ||
|
53
|
+
double2_reset_calls += 1
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
yield
|
58
|
+
double1_verify_calls.should == 1
|
59
|
+
double2_verify_calls.should == 1
|
60
|
+
double1_reset_calls.should == 1
|
61
|
+
double1_reset_calls.should == 1
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe InstanceMethods, "#reset" do
|
66
|
+
it_should_behave_like "RR::Extensions::InstanceMethods space example"
|
67
|
+
|
68
|
+
it "#reset removes the ordered scenarios" do
|
69
|
+
should remove_ordered_scenarios {reset}
|
70
|
+
end
|
71
|
+
|
72
|
+
it "#rr_reset removes the ordered scenarios" do
|
73
|
+
should remove_ordered_scenarios {rr_reset}
|
74
|
+
end
|
75
|
+
|
76
|
+
it "#reset resets all doubles" do
|
77
|
+
should reset_all_doubles {reset}
|
78
|
+
end
|
79
|
+
|
80
|
+
it "#rr_reset resets all doubles" do
|
81
|
+
should reset_all_doubles {rr_reset}
|
82
|
+
end
|
83
|
+
|
84
|
+
def remove_ordered_scenarios
|
85
|
+
double1 = @space.create_double(@object1, :foobar1)
|
86
|
+
double2 = @space.create_double(@object1, :foobar2)
|
87
|
+
|
88
|
+
scenario1 = @space.create_scenario(double1)
|
89
|
+
scenario2 = @space.create_scenario(double2)
|
90
|
+
|
91
|
+
scenario1.ordered
|
92
|
+
scenario2.ordered
|
93
|
+
|
94
|
+
@space.ordered_scenarios.should_not be_empty
|
95
|
+
|
96
|
+
yield
|
97
|
+
@space.ordered_scenarios.should be_empty
|
98
|
+
end
|
99
|
+
|
100
|
+
def reset_all_doubles
|
101
|
+
double1 = @space.create_double(@object1, @method_name)
|
102
|
+
double1_reset_calls = 0
|
103
|
+
(class << double1; self; end).class_eval do
|
104
|
+
define_method(:reset) do ||
|
105
|
+
double1_reset_calls += 1
|
106
|
+
end
|
107
|
+
end
|
108
|
+
double2 = @space.create_double(@object2, @method_name)
|
109
|
+
double2_reset_calls = 0
|
110
|
+
(class << double2; self; end).class_eval do
|
111
|
+
define_method(:reset) do ||
|
112
|
+
double2_reset_calls += 1
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
yield
|
117
|
+
double1_reset_calls.should == 1
|
118
|
+
double2_reset_calls.should == 1
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
data/lib/rr/adapters/rspec.rb
CHANGED
@@ -6,13 +6,13 @@ module RR
|
|
6
6
|
module Rspec
|
7
7
|
include RR::Extensions::InstanceMethods
|
8
8
|
def setup_mocks_for_rspec
|
9
|
-
|
9
|
+
rr_reset
|
10
10
|
end
|
11
11
|
def verify_mocks_for_rspec
|
12
|
-
|
12
|
+
rr_verify
|
13
13
|
end
|
14
14
|
def teardown_mocks_for_rspec
|
15
|
-
|
15
|
+
rr_reset
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
@@ -9,13 +9,13 @@ module RR
|
|
9
9
|
alias_method :setup_without_rr, :setup
|
10
10
|
def setup_with_rr
|
11
11
|
setup_without_rr
|
12
|
-
|
12
|
+
rr_reset
|
13
13
|
end
|
14
14
|
alias_method :setup, :setup_with_rr
|
15
15
|
|
16
16
|
alias_method :teardown_without_rr, :teardown
|
17
17
|
def teardown_with_rr
|
18
|
-
|
18
|
+
rr_verify
|
19
19
|
teardown_without_rr
|
20
20
|
end
|
21
21
|
alias_method :teardown, :teardown_with_rr
|
@@ -1,6 +1,17 @@
|
|
1
1
|
module RR
|
2
2
|
module Extensions
|
3
3
|
module InstanceMethods
|
4
|
+
# Verifies all the Double objects have met their
|
5
|
+
# TimesCalledExpectations.
|
6
|
+
def verify
|
7
|
+
RR::Space.instance.verify_doubles
|
8
|
+
end
|
9
|
+
|
10
|
+
# Resets the registered Doubles and ordered Scenarios
|
11
|
+
def reset
|
12
|
+
RR::Space.instance.reset
|
13
|
+
end
|
14
|
+
|
4
15
|
# Sets up a MockCreator that generates a Double Scenario that
|
5
16
|
# acts like a mock.
|
6
17
|
# mock(object).method_name(arg1, arg2) {return_value}
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.
|
2
|
+
rubygems_version: 0.9.2
|
3
3
|
specification_version: 1
|
4
4
|
name: rr
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.2.
|
7
|
-
date: 2007-07-
|
6
|
+
version: 0.2.3
|
7
|
+
date: 2007-07-18 00:00:00 -07:00
|
8
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
9
|
require_paths:
|
10
10
|
- lib
|
@@ -29,106 +29,107 @@ post_install_message:
|
|
29
29
|
authors:
|
30
30
|
- Brian Takita
|
31
31
|
files:
|
32
|
+
- README
|
32
33
|
- Rakefile
|
33
34
|
- CHANGES
|
34
|
-
-
|
35
|
-
- lib/rr.rb
|
36
|
-
- lib/rr/
|
37
|
-
- lib/rr/scenario.rb
|
38
|
-
- lib/rr/creator.rb
|
39
|
-
- lib/rr/stub_probe_creator.rb
|
40
|
-
- lib/rr/scenario_matches.rb
|
41
|
-
- lib/rr/stub_creator.rb
|
42
|
-
- lib/rr/space.rb
|
43
|
-
- lib/rr/double.rb
|
44
|
-
- lib/rr/do_not_allow_creator.rb
|
45
|
-
- lib/rr/mock_creator.rb
|
46
|
-
- lib/rr/times_called_matchers/any_times_matcher.rb
|
47
|
-
- lib/rr/times_called_matchers/at_most_matcher.rb
|
48
|
-
- lib/rr/times_called_matchers/times_called_matcher.rb
|
49
|
-
- lib/rr/times_called_matchers/at_least_matcher.rb
|
50
|
-
- lib/rr/times_called_matchers/proc_matcher.rb
|
51
|
-
- lib/rr/times_called_matchers/integer_matcher.rb
|
52
|
-
- lib/rr/times_called_matchers/non_terminal.rb
|
53
|
-
- lib/rr/times_called_matchers/terminal.rb
|
54
|
-
- lib/rr/times_called_matchers/range_matcher.rb
|
35
|
+
- lib/rr/extensions/instance_methods.rb
|
36
|
+
- lib/rr/adapters/test_unit.rb
|
37
|
+
- lib/rr/adapters/rspec.rb
|
55
38
|
- lib/rr/expectations/argument_equality_expectation.rb
|
56
39
|
- lib/rr/expectations/times_called_expectation.rb
|
57
40
|
- lib/rr/expectations/any_argument_expectation.rb
|
41
|
+
- lib/rr/scenario.rb
|
42
|
+
- lib/rr/stub_creator.rb
|
43
|
+
- lib/rr/errors/times_called_error.rb
|
58
44
|
- lib/rr/errors/scenario_not_found_error.rb
|
59
|
-
- lib/rr/errors/argument_equality_error.rb
|
60
45
|
- lib/rr/errors/scenario_order_error.rb
|
46
|
+
- lib/rr/errors/argument_equality_error.rb
|
61
47
|
- lib/rr/errors/rr_error.rb
|
62
|
-
- lib/rr/
|
63
|
-
- lib/rr/
|
64
|
-
- lib/rr/
|
48
|
+
- lib/rr/do_not_allow_creator.rb
|
49
|
+
- lib/rr/mock_creator.rb
|
50
|
+
- lib/rr/double.rb
|
51
|
+
- lib/rr/space.rb
|
52
|
+
- lib/rr/creator.rb
|
65
53
|
- lib/rr/wildcard_matchers/boolean.rb
|
54
|
+
- lib/rr/wildcard_matchers/anything.rb
|
55
|
+
- lib/rr/wildcard_matchers/numeric.rb
|
66
56
|
- lib/rr/wildcard_matchers/duck_type.rb
|
67
|
-
- lib/rr/wildcard_matchers/range.rb
|
68
57
|
- lib/rr/wildcard_matchers/regexp.rb
|
69
|
-
- lib/rr/wildcard_matchers/numeric.rb
|
70
58
|
- lib/rr/wildcard_matchers/is_a.rb
|
71
|
-
- lib/rr/wildcard_matchers/
|
72
|
-
- lib/rr/
|
73
|
-
-
|
74
|
-
-
|
75
|
-
-
|
76
|
-
-
|
77
|
-
-
|
78
|
-
-
|
79
|
-
-
|
80
|
-
-
|
81
|
-
-
|
82
|
-
-
|
83
|
-
-
|
84
|
-
-
|
85
|
-
- examples/rr/
|
86
|
-
- examples/rr/
|
87
|
-
- examples/rr/
|
88
|
-
- examples/rr/
|
89
|
-
- examples/rr/
|
90
|
-
- examples/rr/times_called_matchers/times_called_matcher_example.rb
|
91
|
-
- examples/rr/times_called_matchers/range_matcher_example.rb
|
92
|
-
- examples/rr/times_called_matchers/proc_matcher_example.rb
|
93
|
-
- examples/rr/times_called_matchers/any_times_matcher_example.rb
|
94
|
-
- examples/rr/times_called_matchers/integer_matcher_example.rb
|
95
|
-
- examples/rr/space/space_verify_example.rb
|
96
|
-
- examples/rr/space/space_reset_example.rb
|
97
|
-
- examples/rr/space/space_create_example.rb
|
98
|
-
- examples/rr/space/space_helper.rb
|
99
|
-
- examples/rr/space/space_example.rb
|
100
|
-
- examples/rr/space/space_register_example.rb
|
101
|
-
- examples/rr/expectations/is_a_argument_equality_expectation_example.rb
|
102
|
-
- examples/rr/expectations/any_argument_expectation_example.rb
|
103
|
-
- examples/rr/expectations/regexp_argument_equality_expectation_example.rb
|
104
|
-
- examples/rr/expectations/boolean_argument_equality_expectation_example.rb
|
105
|
-
- examples/rr/expectations/duck_type_argument_equality_expectation_example.rb
|
106
|
-
- examples/rr/expectations/numeric_argument_equality_expectation_example.rb
|
107
|
-
- examples/rr/expectations/range_argument_equality_expectation_example.rb
|
59
|
+
- lib/rr/wildcard_matchers/range.rb
|
60
|
+
- lib/rr/times_called_matchers/at_least_matcher.rb
|
61
|
+
- lib/rr/times_called_matchers/range_matcher.rb
|
62
|
+
- lib/rr/times_called_matchers/integer_matcher.rb
|
63
|
+
- lib/rr/times_called_matchers/non_terminal.rb
|
64
|
+
- lib/rr/times_called_matchers/proc_matcher.rb
|
65
|
+
- lib/rr/times_called_matchers/times_called_matcher.rb
|
66
|
+
- lib/rr/times_called_matchers/at_most_matcher.rb
|
67
|
+
- lib/rr/times_called_matchers/any_times_matcher.rb
|
68
|
+
- lib/rr/times_called_matchers/terminal.rb
|
69
|
+
- lib/rr/stub_probe_creator.rb
|
70
|
+
- lib/rr/mock_probe_creator.rb
|
71
|
+
- lib/rr/scenario_matches.rb
|
72
|
+
- lib/rr.rb
|
73
|
+
- examples/rr/extensions/instance_methods_creator_example.rb
|
74
|
+
- examples/rr/extensions/instance_methods_example_helper.rb
|
75
|
+
- examples/rr/extensions/instance_methods_times_matcher_example.rb
|
76
|
+
- examples/rr/extensions/instance_methods_argument_matcher_example.rb
|
77
|
+
- examples/rr/extensions/instance_methods_space_example.rb
|
108
78
|
- examples/rr/expectations/argument_equality_expectation_example.rb
|
109
79
|
- examples/rr/expectations/anything_argument_equality_expectation_example.rb
|
80
|
+
- examples/rr/expectations/times_called_expectation/times_called_expectation_at_least_example.rb
|
81
|
+
- examples/rr/expectations/times_called_expectation/times_called_expectation_range_example.rb
|
110
82
|
- examples/rr/expectations/times_called_expectation/times_called_expectation_integer_example.rb
|
111
|
-
- examples/rr/expectations/times_called_expectation/times_called_expectation_any_times_example.rb
|
112
|
-
- examples/rr/expectations/times_called_expectation/times_called_expectation_helper.rb
|
113
|
-
- examples/rr/expectations/times_called_expectation/times_called_expectation_proc_example.rb
|
114
83
|
- examples/rr/expectations/times_called_expectation/times_called_expectation_example.rb
|
115
|
-
- examples/rr/expectations/times_called_expectation/
|
84
|
+
- examples/rr/expectations/times_called_expectation/times_called_expectation_proc_example.rb
|
85
|
+
- examples/rr/expectations/times_called_expectation/times_called_expectation_helper.rb
|
116
86
|
- examples/rr/expectations/times_called_expectation/times_called_expectation_at_most_example.rb
|
117
|
-
- examples/rr/expectations/times_called_expectation/
|
118
|
-
- examples/rr/
|
119
|
-
- examples/rr/
|
87
|
+
- examples/rr/expectations/times_called_expectation/times_called_expectation_any_times_example.rb
|
88
|
+
- examples/rr/expectations/any_argument_expectation_example.rb
|
89
|
+
- examples/rr/expectations/is_a_argument_equality_expectation_example.rb
|
90
|
+
- examples/rr/expectations/numeric_argument_equality_expectation_example.rb
|
91
|
+
- examples/rr/expectations/boolean_argument_equality_expectation_example.rb
|
92
|
+
- examples/rr/expectations/duck_type_argument_equality_expectation_example.rb
|
93
|
+
- examples/rr/expectations/regexp_argument_equality_expectation_example.rb
|
94
|
+
- examples/rr/expectations/range_argument_equality_expectation_example.rb
|
95
|
+
- examples/rr/rspec/rspec_adapter_example.rb
|
96
|
+
- examples/rr/rspec/rspec_usage_example.rb
|
97
|
+
- examples/rr/rspec/rspec_backtrace_tweaking_example.rb
|
98
|
+
- examples/rr/test_unit/test_helper.rb
|
99
|
+
- examples/rr/test_unit/test_unit_integration_test.rb
|
100
|
+
- examples/rr/test_unit/test_unit_backtrace_test.rb
|
101
|
+
- examples/rr/scenario_example.rb
|
120
102
|
- examples/rr/double/double_bind_example.rb
|
121
|
-
- examples/rr/double/double_register_scenario_example.rb
|
122
|
-
- examples/rr/double/double_example.rb
|
123
103
|
- examples/rr/double/double_dispatching_example.rb
|
104
|
+
- examples/rr/double/double_example.rb
|
105
|
+
- examples/rr/double/double_reset_example.rb
|
124
106
|
- examples/rr/double/double_verify_example.rb
|
125
|
-
- examples/rr/
|
126
|
-
- examples/rr/
|
127
|
-
- examples/rr/
|
128
|
-
- examples/rr/
|
129
|
-
- examples/rr/
|
130
|
-
- examples/rr/
|
131
|
-
- examples/rr/
|
107
|
+
- examples/rr/double/double_register_scenario_example.rb
|
108
|
+
- examples/rr/space/space_example.rb
|
109
|
+
- examples/rr/space/space_reset_example.rb
|
110
|
+
- examples/rr/space/space_create_example.rb
|
111
|
+
- examples/rr/space/space_helper.rb
|
112
|
+
- examples/rr/space/space_register_example.rb
|
113
|
+
- examples/rr/space/space_verify_example.rb
|
114
|
+
- examples/rr/mock_creator_example.rb
|
115
|
+
- examples/rr/times_called_matchers/proc_matcher_example.rb
|
116
|
+
- examples/rr/times_called_matchers/times_called_matcher_example.rb
|
117
|
+
- examples/rr/times_called_matchers/at_most_matcher_example.rb
|
118
|
+
- examples/rr/times_called_matchers/any_times_matcher_example.rb
|
119
|
+
- examples/rr/times_called_matchers/at_least_matcher_example.rb
|
120
|
+
- examples/rr/times_called_matchers/range_matcher_example.rb
|
121
|
+
- examples/rr/times_called_matchers/integer_matcher_example.rb
|
122
|
+
- examples/rr/stub_probe_creator_example.rb
|
123
|
+
- examples/rr/stub_creator_example.rb
|
124
|
+
- examples/rr/do_not_allow_creator_example.rb
|
125
|
+
- examples/rr/mock_probe_creator_example.rb
|
126
|
+
- examples/rr/errors/rr_error_example.rb
|
127
|
+
- examples/rspec_example_suite.rb
|
128
|
+
- examples/high_level_example.rb
|
129
|
+
- examples/test_unit_example_suite.rb
|
130
|
+
- examples/example_suite.rb
|
131
|
+
- examples/environment_fixture_setup.rb
|
132
|
+
- examples/example_helper.rb
|
132
133
|
test_files: []
|
133
134
|
|
134
135
|
rdoc_options:
|