rr 0.4.8 → 0.4.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/CHANGES +3 -0
  2. data/{README → README.rdoc} +14 -6
  3. data/Rakefile +2 -2
  4. data/lib/rr.rb +11 -3
  5. data/lib/rr/adapters/rr_methods.rb +12 -12
  6. data/lib/rr/adapters/rspec.rb +3 -3
  7. data/lib/rr/adapters/test_unit.rb +3 -3
  8. data/lib/rr/double.rb +12 -10
  9. data/lib/rr/double_creator.rb +48 -45
  10. data/lib/rr/double_definition.rb +17 -149
  11. data/lib/rr/double_definition_builder.rb +11 -11
  12. data/lib/rr/double_definition_creator.rb +156 -0
  13. data/lib/rr/{double_method_proxy.rb → double_definition_creator_proxy.rb} +2 -2
  14. data/lib/rr/double_injection.rb +6 -6
  15. data/lib/rr/double_matches.rb +40 -40
  16. data/lib/rr/errors/rr_error.rb +1 -1
  17. data/lib/rr/expectations/times_called_expectation.rb +1 -1
  18. data/lib/rr/space.rb +9 -30
  19. data/spec/high_level_spec.rb +140 -143
  20. data/spec/rr/adapters/rr_methods_creator_spec.rb +21 -21
  21. data/spec/rr/adapters/rr_methods_space_spec.rb +2 -2
  22. data/spec/rr/double/double_injection_dispatching_spec.rb +15 -15
  23. data/spec/rr/double/double_injection_reset_spec.rb +1 -1
  24. data/spec/rr/double/double_injection_verify_spec.rb +5 -4
  25. data/spec/rr/{double_method_proxy_spec.rb → double_definition_creator_proxy_spec.rb} +12 -10
  26. data/spec/rr/{double_creator_spec.rb → double_definition_creator_spec.rb} +166 -124
  27. data/spec/rr/double_definition_spec.rb +637 -642
  28. data/spec/rr/double_spec.rb +44 -43
  29. data/spec/rr/errors/rr_error_spec.rb +6 -6
  30. data/spec/rr/expectations/times_called_expectation/times_called_expectation_any_times_spec.rb +3 -3
  31. data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb +8 -8
  32. data/spec/rr/expectations/times_called_expectation/times_called_expectation_at_most_spec.rb +11 -13
  33. data/spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +2 -2
  34. data/spec/rr/expectations/times_called_expectation/times_called_expectation_integer_spec.rb +19 -19
  35. data/spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb +16 -16
  36. data/spec/rr/expectations/times_called_expectation/times_called_expectation_range_spec.rb +16 -16
  37. data/spec/rr/expectations/times_called_expectation/times_called_expectation_spec.rb +7 -11
  38. data/spec/rr/rspec/rspec_adapter_spec.rb +10 -10
  39. data/spec/rr/rspec/rspec_backtrace_tweaking_spec.rb +1 -1
  40. data/spec/rr/space/space_spec.rb +372 -18
  41. data/spec/rr/test_unit/test_unit_backtrace_test.rb +1 -1
  42. data/spec/rr/times_called_matchers/proc_matcher_spec.rb +3 -3
  43. data/spec/rr/times_called_matchers/times_called_matcher_spec.rb +3 -3
  44. data/spec/spec_helper.rb +14 -3
  45. data/spec/spec_suite.rb +2 -2
  46. metadata +47 -45
  47. data/spec/rr/double/double_injection_register_scenario_spec.rb +0 -24
  48. data/spec/rr/space/space_create_spec.rb +0 -268
  49. data/spec/rr/space/space_helper.rb +0 -7
  50. data/spec/rr/space/space_register_spec.rb +0 -32
  51. data/spec/rr/space/space_reset_spec.rb +0 -131
  52. data/spec/rr/space/space_verify_spec.rb +0 -181
@@ -12,7 +12,7 @@ class TestUnitBacktraceTest < Test::Unit::TestCase
12
12
  end
13
13
 
14
14
  def test_trim_backtrace_is_set
15
- assert RR::Space.trim_backtrace
15
+ assert RR.trim_backtrace
16
16
  end
17
17
 
18
18
  def test_backtrace_tweaking
@@ -5,7 +5,7 @@ module RR
5
5
  describe ProcMatcher do
6
6
  attr_reader :matcher, :times
7
7
  before do
8
- @times = proc {|other| other == 3}
8
+ @times = lambda {|other| other == 3}
9
9
  @matcher = ProcMatcher.new(times)
10
10
  end
11
11
 
@@ -18,12 +18,12 @@ module RR
18
18
  end
19
19
 
20
20
  describe "#matches?" do
21
- it "returns false when proc returns false" do
21
+ it "returns false when lambda returns false" do
22
22
  times.call(2).should be_false
23
23
  matcher.should_not be_matches(2)
24
24
  end
25
25
 
26
- it "returns true when proc returns true" do
26
+ it "returns true when lambda returns true" do
27
27
  times.call(3).should be_true
28
28
  matcher.should be_matches(3)
29
29
  end
@@ -40,14 +40,14 @@ module RR
40
40
 
41
41
  describe "when passed a ProcMatcher" do
42
42
  it "returns the passed in argument" do
43
- matcher = ProcMatcher.new(proc {|other| other == 5})
43
+ matcher = ProcMatcher.new(lambda {|other| other == 5})
44
44
  TimesCalledMatcher.create(matcher).should === matcher
45
45
  end
46
46
  end
47
47
 
48
48
  describe "when passed a Lambda" do
49
49
  it "returns ProcMatcher" do
50
- value = proc {|other| other == 5}
50
+ value = lambda {|other| other == 5}
51
51
  TimesCalledMatcher.create(value).should == ProcMatcher.new(value)
52
52
  end
53
53
  end
@@ -75,7 +75,7 @@ module RR
75
75
  describe "when passed an unsupported type" do
76
76
  it "raises an ArgumentError" do
77
77
  matcher = Object.new
78
- proc do
78
+ lambda do
79
79
  TimesCalledMatcher.create(matcher)
80
80
  end.should raise_error(ArgumentError, "There is no TimesCalledMatcher for #{matcher.inspect}.")
81
81
  end
@@ -1,9 +1,20 @@
1
1
  dir = File.dirname(__FILE__)
2
2
  require "#{dir}/environment_fixture_setup"
3
- require "spec/rr/space/space_helper"
4
- require "spec/rr/expectations/times_called_expectation/times_called_expectation_helper"
5
- require "spec/rr/adapters/rr_methods_spec_helper"
3
+ require "#{dir}/rr/expectations/times_called_expectation/times_called_expectation_helper"
4
+ require "#{dir}/rr/adapters/rr_methods_spec_helper"
6
5
 
7
6
  Spec::Runner.configure do |config|
8
7
  config.mock_with RR::Adapters::Rspec
9
8
  end
9
+
10
+ describe "Swapped Space", :shared => true do
11
+ before do
12
+ @original_space = RR::Space.instance
13
+ RR::Space.instance = RR::Space.new
14
+ @space = RR::Space.instance
15
+ end
16
+
17
+ after(:each) do
18
+ RR::Space.instance = @original_space
19
+ end
20
+ end
@@ -6,11 +6,11 @@ class ExampleSuite
6
6
  end
7
7
 
8
8
  def run_core_examples
9
- system("ruby #{dir}/core_spec_suite.rb") || raise("Core suite Failed")
9
+ system("ruby #{dir}/core_spec_suite.rb --options #{dir}/spec.opts") || raise("Core suite Failed")
10
10
  end
11
11
 
12
12
  def run_rspec_examples
13
- system("ruby #{dir}/rspec_spec_suite.rb") || raise("Rspec suite Failed")
13
+ system("ruby #{dir}/rspec_spec_suite.rb --options #{dir}/spec.opts") || raise("Rspec suite Failed")
14
14
  end
15
15
 
16
16
  def run_test_unit_examples
metadata CHANGED
@@ -1,37 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
4
2
  name: rr
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.4.8
7
- date: 2008-01-23 00:00:00 -08: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:
4
+ version: 0.4.9
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Brian Takita
8
+ autorequire: rr
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-06-18 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ 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
17
+ email: brian@pivotallabs.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ - CHANGES
31
25
  files:
32
26
  - Rakefile
33
27
  - CHANGES
34
- - README
28
+ - README.rdoc
35
29
  - lib/rr.rb
36
30
  - lib/rr/times_called_matchers/any_times_matcher.rb
37
31
  - lib/rr/times_called_matchers/at_most_matcher.rb
@@ -59,8 +53,8 @@ files:
59
53
  - lib/rr/adapters/test_unit.rb
60
54
  - lib/rr/adapters/rspec.rb
61
55
  - lib/rr/double_definition.rb
56
+ - lib/rr/double_definition_creator.rb
62
57
  - lib/rr/double_injection.rb
63
- - lib/rr/double_method_proxy.rb
64
58
  - lib/rr/space.rb
65
59
  - lib/rr/wildcard_matchers/boolean.rb
66
60
  - lib/rr/wildcard_matchers/duck_type.rb
@@ -69,6 +63,7 @@ files:
69
63
  - lib/rr/wildcard_matchers/numeric.rb
70
64
  - lib/rr/wildcard_matchers/is_a.rb
71
65
  - lib/rr/wildcard_matchers/anything.rb
66
+ - lib/rr/double_definition_creator_proxy.rb
72
67
  - lib/rr/double.rb
73
68
  - spec/environment_fixture_setup.rb
74
69
  - spec/spec_suite.rb
@@ -86,14 +81,8 @@ files:
86
81
  - spec/rr/times_called_matchers/at_least_matcher_spec.rb
87
82
  - spec/rr/times_called_matchers/at_most_matcher_spec.rb
88
83
  - spec/rr/times_called_matchers/integer_matcher_spec.rb
89
- - spec/rr/double_creator_spec.rb
90
- - spec/rr/space/space_create_spec.rb
91
84
  - spec/rr/space/hash_with_object_id_key_spec.rb
92
- - spec/rr/space/space_register_spec.rb
93
- - spec/rr/space/space_verify_spec.rb
94
- - spec/rr/space/space_reset_spec.rb
95
85
  - spec/rr/space/space_spec.rb
96
- - spec/rr/space/space_helper.rb
97
86
  - spec/rr/expectations/times_called_expectation/times_called_expectation_proc_spec.rb
98
87
  - spec/rr/expectations/times_called_expectation/times_called_expectation_helper.rb
99
88
  - spec/rr/expectations/times_called_expectation/times_called_expectation_at_least_spec.rb
@@ -125,34 +114,47 @@ files:
125
114
  - spec/rr/adapters/rr_methods_creator_spec.rb
126
115
  - spec/rr/adapters/rr_methods_argument_matcher_spec.rb
127
116
  - spec/rr/double_definition_spec.rb
128
- - spec/rr/double/double_injection_register_scenario_spec.rb
117
+ - spec/rr/double_definition_creator_proxy_spec.rb
118
+ - spec/rr/double_definition_creator_spec.rb
129
119
  - spec/rr/double/double_injection_has_original_method_spec.rb
130
120
  - spec/rr/double/double_injection_spec.rb
131
121
  - spec/rr/double/double_injection_bind_spec.rb
132
122
  - spec/rr/double/double_injection_dispatching_spec.rb
133
123
  - spec/rr/double/double_injection_verify_spec.rb
134
124
  - spec/rr/double/double_injection_reset_spec.rb
135
- - spec/rr/double_method_proxy_spec.rb
136
125
  - spec/rr/test_unit/test_unit_backtrace_test.rb
137
126
  - spec/rr/test_unit/test_helper.rb
138
127
  - spec/rr/test_unit/test_unit_integration_test.rb
139
128
  - spec/rspec_spec_suite.rb
140
129
  - spec/core_spec_suite.rb
141
- test_files:
142
- - spec/high_level_spec.rb
130
+ has_rdoc: true
131
+ homepage: http://pivotallabs.com
132
+ post_install_message:
143
133
  rdoc_options:
144
134
  - --main
145
135
  - README
146
136
  - --inline-source
147
137
  - --line-numbers
148
- extra_rdoc_files:
149
- - README
150
- - CHANGES
151
- executables: []
152
-
153
- extensions: []
154
-
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: "0"
145
+ version:
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: "0"
151
+ version:
155
152
  requirements: []
156
153
 
