rr 0.1.8 → 0.1.9

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 CHANGED
@@ -1,3 +1,7 @@
1
+ * 0.1.9
2
+ - Added DoubleMethods#any_times
3
+ - Added Scenario#any_number_of_times
4
+
1
5
  * 0.1.8
2
6
  - TimesCalledError Message Formatted to be on multiple lines
3
7
  - ScenarioNotFoundError Message includes all Scenarios for the Double
data/Rakefile CHANGED
@@ -21,7 +21,7 @@ def run_suite
21
21
  end
22
22
 
23
23
  PKG_NAME = "rr"
24
- PKG_VERSION = "0.1.8"
24
+ PKG_VERSION = "0.1.9"
25
25
  PKG_FILES = FileList[
26
26
  '[A-Z]*',
27
27
  '*.rb',
@@ -2,6 +2,7 @@ dir = File.dirname(__FILE__)
2
2
  require "#{dir}/environment_fixture_setup"
3
3
  require "examples/rr/space_helper"
4
4
  require "examples/rr/expectations/times_called_expectation/times_called_expectation_helper"
5
+ require "examples/rr/extensions/double_methods_example_helper"
5
6
 
6
7
  require "rr/adapters/rspec"
7
8
  Spec::Runner.configure do |config|
@@ -2,7 +2,7 @@ require "examples/example_helper"
2
2
 
3
3
  module RR
4
4
  module Expectations
5
- describe ArgumentEqualityExpectation, "#exact_match? with is_a argument" do
5
+ describe ArgumentEqualityExpectation, "#exact_match? with numeric argument" do
6
6
  before do
7
7
  @expectation = ArgumentEqualityExpectation.new(numeric)
8
8
  end
@@ -20,7 +20,7 @@ module Expectations
20
20
  end
21
21
  end
22
22
 
23
- describe ArgumentEqualityExpectation, "#wildcard_match? with is_a Numeric argument" do
23
+ describe ArgumentEqualityExpectation, "#wildcard_match? with Numeric argument" do
24
24
  before do
25
25
  @expectation = ArgumentEqualityExpectation.new(numeric)
26
26
  end
@@ -0,0 +1,42 @@
1
+ require "examples/example_helper"
2
+
3
+ module RR
4
+ module Expectations
5
+ describe TimesCalledExpectation, ' with AnyTimesMatcher', :shared => true do
6
+ it_should_behave_like "RR::Expectations::TimesCalledExpectation"
7
+
8
+ before do
9
+ @at_least = TimesCalledMatchers::AnyTimesMatcher.new
10
+ @expectation = TimesCalledExpectation.new(@at_least)
11
+ end
12
+ end
13
+
14
+ describe TimesCalledExpectation, "#verify! with AnyTimesMatcher" do
15
+ it_should_behave_like "RR::Expectations::TimesCalledExpectation with AnyTimesMatcher"
16
+
17
+ it "always passes" do
18
+ @expectation.verify!
19
+ 10.times {@expectation.attempt!}
20
+ @expectation.verify!
21
+ end
22
+ end
23
+
24
+ describe TimesCalledExpectation, "#attempt? with AnyTimesMatcher" do
25
+ it_should_behave_like "RR::Expectations::TimesCalledExpectation with AnyTimesMatcher"
26
+
27
+ it "always returns true" do
28
+ @expectation.should be_attempt
29
+ 10.times {@expectation.attempt!}
30
+ @expectation.should be_attempt
31
+ end
32
+ end
33
+
34
+ describe TimesCalledExpectation, "#attempt! with AnyTimesMatcher" do
35
+ it_should_behave_like "RR::Expectations::TimesCalledExpectation with AnyTimesMatcher"
36
+
37
+ it "always passes" do
38
+ 10.times {@expectation.attempt!}
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,65 @@
1
+ require "examples/example_helper"
2
+
3
+ module RR
4
+ module Extensions
5
+ describe DoubleMethods, "#anything" do
6
+ it_should_behave_like "RR::Extensions::DoubleMethods"
7
+
8
+ it "returns an Anything matcher" do
9
+ anything.should == WildcardMatchers::Anything.new
10
+ end
11
+
12
+ it "rr_anything returns an Anything matcher" do
13
+ rr_anything.should == WildcardMatchers::Anything.new
14
+ end
15
+ end
16
+
17
+ describe DoubleMethods, "#is_a" do
18
+ it_should_behave_like "RR::Extensions::DoubleMethods"
19
+
20
+ it "returns an IsA matcher" do
21
+ is_a(Integer).should == WildcardMatchers::IsA.new(Integer)
22
+ end
23
+
24
+ it "rr_is_a returns an IsA matcher" do
25
+ rr_is_a(Integer).should == WildcardMatchers::IsA.new(Integer)
26
+ end
27
+ end
28
+
29
+ describe DoubleMethods, "#numeric" do
30
+ it_should_behave_like "RR::Extensions::DoubleMethods"
31
+
32
+ it "returns an Numeric matcher" do
33
+ numeric.should == WildcardMatchers::Numeric.new
34
+ end
35
+
36
+ it "rr_numeric returns an Numeric matcher" do
37
+ rr_numeric.should == WildcardMatchers::Numeric.new
38
+ end
39
+ end
40
+
41
+ describe DoubleMethods, "#boolean" do
42
+ it_should_behave_like "RR::Extensions::DoubleMethods"
43
+
44
+ it "returns an Boolean matcher" do
45
+ boolean.should == WildcardMatchers::Boolean.new
46
+ end
47
+
48
+ it "rr_boolean returns an Boolean matcher" do
49
+ rr_boolean.should == WildcardMatchers::Boolean.new
50
+ end
51
+ end
52
+
53
+ describe DoubleMethods, "#duck_type" do
54
+ it_should_behave_like "RR::Extensions::DoubleMethods"
55
+
56
+ it "returns a DuckType matcher" do
57
+ duck_type(:one, :two).should == WildcardMatchers::DuckType.new(:one, :two)
58
+ end
59
+
60
+ it "rr_duck_type returns a DuckType matcher" do
61
+ rr_duck_type(:one, :two).should == WildcardMatchers::DuckType.new(:one, :two)
62
+ end
63
+ end
64
+ end
65
+ end
@@ -3,8 +3,9 @@ require "examples/example_helper"
3
3
  module RR
4
4
  module Extensions
5
5
  describe DoubleMethods, "#mock" do
6
+ it_should_behave_like "RR::Extensions::DoubleMethods"
7
+
6
8
  before do
7
- extend RR::Extensions::DoubleMethods
8
9
  @subject = Object.new
9
10
  end
10
11
 
@@ -24,7 +25,7 @@ module Extensions
24
25
  end
25
26
 
26
27
  scenario = creator.foobar(1, 2) {:baz}
27
- scenario.times_called_expectation.matcher.should == TimesCalledMatchers::IntegerMatcher.new(1)
28
+ scenario.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(1)
28
29
  scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
29
30
  scenario.argument_expectation.expected_arguments.should == [1, 2]
30
31
 
@@ -33,8 +34,9 @@ module Extensions
33
34
  end
34
35
 
35
36
  describe DoubleMethods, "#stub" do
37
+ it_should_behave_like "RR::Extensions::DoubleMethods"
38
+
36
39
  before do
37
- extend RR::Extensions::DoubleMethods
38
40
  @subject = Object.new
39
41
  end
40
42
 
@@ -54,24 +56,25 @@ module Extensions
54
56
  end
55
57
 
56
58
  scenario = creator.foobar(1, 2) {:baz}
57
- scenario.times_called_expectation.should == nil
59
+ scenario.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
58
60
  scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
59
61
  @subject.foobar(1, 2).should == :baz
60
62
  end
61
63
  end
62
64
 
63
65
  describe DoubleMethods, "#probe" do
66
+ it_should_behave_like "RR::Extensions::DoubleMethods"
67
+
64
68
  before do
65
- extend RR::Extensions::DoubleMethods
66
69
  @subject = Object.new
67
70
  end
68
71
 
69
72
  it "sets up the RR probe call chain" do
70
- creator = probe(@subject)
73
+ should_create_probe_call_chain probe(@subject)
71
74
  end
72
75
 
73
76
  it "sets up the RR probe call chain with rr_probe" do
74
- creator = rr_probe(@subject)
77
+ should_create_probe_call_chain rr_probe(@subject)
75
78
  end
76
79
 
77
80
  def should_create_probe_call_chain(creator)
@@ -82,7 +85,7 @@ module Extensions
82
85
  end
83
86
 
84
87
  scenario = creator.foobar(1, 2)
85
- scenario.times_called_expectation.times.should == 1
88
+ scenario.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(1)
86
89
  scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
87
90
  scenario.argument_expectation.expected_arguments.should == [1, 2]
88
91
 
@@ -91,8 +94,9 @@ module Extensions
91
94
  end
92
95
 
93
96
  describe DoubleMethods, "#do_not_allow" do
97
+ it_should_behave_like "RR::Extensions::DoubleMethods"
98
+
94
99
  before do
95
- extend RR::Extensions::DoubleMethods
96
100
  @subject = Object.new
97
101
  end
98
102
 
@@ -120,7 +124,7 @@ module Extensions
120
124
  end
121
125
 
122
126
  scenario = creator.foobar(1, 2)
123
- scenario.times_called_expectation.matcher.should == TimesCalledMatchers::IntegerMatcher.new(0)
127
+ scenario.times_matcher.should == TimesCalledMatchers::IntegerMatcher.new(0)
124
128
  scenario.argument_expectation.class.should == RR::Expectations::ArgumentEqualityExpectation
125
129
  scenario.argument_expectation.expected_arguments.should == [1, 2]
126
130
  end
@@ -0,0 +1,11 @@
1
+ require "examples/example_helper"
2
+
3
+ module RR
4
+ module Extensions
5
+ describe DoubleMethods, :shared => true do
6
+ before do
7
+ extend RR::Extensions::DoubleMethods
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ require "examples/example_helper"
2
+
3
+ module RR
4
+ module Extensions
5
+ describe DoubleMethods, "#any_times" do
6
+ it_should_behave_like "RR::Extensions::DoubleMethods"
7
+
8
+ it "returns an AnyTimesMatcher" do
9
+ any_times.should == TimesCalledMatchers::AnyTimesMatcher.new
10
+ end
11
+
12
+ it "rr_any_times returns an AnyTimesMatcher" do
13
+ rr_any_times.should == TimesCalledMatchers::AnyTimesMatcher.new
14
+ end
15
+ end
16
+ end
17
+ end
@@ -180,6 +180,24 @@ describe Scenario, "#times" do
180
180
  end
181
181
  end
182
182
 
183
+ describe Scenario, "#any_number_of_times" do
184
+ it_should_behave_like "RR::Scenario"
185
+
186
+ it "returns self" do
187
+ @scenario.any_number_of_times.should === @scenario
188
+ end
189
+
190
+ it "sets up a Times Called Expectation with AnyTimes matcher" do
191
+ @scenario.any_number_of_times
192
+ @scenario.times_matcher.should == TimesCalledMatchers::AnyTimesMatcher.new
193
+ end
194
+
195
+ it "sets return value when block passed in" do
196
+ @scenario.with_any_args.any_number_of_times {:return_value}
197
+ @object.foobar.should == :return_value
198
+ end
199
+ end
200
+
183
201
  describe Scenario, "#ordered" do
184
202
  it_should_behave_like "RR::Scenario"
185
203
 
@@ -4,15 +4,14 @@ module RR
4
4
  module TimesCalledMatchers
5
5
  describe TimesCalledMatcher, ".create when passed a AnyTimesMatcher" do
6
6
  it "returns the passed in argument" do
7
- matcher = AnyTimesMatcher.new(5)
7
+ matcher = AnyTimesMatcher.new
8
8
  TimesCalledMatcher.create(matcher).should === matcher
9
9
  end
10
10
  end
11
11
 
12
12
  describe AnyTimesMatcher, "#possible_match?" do
13
13
  before do
14
- @times = 3
15
- @matcher = AnyTimesMatcher.new(@times)
14
+ @matcher = AnyTimesMatcher.new
16
15
  end
17
16
 
18
17
  it "always returns true" do
@@ -23,8 +22,7 @@ module TimesCalledMatchers
23
22
 
24
23
  describe AnyTimesMatcher, "#matches?" do
25
24
  before do
26
- @times = 3
27
- @matcher = AnyTimesMatcher.new(@times)
25
+ @matcher = AnyTimesMatcher.new
28
26
  end
29
27
 
30
28
  it "always returns true" do
@@ -35,8 +33,7 @@ module TimesCalledMatchers
35
33
 
36
34
  describe AnyTimesMatcher, "#attempt?" do
37
35
  before do
38
- @times = 3
39
- @matcher = AnyTimesMatcher.new(@times)
36
+ @matcher = AnyTimesMatcher.new
40
37
  end
41
38
 
42
39
  it "always returns true" do
@@ -47,8 +44,7 @@ module TimesCalledMatchers
47
44
 
48
45
  describe AnyTimesMatcher, "#error_message" do
49
46
  before do
50
- @times = 3
51
- @matcher = AnyTimesMatcher.new(@times)
47
+ @matcher = AnyTimesMatcher.new
52
48
  end
53
49
 
54
50
  it "has an error message" do
@@ -30,6 +30,14 @@ module Extensions
30
30
  end
31
31
  alias_method :dont_allow, :do_not_allow
32
32
 
33
+ # Returns a AnyTimesMatcher. This is meant to be passed in as an argument
34
+ # to Scenario#times.
35
+ #
36
+ # mock(object).method_name(anything).times(any_times) {return_value}
37
+ def any_times
38
+ TimesCalledMatchers::AnyTimesMatcher.new
39
+ end
40
+
33
41
  # Sets up an Anything wildcard ArgumentEqualityExpectation
34
42
  # that succeeds when passed any argument.
35
43
  # mock(object).method_name(anything) {return_value}
@@ -65,7 +65,8 @@ module RR
65
65
  self
66
66
  end
67
67
 
68
- # Scenario#never creates an TimesCalledExpectation of 0.
68
+ # Scenario#never sets an expectation that the Scenario will never be
69
+ # called.
69
70
  #
70
71
  # This method does not accept a block because it will never be called.
71
72
  #
@@ -75,7 +76,8 @@ module RR
75
76
  self
76
77
  end
77
78
 
78
- # Scenario#once creates an TimesCalledExpectation of 1.
79
+ # Scenario#once sets an expectation that the Scenario will be called
80
+ # 1 time.
79
81
  #
80
82
  # Passing in a block sets the return value.
81
83
  #
@@ -86,7 +88,8 @@ module RR
86
88
  self
87
89
  end
88
90
 
89
- # Scenario#twice creates an TimesCalledExpectation of 2.
91
+ # Scenario#twice sets an expectation that the Scenario will be called
92
+ # 2 times.
90
93
  #
91
94
  # Passing in a block sets the return value.
92
95
  #
@@ -97,7 +100,7 @@ module RR
97
100
  self
98
101
  end
99
102
 
100
- # Scenario#at_least allows you to set an expectation that the Scenario
103
+ # Scenario#at_least sets an expectation that the Scenario
101
104
  # will be called at least n times.
102
105
  # It works by creating a TimesCalledExpectation.
103
106
  #
@@ -111,7 +114,7 @@ module RR
111
114
  self
112
115
  end
113
116
 
114
- # Scenario#at_most allows you to set an expectation that the Scenario
117
+ # Scenario#at_most allows sets an expectation that the Scenario
115
118
  # will be called at most n times.
116
119
  # It works by creating a TimesCalledExpectation.
117
120
  #
@@ -125,6 +128,19 @@ module RR
125
128
  self
126
129
  end
127
130
 
131
+ # Scenario#any_number_of_times sets an that the Scenario will be called
132
+ # any number of times. This effectively removes the times called expectation
133
+ # from the Scenarion
134
+ #
135
+ # Passing in a block sets the return value.
136
+ #
137
+ # mock(subject).method_name.any_number_of_times
138
+ def any_number_of_times(&returns)
139
+ @times_called_expectation = Expectations::TimesCalledExpectation.new(TimesCalledMatchers::AnyTimesMatcher.new)
140
+ returns(&returns) if returns
141
+ self
142
+ end
143
+
128
144
  # Scenario#times creates an TimesCalledExpectation of the passed
129
145
  # in number.
130
146
  #
@@ -286,10 +302,15 @@ module RR
286
302
  double.method_name
287
303
  end
288
304
 
289
- # The Argumentns that this Scenario expects
305
+ # The Arguments that this Scenario expects
290
306
  def expected_arguments
291
307
  return [] unless argument_expectation
292
308
  argument_expectation.expected_arguments
293
309
  end
310
+
311
+ # The TimesCalledMatcher for the TimesCalledExpectation
312
+ def times_matcher
313
+ times_called_expectation.matcher
314
+ end
294
315
  end
295
316
  end
@@ -25,7 +25,7 @@ module RR
25
25
  def method_missing(method_name, *args, &returns)
26
26
  double = @space.create_double(@subject, method_name)
27
27
  scenario = @space.create_scenario(double)
28
- scenario.returns(&returns)
28
+ scenario.returns(&returns).any_number_of_times
29
29
  if args.empty?
30
30
  scenario.with_any_args
31
31
  else
@@ -1,6 +1,9 @@
1
1
  module RR
2
2
  module TimesCalledMatchers
3
3
  class AnyTimesMatcher < TimesCalledMatcher
4
+ def initialize
5
+ end
6
+
4
7
  def possible_match?(times_called)
5
8
  true
6
9
  end
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.3
3
3
  specification_version: 1
4
4
  name: rr
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.8
6
+ version: 0.1.9
7
7
  date: 2007-07-14 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:
@@ -102,15 +102,16 @@ files:
102
102
  - examples/rr/expectations/any_argument_expectation_example.rb
103
103
  - examples/rr/expectations/regexp_argument_equality_expectation_example.rb
104
104
  - examples/rr/expectations/boolean_argument_equality_expectation_example.rb
105
- - examples/rr/expectations/times_called_expectation_example.rb
106
105
  - examples/rr/expectations/duck_type_argument_equality_expectation_example.rb
107
106
  - examples/rr/expectations/numeric_argument_equality_expectation_example.rb
108
107
  - examples/rr/expectations/range_argument_equality_expectation_example.rb
109
108
  - examples/rr/expectations/argument_equality_expectation_example.rb
110
109
  - examples/rr/expectations/anything_argument_equality_expectation_example.rb
111
110
  - 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
112
  - examples/rr/expectations/times_called_expectation/times_called_expectation_helper.rb
113
113
  - examples/rr/expectations/times_called_expectation/times_called_expectation_proc_example.rb
114
+ - examples/rr/expectations/times_called_expectation/times_called_expectation_example.rb
114
115
  - examples/rr/expectations/times_called_expectation/times_called_expectation_at_least_example.rb
115
116
  - examples/rr/expectations/times_called_expectation/times_called_expectation_at_most_example.rb
116
117
  - examples/rr/expectations/times_called_expectation/times_called_expectation_range_example.rb
@@ -118,7 +119,10 @@ files:
118
119
  - examples/rr/test_unit/test_unit_backtrace_test.rb
119
120
  - examples/rr/test_unit/test_helper.rb
120
121
  - examples/rr/test_unit/test_unit_integration_test.rb
121
- - examples/rr/extensions/double_methods_example.rb
122
+ - examples/rr/extensions/double_methods_creator_example.rb
123
+ - examples/rr/extensions/double_methods_argument_matcher_example.rb
124
+ - examples/rr/extensions/double_methods_example_helper.rb
125
+ - examples/rr/extensions/double_methods_times_matcher_example.rb
122
126
  test_files: []
123
127
 
124
128
  rdoc_options: