rr 0.1.3 → 0.1.4
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 +4 -0
- data/Rakefile +1 -1
- data/examples/rr/double_dispatching_example.rb +2 -2
- data/examples/rr/errors/rr_error_example.rb +19 -0
- data/examples/rr/expectations/times_called_expectation_example.rb +12 -0
- data/lib/rr/double.rb +3 -1
- data/lib/rr/errors/rr_error.rb +2 -1
- data/lib/rr/expectations/times_called_expectation.rb +10 -1
- metadata +1 -1
data/CHANGES
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
* 0.1.4
|
2
|
+
- TimesCalledError prints the backtrace to where the Scenario was defined when being verified
|
3
|
+
- Error message includes method name when Scenario is not found
|
4
|
+
|
1
5
|
* 0.1.3
|
2
6
|
- Fixed issue where Double#placeholder_name issues when Double method name has a ! or ?
|
3
7
|
|
data/Rakefile
CHANGED
@@ -96,9 +96,9 @@ describe Double, " method dispatching where there are scenarios" do
|
|
96
96
|
scenario_2 = @space.create_scenario(@double)
|
97
97
|
scenario_2.with(3)
|
98
98
|
|
99
|
-
proc {@object.foobar(:
|
99
|
+
proc {@object.foobar(:arg1, :arg2)}.should raise_error(
|
100
100
|
Errors::ScenarioNotFoundError,
|
101
|
-
"No scenario for
|
101
|
+
"No scenario for foobar(:arg1, :arg2)"
|
102
102
|
)
|
103
103
|
end
|
104
104
|
end
|
@@ -42,6 +42,25 @@ module Errors
|
|
42
42
|
|
43
43
|
backtrace.should include("lib/rr")
|
44
44
|
end
|
45
|
+
|
46
|
+
it "returns custom backtrace when backtrace is set" do
|
47
|
+
error = RRError.new
|
48
|
+
custom_backtrace = caller
|
49
|
+
error.backtrace = custom_backtrace
|
50
|
+
error.backtrace.should == custom_backtrace
|
51
|
+
end
|
52
|
+
|
53
|
+
it "returns normal backtrace when backtrace is not set" do
|
54
|
+
error = nil
|
55
|
+
expected_line = __LINE__ + 2
|
56
|
+
begin
|
57
|
+
raise RRError
|
58
|
+
rescue RRError => e
|
59
|
+
error = e
|
60
|
+
end
|
61
|
+
error.backtrace.first.should include(__FILE__)
|
62
|
+
error.backtrace.first.should include(expected_line.to_s)
|
63
|
+
end
|
45
64
|
end
|
46
65
|
end
|
47
66
|
end
|
@@ -66,6 +66,7 @@ describe TimesCalledExpectation, "#verify! when passed an Integer (2)" do
|
|
66
66
|
|
67
67
|
before do
|
68
68
|
@expectation = TimesCalledExpectation.new(2)
|
69
|
+
@expected_line = __LINE__ - 1
|
69
70
|
end
|
70
71
|
|
71
72
|
it "passes after verify_input called 2 times" do
|
@@ -86,6 +87,17 @@ describe TimesCalledExpectation, "#verify! when passed an Integer (2)" do
|
|
86
87
|
@expectation.verify_input
|
87
88
|
end.should raise_error(Errors::TimesCalledError)
|
88
89
|
end
|
90
|
+
|
91
|
+
it "has a backtrace to where the TimesCalledExpectation was instantiated on failure" do
|
92
|
+
error = nil
|
93
|
+
begin
|
94
|
+
@expectation.verify!
|
95
|
+
rescue Errors::TimesCalledError => e
|
96
|
+
error = e
|
97
|
+
end
|
98
|
+
e.backtrace.first.should include(__FILE__)
|
99
|
+
e.backtrace.first.should include(":#{@expected_line}")
|
100
|
+
end
|
89
101
|
end
|
90
102
|
|
91
103
|
describe TimesCalledExpectation, "#verify! when passed a Range (1..2)" do
|
data/lib/rr/double.rb
CHANGED
@@ -77,7 +77,9 @@ module RR
|
|
77
77
|
end
|
78
78
|
end
|
79
79
|
matching_scenarios.first.call(*args) unless matching_scenarios.empty?
|
80
|
-
|
80
|
+
|
81
|
+
formatted_errors = args.collect {|arg| arg.inspect}.join(', ')
|
82
|
+
raise Errors::ScenarioNotFoundError, "No scenario for #{@method_name}(#{formatted_errors})"
|
81
83
|
end
|
82
84
|
|
83
85
|
def placeholder_name
|
data/lib/rr/errors/rr_error.rb
CHANGED
@@ -3,8 +3,9 @@ module Errors
|
|
3
3
|
BACKTRACE_IDENTIFIER = /lib\/rr/
|
4
4
|
|
5
5
|
class RRError < RuntimeError
|
6
|
+
attr_writer :backtrace
|
6
7
|
def backtrace
|
7
|
-
original_backtrace = super
|
8
|
+
original_backtrace = (@backtrace) ? @backtrace : super
|
8
9
|
return original_backtrace unless RR::Space.trim_backtrace
|
9
10
|
|
10
11
|
return original_backtrace unless original_backtrace.respond_to?(:each)
|
@@ -7,6 +7,7 @@ module RR
|
|
7
7
|
raise ArgumentError, "Cannot pass in both an argument and a block" if times && time_condition_block
|
8
8
|
@times = times || time_condition_block
|
9
9
|
@times_called = 0
|
10
|
+
@verify_backtrace = caller[1..-1]
|
10
11
|
end
|
11
12
|
|
12
13
|
def verify_input
|
@@ -24,7 +25,15 @@ module RR
|
|
24
25
|
end
|
25
26
|
|
26
27
|
def verify!
|
27
|
-
|
28
|
+
unless verify
|
29
|
+
if @verify_backtrace
|
30
|
+
error = Errors::TimesCalledError.new
|
31
|
+
error.backtrace = @verify_backtrace
|
32
|
+
raise error
|
33
|
+
else
|
34
|
+
raise Errors::TimesCalledError
|
35
|
+
end
|
36
|
+
end
|
28
37
|
end
|
29
38
|
|
30
39
|
protected
|
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.
|
6
|
+
version: 0.1.4
|
7
7
|
date: 2007-07-09 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:
|