157
- dependencies: []
158
-
154
+ rubyforge_project: pivotalrb
155
+ rubygems_version: 1.1.0
156
+ signing_key:
157
+ specification_version: 2
158
+ 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
159
+ test_files:
160
+ - spec/high_level_spec.rb
@@ -1,24 +0,0 @@
1
- require "spec/spec_helper"
2
-
3
- module RR
4
- describe DoubleInjection, "#register_double" do
5
- before do
6
- @space = Space.new
7
- @object = Object.new
8
- @method_name = :foobar
9
- @object.methods.should_not include(@method_name.to_s)
10
- @double_injection = DoubleInjection.new(@object, @method_name)
11
- def @double_injection.doubles
12
- @doubles
13
- end
14
- end
15
-
16
- it "adds the double to the doubles list" do
17
- double = Double.new(@space, @double_injection, @space.double_definition)
18
-
19
- @double_injection.doubles.should_not include(double)
20
- @double_injection.register_double double
21
- @double_injection.doubles.should include(double)
22
- end
23
- end
24
- end
@@ -1,268 +0,0 @@
1
- require "spec/spec_helper"
2
-
3
- module RR
4
- describe Space, "#double_method_proxy", :shared => true do
5
- it_should_behave_like "RR::Space"
6
-
7
- before do
8
- @space = Space.new
9
- @object = Object.new
10
- end
11
-
12
- it "creates a DoubleMethodProxy" do
13
- proxy = @space.double_method_proxy(@creator, @object)
14
- proxy.should be_instance_of(DoubleMethodProxy)
15
- end
16
-
17
- it "sets creator to passed in creator" do
18
- proxy = @space.double_method_proxy(@creator, @object)
19
- class << proxy
20
- attr_reader :creator
21
- end
22
- proxy.creator.should === @creator
23
- end
24
-
25
- it "raises error if passed a method name and a block" do
26
- proc do
27
- @space.double_method_proxy(@creator, @object, :foobar) {}
28
- end.should raise_error(ArgumentError, "Cannot pass in a method name and a block")
29
- end
30
- end
31
-
32
- describe Space, "#double_method_proxy with a Mock strategy" do
33
- it_should_behave_like "RR::Space#double_method_proxy"
34
-
35
- before do
36
- @creator = @space.double_creator
37
- @creator.mock
38
- end
39
-
40
- it "creates a mock Double for method when passed a second argument" do
41
- @space.double_method_proxy(@creator, @object, :foobar).with(1) {:baz}
42
- @object.foobar(1).should == :baz
43
- proc {@object.foobar(1)}.should raise_error(Errors::TimesCalledError)
44
- end
45
-
46
- it "uses block definition when passed a block" do
47
- @space.double_method_proxy(@creator, @object) do |c|
48
- c.foobar(1) {:baz}
49
- end
50
- @object.foobar(1).should == :baz
51
- proc {@object.foobar(1)}.should raise_error(Errors::TimesCalledError)
52
- end
53
- end
54
-
55
- describe Space, "#double_method_proxy with a Stub strategy" do
56
- it_should_behave_like "RR::Space#double_method_proxy"
57
-
58
- before do
59
- @creator = @space.double_creator
60
- @creator.stub
61
- end
62
-
63
- it "creates a stub Double for method when passed a second argument" do
64
- @space.double_method_proxy(@creator, @object, :foobar).with(1) {:baz}
65
- @object.foobar(1).should == :baz
66
- @object.foobar(1).should == :baz
67
- end
68
-
69
- it "uses block definition when passed a block" do
70
- @space.double_method_proxy(@creator, @object) do |c|
71
- c.foobar(1) {:return_value}
72
- c.foobar.with_any_args {:default}
73
- c.baz(1) {:baz_value}
74
- end
75
- @object.foobar(1).should == :return_value
76
- @object.foobar.should == :default
77
- proc {@object.baz.should == :return_value}.should raise_error
78
- end
79
- end
80
-
81
- describe Space, "#double_method_proxy with a Mock Proxy strategy" do
82
- it_should_behave_like "RR::Space#double_method_proxy"
83
-
84
- before do
85
- @creator = @space.double_creator
86
- @creator.mock.proxy
87
- def @object.foobar(*args)
88
- :original_foobar
89
- end
90
- end
91
-
92
- it "creates a mock proxy Double for method when passed a second argument" do
93
- @space.double_method_proxy(@creator, @object, :foobar).with(1)
94
- @object.foobar(1).should == :original_foobar
95
- proc {@object.foobar(1)}.should raise_error(Errors::TimesCalledError)
96
- end
97
-
98
- it "uses block definition when passed a block" do
99
- @space.double_method_proxy(@creator, @object) do |c|
100
- c.foobar(1)
101
- end
102
- @object.foobar(1).should == :original_foobar
103
- proc {@object.foobar(1)}.should raise_error(Errors::TimesCalledError)
104
- end
105
- end
106
-
107
- describe Space, "#double_method_proxy with a Stub proxy strategy" do
108
- it_should_behave_like "RR::Space#double_method_proxy"
109
-
110
- before do
111
- @creator = @space.double_creator
112
- @creator.stub.proxy
113
- def @object.foobar(*args)
114
- :original_foobar
115
- end
116
- end
117
-
118
- it "creates a stub proxy Double for method when passed a second argument" do
119
- @space.double_method_proxy(@creator, @object, :foobar)
120
- @object.foobar(1).should == :original_foobar
121
- @object.foobar(1).should == :original_foobar
122
- end
123
-
124
- it "uses block definition when passed a block" do
125
- @space.double_method_proxy(@creator, @object) do |c|
126
- c.foobar(1)
127
- end
128
- @object.foobar(1).should == :original_foobar
129
- @object.foobar(1).should == :original_foobar
130
- end
131
- end
132
-
133
- describe Space, "#double_method_proxy with a Do Not Allow strategy" do
134
- it_should_behave_like "RR::Space#double_method_proxy"
135
-
136
- before do
137
- @creator = @space.double_creator
138
- @creator.dont_allow
139
- end
140
-
141
- it "creates a do not allow Double for method when passed a second argument" do
142
- @space.double_method_proxy(@creator, @object, :foobar).with(1)
143
- proc {@object.foobar(1)}.should raise_error(Errors::TimesCalledError)
144
- end
145
-
146
- it "uses block definition when passed a block" do
147
- @space.double_method_proxy(@creator, @object) do |c|
148
- c.foobar(1)
149
- end
150
- proc {@object.foobar(1)}.should raise_error(Errors::TimesCalledError)
151
- end
152
- end
153
-
154
- describe Space, "#double_creator" do
155
- it_should_behave_like "RR::Space"
156
-
157
- before do
158
- @space = Space.new
159
- @object = Object.new
160
- @creator = @space.double_creator
161
- end
162
-
163
- it "sets the space" do
164
- @creator.space.should === @space
165
- end
166
-
167
- it "creates a DoubleCreator" do
168
- @creator.should be_instance_of(DoubleCreator)
169
- end
170
- end
171
-
172
- describe Space, "#double" do
173
- it_should_behave_like "RR::Space"
174
-
175
- before do
176
- @space = Space.new
177
- @object = Object.new
178
- @method_name = :foobar
179
- end
180
-
181
- it "creates a Double and registers it to the double_injection" do
182
- double_injection = @space.double_injection(@object, @method_name)
183
- def double_injection.doubles
184
- @doubles
185
- end
186
-
187
- double = @space.double(double_injection)
188
- double_injection.doubles.should include(double)
189
- end
190
- end
191
-
192
- describe Space, "#double_injection" do
193
- it_should_behave_like "RR::Space"
194
-
195
- before do
196
- @space = Space.new
197
- end
198
-
199
- it "creates a new double_injection when existing object == but not === with the same method name" do
200
- object1 = []
201
- object2 = []
202
- (object1 === object2).should be_true
203
- object1.__id__.should_not == object2.__id__
204
-
205
- double1 = @space.double_injection(object1, :foobar)
206
- double2 = @space.double_injection(object2, :foobar)
207
-
208
- double1.should_not == double2
209
- end
210
- end
211
-
212
- describe Space, "#double_injection when double_injection does not exist" do
213
- it_should_behave_like "RR::Space"
214
-
215
- before do
216
- @space = Space.new
217
- @object = Object.new
218
- def @object.foobar(*args)
219
- :original_foobar
220
- end
221
- @method_name = :foobar
222
- end
223
-
224
- it "returns double_injection and adds double_injection to double_injection list when method_name is a symbol" do
225
- double_injection = @space.double_injection(@object, @method_name)
226
- @space.double_injection(@object, @method_name).should === double_injection
227
- double_injection.object.should === @object
228
- double_injection.method_name.should === @method_name
229
- end
230
-
231
- it "returns double_injection and adds double_injection to double_injection list when method_name is a string" do
232
- double_injection = @space.double_injection(@object, 'foobar')
233
- @space.double_injection(@object, @method_name).should === double_injection
234
- double_injection.object.should === @object
235
- double_injection.method_name.should === @method_name
236
- end
237
-
238
- it "overrides the method when passing a block" do
239
- double_injection = @space.double_injection(@object, @method_name)
240
- @object.methods.should include("__rr__#{@method_name}")
241
- end
242
- end
243
-
244
- describe Space, "#double_injection when double_injection exists" do
245
- it_should_behave_like "RR::Space"
246
-
247
- before do
248
- @space = Space.new
249
- @object = Object.new
250
- def @object.foobar(*args)
251
- :original_foobar
252
- end
253
- @method_name = :foobar
254
- end
255
-
256
- it "returns the existing double_injection" do
257
- original_foobar_method = @object.method(:foobar)
258
- double_injection = @space.double_injection(@object, 'foobar')
259
-
260
- double_injection.object_has_original_method?.should be_true
261
-
262
- @space.double_injection(@object, 'foobar').should === double_injection
263
-
264
- double_injection.reset
265
- @object.foobar.should == :original_foobar
266
- end
267
- end
268
- end