rr 0.3.7 → 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,6 @@
1
+ * 0.3.8
2
+ - Implemented [#13009] Better error mesage from TimesCalledMatcher
3
+
1
4
  * 0.3.7
2
5
  - Fixed [#12928] Reset doubles fails on Rails association proxies
3
6
 
data/Rakefile CHANGED
@@ -25,7 +25,7 @@ def run_suite
25
25
  end
26
26
 
27
27
  PKG_NAME = "rr"
28
- PKG_VERSION = "0.3.7"
28
+ PKG_VERSION = "0.3.8"
29
29
  PKG_FILES = FileList[
30
30
  '[A-Z]*',
31
31
  '*.rb',
@@ -7,7 +7,7 @@ module Expectations
7
7
 
8
8
  before do
9
9
  @at_least = TimesCalledMatchers::AnyTimesMatcher.new
10
- @expectation = TimesCalledExpectation.new(@at_least)
10
+ @expectation = TimesCalledExpectation.new(@scenario, @at_least)
11
11
  end
12
12
  end
13
13
 
@@ -8,7 +8,7 @@ module Expectations
8
8
  before do
9
9
  @times = 3
10
10
  @at_least = TimesCalledMatchers::AtLeastMatcher.new(@times)
11
- @expectation = TimesCalledExpectation.new(@at_least)
11
+ @expectation = TimesCalledExpectation.new(@scenario, @at_least)
12
12
  end
13
13
  end
14
14
 
@@ -31,7 +31,7 @@ module Expectations
31
31
  @expectation.verify!
32
32
  end.should raise_error(
33
33
  RR::Errors::TimesCalledError,
34
- "Called 1 time.\nExpected at least 3 times."
34
+ "foobar()\nCalled 1 time.\nExpected at least 3 times."
35
35
  )
36
36
  end
37
37
  end
@@ -8,7 +8,7 @@ module Expectations
8
8
  before do
9
9
  @times = 3
10
10
  @at_most = TimesCalledMatchers::AtMostMatcher.new(@times)
11
- @expectation = TimesCalledExpectation.new(@at_most)
11
+ @expectation = TimesCalledExpectation.new(@scenario, @at_most)
12
12
  end
13
13
  end
14
14
 
@@ -54,7 +54,7 @@ module Expectations
54
54
  3.times {@expectation.attempt!}
55
55
  proc do
56
56
  @expectation.attempt!
57
- end.should raise_error(Errors::TimesCalledError, "Called 4 times.\nExpected at most 3 times.")
57
+ end.should raise_error(Errors::TimesCalledError, "foobar()\nCalled 4 times.\nExpected at most 3 times.")
58
58
  end
59
59
 
60
60
  it "passes when times called == times" do
@@ -2,7 +2,51 @@ require "examples/example_helper"
2
2
 
3
3
  module RR
4
4
  module Expectations
5
- describe TimesCalledExpectation, ".new" do
5
+ describe TimesCalledExpectation, :shared => true do
6
+ before do
7
+ @space = Space.new
8
+ @object = Object.new
9
+ @double = @space.double(@object, :foobar)
10
+ @scenario = @space.scenario(@double)
11
+ @scenario.with(1, 2)
12
+ end
13
+ end
14
+
15
+ describe TimesCalledExpectation, " with failure", :shared => true do
16
+ it_should_behave_like "RR::Expectations::TimesCalledExpectation"
17
+
18
+ before do
19
+ @times = 0
20
+ @matcher = TimesCalledMatchers::IntegerMatcher.new(@times)
21
+ @expectation = TimesCalledExpectation.new(@scenario, @matcher)
22
+ end
23
+ end
24
+
25
+ describe TimesCalledExpectation, "#attempt! with failure" do
26
+ it_should_behave_like "RR::Expectations::TimesCalledExpectation with failure"
27
+
28
+ it "raises error that includes the scenario" do
29
+ proc do
30
+ @expectation.attempt!
31
+ end.should raise_error(
32
+ Errors::TimesCalledError,
33
+ "#{@scenario.formatted_name}\n#{@matcher.error_message(1)}"
34
+ )
35
+ end
36
+ end
37
+
38
+ describe TimesCalledExpectation, "#verify! with failure" do
39
+ it_should_behave_like "RR::Expectations::TimesCalledExpectation with failure"
40
+
41
+ it "raises error with passed in message prepended" do
42
+ @expectation.instance_variable_set(:@times_called, 1)
43
+ proc do
44
+ @expectation.verify!
45
+ end.should raise_error(
46
+ Errors::TimesCalledError,
47
+ "#{@scenario.formatted_name}\n#{@matcher.error_message(1)}"
48
+ )
49
+ end
6
50
  end
7
51
  end
8
52
  end
@@ -7,7 +7,7 @@ module Expectations
7
7
 
8
8
  before do
9
9
  @matcher = TimesCalledMatchers::IntegerMatcher.new(2)
10
- @expectation = TimesCalledExpectation.new(@matcher)
10
+ @expectation = TimesCalledExpectation.new(@scenario, @matcher)
11
11
  @expected_line = __LINE__ - 1
12
12
  end
13
13
  end
@@ -37,7 +37,7 @@ module Expectations
37
37
  @expectation.attempt!
38
38
  proc {@expectation.verify!}.should raise_error(
39
39
  Errors::TimesCalledError,
40
- "Called 1 time.\nExpected 2 times."
40
+ "foobar()\nCalled 1 time.\nExpected 2 times."
41
41
  )
42
42
  end
43
43
 
@@ -46,7 +46,7 @@ module Expectations
46
46
  @expectation.attempt!
47
47
  proc do
48
48
  @expectation.attempt!
49
- end.should raise_error(Errors::TimesCalledError, "Called 3 times.\nExpected 2 times.")
49
+ end.should raise_error(Errors::TimesCalledError, "foobar()\nCalled 3 times.\nExpected 2 times.")
50
50
  end
51
51
 
52
52
  it "has a backtrace to where the TimesCalledExpectation was instantiated on failure" do
@@ -63,7 +63,7 @@ module Expectations
63
63
  it "has an error message that includes the number of times called and expected number of times" do
64
64
  proc do
65
65
  @expectation.verify!
66
- end.should raise_error(Errors::TimesCalledError, "Called 0 times.\nExpected 2 times.")
66
+ end.should raise_error(Errors::TimesCalledError, "foobar()\nCalled 0 times.\nExpected 2 times.")
67
67
  end
68
68
  end
69
69
 
@@ -7,7 +7,7 @@ module Expectations
7
7
 
8
8
  before do
9
9
  @matcher = TimesCalledMatchers::ProcMatcher.new(proc {|value| value == 2})
10
- @expectation = TimesCalledExpectation.new(@matcher)
10
+ @expectation = TimesCalledExpectation.new(@scenario, @matcher)
11
11
  @expected_line = __LINE__ - 1
12
12
  end
13
13
  end
@@ -7,7 +7,7 @@ module Expectations
7
7
 
8
8
  before do
9
9
  @matcher = TimesCalledMatchers::RangeMatcher.new(1..2)
10
- @expectation = TimesCalledExpectation.new(@matcher)
10
+ @expectation = TimesCalledExpectation.new(@scenario, @matcher)
11
11
  @expected_line = __LINE__ - 1
12
12
  end
13
13
  end
@@ -43,7 +43,7 @@ module Expectations
43
43
  @expectation.attempt!
44
44
  proc do
45
45
  @expectation.attempt!
46
- end.should raise_error(Errors::TimesCalledError, "Called 3 times.\nExpected 1..2 times.")
46
+ end.should raise_error(Errors::TimesCalledError, "foobar()\nCalled 3 times.\nExpected 1..2 times.")
47
47
  end
48
48
  end
49
49
 
@@ -165,7 +165,7 @@ describe ScenarioDefinition, "#at_most" do
165
165
  @object.foobar
166
166
  end.should raise_error(
167
167
  Errors::TimesCalledError,
168
- "Called 3 times.\nExpected at most 2 times."
168
+ "foobar()\nCalled 3 times.\nExpected at most 2 times."
169
169
  )
170
170
  end
171
171
 
@@ -163,7 +163,7 @@ describe Scenario, "#at_most" do
163
163
  @scenario.call(@double)
164
164
  end.should raise_error(
165
165
  Errors::TimesCalledError,
166
- "Called 3 times.\nExpected at most 2 times."
166
+ "foobar()\nCalled 3 times.\nExpected at most 2 times."
167
167
  )
168
168
  end
169
169
 
@@ -660,4 +660,17 @@ describe Scenario, "#expected_arguments" do
660
660
  @scenario.expected_arguments.should == []
661
661
  end
662
662
  end
663
+
664
+ describe Scenario, "#formatted_name" do
665
+ it_should_behave_like "RR::Scenario"
666
+
667
+ it "renders the formatted name of the Scenario with no arguments" do
668
+ @scenario.formatted_name.should == "foobar()"
669
+ end
670
+
671
+ it "renders the formatted name of the Scenario with arguments" do
672
+ @scenario.with(1, 2)
673
+ @scenario.formatted_name.should == "foobar(1, 2)"
674
+ end
675
+ end
663
676
  end
@@ -1,10 +1,11 @@
1
1
  module RR
2
2
  module Expectations
3
3
  class TimesCalledExpectation
4
- attr_reader :times_called
4
+ attr_reader :scenario, :times_called
5
5
  attr_accessor :matcher
6
-
7
- def initialize(matcher=nil)
6
+
7
+ def initialize(scenario, matcher=nil)
8
+ @scenario = scenario
8
9
  @matcher = matcher
9
10
  @times_called = 0
10
11
  @verify_backtrace = caller[1..-1]
@@ -47,7 +48,7 @@ module RR
47
48
  end
48
49
 
49
50
  def error_message
50
- @matcher.error_message(@times_called)
51
+ "#{scenario.formatted_name}\n#{@matcher.error_message(@times_called)}"
51
52
  end
52
53
  end
53
54
  end
data/lib/rr/scenario.rb CHANGED
@@ -23,7 +23,7 @@ module RR
23
23
  @double = double
24
24
  @definition = definition
25
25
  @times_called = 0
26
- @times_called_expectation = Expectations::TimesCalledExpectation.new
26
+ @times_called_expectation = Expectations::TimesCalledExpectation.new(self)
27
27
  end
28
28
 
29
29
  # Scenario#with sets the expectation that the Scenario will receive
@@ -244,7 +244,7 @@ module RR
244
244
  else
245
245
  return double.object.__send__(
246
246
  :method_missing,
247
- double.method_name,
247
+ method_name,
248
248
  *args,
249
249
  &block
250
250
  )
@@ -329,5 +329,9 @@ module RR
329
329
  definition.argument_expectation = value
330
330
  end
331
331
  protected :argument_expectation=
332
+
333
+ def formatted_name
334
+ self.class.formatted_name(method_name, expected_arguments)
335
+ end
332
336
  end
333
337
  end
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.2
2
+ rubygems_version: 0.9.3
3
3
  specification_version: 1
4
4
  name: rr
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.3.7
7
- date: 2007-08-09 00:00:00 -07:00
6
+ version: 0.3.8
7
+ date: 2007-08-12 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,107 +29,107 @@ post_install_message:
29
29
  authors:
30
30
  - Brian Takita
31
31
  files:
32
- - README
33
32
  - Rakefile
34
33
  - CHANGES
35
- - lib/rr/extensions/instance_methods.rb
36
- - lib/rr/adapters/test_unit.rb
37
- - lib/rr/adapters/rspec.rb
34
+ - README
35
+ - lib/rr.rb
36
+ - lib/rr/scenario_method_proxy.rb
37
+ - lib/rr/scenario.rb
38
+ - lib/rr/scenario_definition.rb
39
+ - lib/rr/hash_with_object_id_key.rb
40
+ - lib/rr/scenario_definition_builder.rb
41
+ - lib/rr/scenario_matches.rb
42
+ - lib/rr/space.rb
43
+ - lib/rr/double.rb
44
+ - lib/rr/scenario_creator.rb
45
+ - lib/rr/times_called_matchers/any_times_matcher.rb
46
+ - lib/rr/times_called_matchers/at_most_matcher.rb
47
+ - lib/rr/times_called_matchers/times_called_matcher.rb
48
+ - lib/rr/times_called_matchers/at_least_matcher.rb
49
+ - lib/rr/times_called_matchers/proc_matcher.rb
50
+ - lib/rr/times_called_matchers/integer_matcher.rb
51
+ - lib/rr/times_called_matchers/non_terminal.rb
52
+ - lib/rr/times_called_matchers/terminal.rb
53
+ - lib/rr/times_called_matchers/range_matcher.rb
38
54
  - lib/rr/expectations/argument_equality_expectation.rb
39
55
  - lib/rr/expectations/times_called_expectation.rb
40
56
  - lib/rr/expectations/any_argument_expectation.rb
41
- - lib/rr/scenario.rb
42
- - lib/rr/double.rb
43
- - lib/rr/errors/times_called_error.rb
44
57
  - lib/rr/errors/scenario_not_found_error.rb
45
- - lib/rr/errors/scenario_order_error.rb
46
58
  - lib/rr/errors/argument_equality_error.rb
59
+ - lib/rr/errors/scenario_order_error.rb
47
60
  - lib/rr/errors/rr_error.rb
61
+ - lib/rr/errors/times_called_error.rb
48
62
  - lib/rr/errors/scenario_definition_error.rb
49
- - lib/rr/scenario_creator.rb
50
- - lib/rr/space.rb
51
- - lib/rr/scenario_definition_builder.rb
52
- - lib/rr/scenario_definition.rb
63
+ - lib/rr/adapters/test_unit.rb
64
+ - lib/rr/adapters/rspec.rb
53
65
  - lib/rr/wildcard_matchers/boolean.rb
54
- - lib/rr/wildcard_matchers/anything.rb
55
- - lib/rr/wildcard_matchers/numeric.rb
56
66
  - lib/rr/wildcard_matchers/duck_type.rb
67
+ - lib/rr/wildcard_matchers/range.rb
57
68
  - lib/rr/wildcard_matchers/regexp.rb
69
+ - lib/rr/wildcard_matchers/numeric.rb
58
70
  - lib/rr/wildcard_matchers/is_a.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/scenario_method_proxy.rb
70
- - lib/rr/scenario_matches.rb
71
- - lib/rr/hash_with_object_id_key.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
71
+ - lib/rr/wildcard_matchers/anything.rb
72
+ - lib/rr/extensions/instance_methods.rb
73
+ - examples/environment_fixture_setup.rb
74
+ - examples/rspec_example_suite.rb
75
+ - examples/example_suite.rb
76
+ - examples/example_helper.rb
77
+ - examples/test_unit_example_suite.rb
78
+ - examples/high_level_example.rb
79
+ - examples/rr/scenario_definition_example.rb
80
+ - examples/rr/scenario_method_proxy_example.rb
81
+ - examples/rr/scenario_example.rb
82
+ - examples/rr/scenario_creator_example.rb
83
+ - examples/rr/rspec/rspec_backtrace_tweaking_example.rb
84
+ - examples/rr/rspec/rspec_adapter_example.rb
85
+ - examples/rr/rspec/rspec_usage_example.rb
86
+ - examples/rr/times_called_matchers/at_most_matcher_example.rb
87
+ - examples/rr/times_called_matchers/at_least_matcher_example.rb
88
+ - examples/rr/times_called_matchers/times_called_matcher_example.rb
89
+ - examples/rr/times_called_matchers/range_matcher_example.rb
90
+ - examples/rr/times_called_matchers/proc_matcher_example.rb
91
+ - examples/rr/times_called_matchers/any_times_matcher_example.rb
92
+ - examples/rr/times_called_matchers/integer_matcher_example.rb
93
+ - examples/rr/space/space_verify_example.rb
94
+ - examples/rr/space/space_reset_example.rb
95
+ - examples/rr/space/space_create_example.rb
96
+ - examples/rr/space/space_helper.rb
97
+ - examples/rr/space/space_example.rb
98
+ - examples/rr/space/hash_with_object_id_key_example.rb
99
+ - examples/rr/space/space_register_example.rb
100
+ - examples/rr/expectations/is_a_argument_equality_expectation_example.rb
101
+ - examples/rr/expectations/any_argument_expectation_example.rb
102
+ - examples/rr/expectations/regexp_argument_equality_expectation_example.rb
103
+ - examples/rr/expectations/boolean_argument_equality_expectation_example.rb
104
+ - examples/rr/expectations/duck_type_argument_equality_expectation_example.rb
105
+ - examples/rr/expectations/numeric_argument_equality_expectation_example.rb
106
+ - examples/rr/expectations/range_argument_equality_expectation_example.rb
78
107
  - examples/rr/expectations/argument_equality_expectation_example.rb
79
108
  - 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
82
109
  - examples/rr/expectations/times_called_expectation/times_called_expectation_integer_example.rb
83
- - examples/rr/expectations/times_called_expectation/times_called_expectation_example.rb
84
- - examples/rr/expectations/times_called_expectation/times_called_expectation_proc_example.rb
110
+ - examples/rr/expectations/times_called_expectation/times_called_expectation_any_times_example.rb
85
111
  - examples/rr/expectations/times_called_expectation/times_called_expectation_helper.rb
112
+ - examples/rr/expectations/times_called_expectation/times_called_expectation_proc_example.rb
113
+ - examples/rr/expectations/times_called_expectation/times_called_expectation_example.rb
114
+ - examples/rr/expectations/times_called_expectation/times_called_expectation_at_least_example.rb
86
115
  - examples/rr/expectations/times_called_expectation/times_called_expectation_at_most_example.rb
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
116
+ - examples/rr/expectations/times_called_expectation/times_called_expectation_range_example.rb
117
+ - examples/rr/errors/rr_error_example.rb
118
+ - examples/rr/double/double_original_method_example.rb
119
+ - examples/rr/double/double_reset_example.rb
102
120
  - examples/rr/double/double_bind_example.rb
103
- - examples/rr/double/double_dispatching_example.rb
121
+ - examples/rr/double/double_register_scenario_example.rb
104
122
  - examples/rr/double/double_example.rb
105
- - examples/rr/double/double_reset_example.rb
123
+ - examples/rr/double/double_dispatching_example.rb
106
124
  - examples/rr/double/double_verify_example.rb
107
- - examples/rr/double/double_register_scenario_example.rb
108
- - examples/rr/double/double_original_method_example.rb
109
- - examples/rr/space/space_example.rb
110
- - examples/rr/space/space_reset_example.rb
111
- - examples/rr/space/space_create_example.rb
112
- - examples/rr/space/space_helper.rb
113
- - examples/rr/space/space_register_example.rb
114
- - examples/rr/space/space_verify_example.rb
115
- - examples/rr/space/hash_with_object_id_key_example.rb
116
- - examples/rr/times_called_matchers/proc_matcher_example.rb
117
- - examples/rr/times_called_matchers/times_called_matcher_example.rb
118
- - examples/rr/times_called_matchers/at_most_matcher_example.rb
119
- - examples/rr/times_called_matchers/any_times_matcher_example.rb
120
- - examples/rr/times_called_matchers/at_least_matcher_example.rb
121
- - examples/rr/times_called_matchers/range_matcher_example.rb
122
- - examples/rr/times_called_matchers/integer_matcher_example.rb
123
- - examples/rr/scenario_creator_example.rb
124
- - examples/rr/scenario_method_proxy_example.rb
125
- - examples/rr/scenario_definition_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
125
+ - examples/rr/test_unit/test_unit_backtrace_test.rb
126
+ - examples/rr/test_unit/test_helper.rb
127
+ - examples/rr/test_unit/test_unit_integration_test.rb
128
+ - examples/rr/extensions/instance_methods_argument_matcher_example.rb
129
+ - examples/rr/extensions/instance_methods_times_matcher_example.rb
130
+ - examples/rr/extensions/instance_methods_creator_example.rb
131
+ - examples/rr/extensions/instance_methods_space_example.rb
132
+ - examples/rr/extensions/instance_methods_example_helper.rb
133
133
  test_files: []
134
134
 
135
135
  rdoc_options: