rr 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. data/CHANGES +7 -0
  2. data/Rakefile +1 -1
  3. data/examples/environment_fixture_setup.rb +1 -1
  4. data/examples/example_helper.rb +1 -0
  5. data/examples/high_level_example.rb +1 -2
  6. data/examples/rr/do_not_allow_creator_example.rb +1 -2
  7. data/examples/rr/double_bind_example.rb +1 -2
  8. data/examples/rr/double_dispatching_example.rb +2 -3
  9. data/examples/rr/double_example.rb +1 -2
  10. data/examples/rr/double_register_scenario_example.rb +1 -2
  11. data/examples/rr/double_reset_example.rb +1 -2
  12. data/examples/rr/double_verify_example.rb +1 -2
  13. data/examples/rr/errors/rr_error_example.rb +1 -2
  14. data/examples/rr/expectations/any_argument_expectation_example.rb +1 -2
  15. data/examples/rr/expectations/anything_argument_equality_expectation_example.rb +1 -2
  16. data/examples/rr/expectations/argument_equality_expectation_example.rb +1 -2
  17. data/examples/rr/expectations/boolean_argument_equality_expectation_example.rb +1 -2
  18. data/examples/rr/expectations/duck_type_argument_equality_expectation_example.rb +1 -2
  19. data/examples/rr/expectations/is_a_argument_equality_expectation_example.rb +1 -2
  20. data/examples/rr/expectations/numeric_argument_equality_expectation_example.rb +1 -2
  21. data/examples/rr/expectations/range_argument_equality_expectation_example.rb +1 -2
  22. data/examples/rr/expectations/regexp_argument_equality_expectation_example.rb +1 -2
  23. data/examples/rr/expectations/times_called_expectation/times_called_expectation_at_least_example.rb +74 -0
  24. data/examples/rr/expectations/times_called_expectation/times_called_expectation_at_most_example.rb +69 -0
  25. data/examples/rr/expectations/times_called_expectation/times_called_expectation_helper.rb +18 -0
  26. data/examples/rr/expectations/times_called_expectation/times_called_expectation_integer_example.rb +102 -0
  27. data/examples/rr/expectations/times_called_expectation/times_called_expectation_proc_example.rb +80 -0
  28. data/examples/rr/expectations/times_called_expectation/times_called_expectation_range_example.rb +81 -0
  29. data/examples/rr/expectations/times_called_expectation_example.rb +1 -185
  30. data/examples/rr/extensions/double_methods_example.rb +3 -4
  31. data/examples/rr/mock_creator_example.rb +1 -2
  32. data/examples/rr/probe_creator_example.rb +1 -2
  33. data/examples/rr/rspec/rspec_adapter_example.rb +1 -2
  34. data/examples/rr/rspec/rspec_backtrace_tweaking_example.rb +1 -2
  35. data/examples/rr/rspec/rspec_usage_example.rb +1 -2
  36. data/examples/rr/scenario_example.rb +60 -15
  37. data/examples/rr/space_create_example.rb +1 -2
  38. data/examples/rr/space_example.rb +1 -2
  39. data/examples/rr/space_register_example.rb +1 -2
  40. data/examples/rr/space_reset_example.rb +51 -4
  41. data/examples/rr/space_verify_example.rb +4 -5
  42. data/examples/rr/stub_creator_example.rb +1 -2
  43. data/examples/rr/test_unit/test_helper.rb +1 -1
  44. data/examples/rr/times_called_matchers/at_least_matcher_example.rb +74 -0
  45. data/examples/rr/times_called_matchers/at_most_matcher_example.rb +82 -0
  46. data/examples/rr/times_called_matchers/integer_matcher_example.rb +88 -0
  47. data/examples/rr/times_called_matchers/proc_matcher_example.rb +74 -0
  48. data/examples/rr/times_called_matchers/range_matcher_example.rb +94 -0
  49. data/examples/rr/times_called_matchers/times_called_matcher_example.rb +53 -0
  50. data/lib/rr.rb +15 -7
  51. data/lib/rr/adapters/rspec.rb +2 -2
  52. data/lib/rr/adapters/test_unit.rb +1 -1
  53. data/lib/rr/double.rb +2 -2
  54. data/lib/rr/expectations/times_called_expectation.rb +14 -13
  55. data/lib/rr/extensions/double_methods.rb +5 -5
  56. data/lib/rr/scenario.rb +35 -7
  57. data/lib/rr/space.rb +20 -8
  58. data/lib/rr/times_called_matchers/at_least_matcher.rb +22 -0
  59. data/lib/rr/times_called_matchers/at_most_matcher.rb +22 -0
  60. data/lib/rr/times_called_matchers/integer_matcher.rb +17 -0
  61. data/lib/rr/times_called_matchers/proc_matcher.rb +17 -0
  62. data/lib/rr/times_called_matchers/range_matcher.rb +19 -0
  63. data/lib/rr/times_called_matchers/times_called_matcher.rb +44 -0
  64. data/lib/rr/wildcard_matchers/anything.rb +13 -0
  65. data/lib/rr/wildcard_matchers/boolean.rb +18 -0
  66. data/lib/rr/wildcard_matchers/duck_type.rb +24 -0
  67. data/lib/rr/wildcard_matchers/is_a.rb +20 -0
  68. data/lib/rr/wildcard_matchers/numeric.rb +9 -0
  69. data/lib/rr/{expectations/wildcard_matchers → wildcard_matchers}/range.rb +0 -0
  70. data/lib/rr/{expectations/wildcard_matchers → wildcard_matchers}/regexp.rb +0 -0
  71. metadata +27 -9
  72. data/lib/rr/expectations/wildcard_matchers/anything.rb +0 -15
  73. data/lib/rr/expectations/wildcard_matchers/boolean.rb +0 -20
  74. data/lib/rr/expectations/wildcard_matchers/duck_type.rb +0 -26
  75. data/lib/rr/expectations/wildcard_matchers/is_a.rb +0 -22
  76. data/lib/rr/expectations/wildcard_matchers/numeric.rb +0 -11
data/CHANGES CHANGED
@@ -1,3 +1,10 @@
1
+ * 0.1.7
2
+ - Fixed [#12194] Double#reset_doubles are not clearing Ordered Scenarios bug
3
+ - Added Space#reset
4
+ - Space#reset_doubles and Space#reset_ordered_scenarios is now protected
5
+ - Added Scenario#at_least
6
+ - Added Scenario#at_most
7
+
1
8
  * 0.1.6
2
9
  - [#12120] probe allows a the return value to be intercepted
3
10
 
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.6"
24
+ PKG_VERSION = "0.1.7"
25
25
  PKG_FILES = FileList[
26
26
  '[A-Z]*',
27
27
  '*.rb',
@@ -1,7 +1,7 @@
1
1
  require "rubygems"
2
2
  require "spec"
3
3
  dir = File.dirname(__FILE__)
4
- $LOAD_PATH << "#{dir}/../lib"
4
+ $LOAD_PATH.unshift "#{dir}/../lib"
5
5
  require "rr"
6
6
  require "ruby-debug"
7
7
  require "pp"
@@ -1,6 +1,7 @@
1
1
  dir = File.dirname(__FILE__)
2
2
  require "#{dir}/environment_fixture_setup"
3
3
  require "examples/rr/space_helper"
4
+ require "examples/rr/expectations/times_called_expectation/times_called_expectation_helper"
4
5
 
5
6
  require "rr/adapters/rspec"
6
7
  Spec::Runner.configure do |config|
@@ -8,7 +8,7 @@ describe "RR", :shared => true do
8
8
  end
9
9
 
10
10
  after(:each) do
11
- RR::Space.instance.reset_doubles
11
+ RR::Space.instance.reset
12
12
  end
13
13
  end
14
14
 
@@ -116,7 +116,6 @@ describe "RR stub:" do
116
116
 
117
117
  it "allows ordering" do
118
118
  stub(@obj).to_s {"value 1"}.once.ordered
119
-
120
119
  stub(@obj).to_s {"value 2"}.once.ordered
121
120
 
122
121
  @obj.to_s.should == "value 1"
@@ -1,5 +1,4 @@
1
- dir = File.dirname(__FILE__)
2
- require "#{dir}/../example_helper"
1
+ require "examples/example_helper"
3
2
 
4
3
  module RR
5
4
  describe DoNotAllowCreator, :shared => true do
@@ -1,5 +1,4 @@
1
- dir = File.dirname(__FILE__)
2
- require "#{dir}/../example_helper"
1
+ require "examples/example_helper"
3
2
 
4
3
  module RR
5
4
  describe Double, "#bind with an existing method" do
@@ -1,5 +1,4 @@
1
- dir = File.dirname(__FILE__)
2
- require "#{dir}/../example_helper"
1
+ require "examples/example_helper"
3
2
 
4
3
  module RR
5
4
  describe Double, "method dispatching", :shared => true do
@@ -24,7 +23,7 @@ describe Double, " method dispatching where method name has a ! in it" do
24
23
  it "executes the block" do
25
24
  scenario = @space.create_scenario(@double)
26
25
  scenario.with(1, 2) {:return_value}
27
- @object.foobar!(1, 2).should == :return_value
26
+ @object.foobar!(1, 2).should == :return_value
28
27
  end
29
28
  end
30
29
 
@@ -1,5 +1,4 @@
1
- dir = File.dirname(__FILE__)
2
- require "#{dir}/../example_helper"
1
+ require "examples/example_helper"
3
2
 
4
3
  module RR
5
4
  describe Double, :shared => true do
@@ -1,5 +1,4 @@
1
- dir = File.dirname(__FILE__)
2
- require "#{dir}/../example_helper"
1
+ require "examples/example_helper"
3
2
 
4
3
  module RR
5
4
  describe Double, "#register_scenario" do
@@ -1,5 +1,4 @@
1
- dir = File.dirname(__FILE__)
2
- require "#{dir}/../example_helper"
1
+ require "examples/example_helper"
3
2
 
4
3
  module RR
5
4
  describe Double, "#reset", :shared => true do
@@ -1,5 +1,4 @@
1
- dir = File.dirname(__FILE__)
2
- require "#{dir}/../example_helper"
1
+ require "examples/example_helper"
3
2
 
4
3
  module RR
5
4
  describe Double, "#verify" do
@@ -1,5 +1,4 @@
1
- dir = File.dirname(__FILE__)
2
- require "#{dir}/../../example_helper"
1
+ require "examples/example_helper"
3
2
 
4
3
  module RR
5
4
  module Errors
@@ -1,5 +1,4 @@
1
- dir = File.dirname(__FILE__)
2
- require "#{dir}/../../example_helper"
1
+ require "examples/example_helper"
3
2
 
4
3
  module RR
5
4
  module Expectations
@@ -1,5 +1,4 @@
1
- dir = File.dirname(__FILE__)
2
- require "#{dir}/../../example_helper"
1
+ require "examples/example_helper"
3
2
 
4
3
  module RR
5
4
  module Expectations
@@ -1,5 +1,4 @@
1
- dir = File.dirname(__FILE__)
2
- require "#{dir}/../../example_helper"
1
+ require "examples/example_helper"
3
2
 
4
3
  module RR
5
4
  module Expectations
@@ -1,5 +1,4 @@
1
- dir = File.dirname(__FILE__)
2
- require "#{dir}/../../example_helper"
1
+ require "examples/example_helper"
3
2
 
4
3
  module RR
5
4
  module Expectations
@@ -1,5 +1,4 @@
1
- dir = File.dirname(__FILE__)
2
- require "#{dir}/../../example_helper"
1
+ require "examples/example_helper"
3
2
 
4
3
  module RR
5
4
  module Expectations
@@ -1,5 +1,4 @@
1
- dir = File.dirname(__FILE__)
2
- require "#{dir}/../../example_helper"
1
+ require "examples/example_helper"
3
2
 
4
3
  module RR
5
4
  module Expectations
@@ -1,5 +1,4 @@
1
- dir = File.dirname(__FILE__)
2
- require "#{dir}/../../example_helper"
1
+ require "examples/example_helper"
3
2
 
4
3
  module RR
5
4
  module Expectations
@@ -1,5 +1,4 @@
1
- dir = File.dirname(__FILE__)
2
- require "#{dir}/../../example_helper"
1
+ require "examples/example_helper"
3
2
 
4
3
  module RR
5
4
  module Expectations
@@ -1,5 +1,4 @@
1
- dir = File.dirname(__FILE__)
2
- require "#{dir}/../../example_helper"
1
+ require "examples/example_helper"
3
2
 
4
3
  module RR
5
4
  module Expectations
@@ -0,0 +1,74 @@
1
+ require "examples/example_helper"
2
+
3
+ module RR
4
+ module Expectations
5
+ describe TimesCalledExpectation, ' with AtLeastMatcher', :shared => true do
6
+ it_should_behave_like "RR::Expectations::TimesCalledExpectation"
7
+
8
+ before do
9
+ @times = 3
10
+ @at_least = TimesCalledMatchers::AtLeastMatcher.new(@times)
11
+ @expectation = TimesCalledExpectation.new(@at_least)
12
+ end
13
+ end
14
+
15
+ describe TimesCalledExpectation, "#verify! with AtLeastMatcher" do
16
+ it_should_behave_like "RR::Expectations::TimesCalledExpectation with AtLeastMatcher"
17
+
18
+ it "passes when times called > times" do
19
+ 4.times {@expectation.attempt!}
20
+ @expectation.verify!
21
+ end
22
+
23
+ it "passes when times called == times" do
24
+ 3.times {@expectation.attempt!}
25
+ @expectation.verify!
26
+ end
27
+
28
+ it "raises error when times called < times" do
29
+ @expectation.attempt!
30
+ proc do
31
+ @expectation.verify!
32
+ end.should raise_error(
33
+ RR::Errors::TimesCalledError,
34
+ "Called 1 time. Expected at least 3 times."
35
+ )
36
+ end
37
+ end
38
+
39
+ describe TimesCalledExpectation, "#attempt? with AtLeastMatcher" do
40
+ it_should_behave_like "RR::Expectations::TimesCalledExpectation with AtLeastMatcher"
41
+
42
+ it "returns true when attempted less than expected times" do
43
+ 2.times {@expectation.attempt!}
44
+ @expectation.should be_attempt
45
+ end
46
+
47
+ it "returns false when attempted expected times" do
48
+ 3.times {@expectation.attempt!}
49
+ @expectation.should_not be_attempt
50
+ end
51
+
52
+ it "returns false when attempted more than expected times" do
53
+ 4.times {@expectation.attempt!}
54
+ @expectation.should_not be_attempt
55
+ end
56
+ end
57
+
58
+ describe TimesCalledExpectation, "#attempt! with AtLeastMatcher" do
59
+ it_should_behave_like "RR::Expectations::TimesCalledExpectation with AtLeastMatcher"
60
+
61
+ it "passes when times called more than times" do
62
+ 4.times {@expectation.attempt!}
63
+ end
64
+
65
+ it "passes when times called == times" do
66
+ 3.times {@expectation.attempt!}
67
+ end
68
+
69
+ it "passes when times called < times" do
70
+ @expectation.attempt!
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,69 @@
1
+ require "examples/example_helper"
2
+
3
+ module RR
4
+ module Expectations
5
+ describe TimesCalledExpectation, ' with AtMostMatcher', :shared => true do
6
+ it_should_behave_like "RR::Expectations::TimesCalledExpectation"
7
+
8
+ before do
9
+ @times = 3
10
+ @at_most = TimesCalledMatchers::AtMostMatcher.new(@times)
11
+ @expectation = TimesCalledExpectation.new(@at_most)
12
+ end
13
+ end
14
+
15
+ describe TimesCalledExpectation, "#verify! with AtMostMatcher" do
16
+ it_should_behave_like "RR::Expectations::TimesCalledExpectation with AtMostMatcher"
17
+
18
+ it "returns true when times called == times" do
19
+ 3.times {@expectation.attempt!}
20
+ @expectation.verify!
21
+ end
22
+
23
+ it "raises error when times called < times" do
24
+ 2.times {@expectation.attempt!}
25
+ @expectation.verify!
26
+ end
27
+ end
28
+
29
+ describe TimesCalledExpectation, "#attempt? with AtMostMatcher" do
30
+ it_should_behave_like "RR::Expectations::TimesCalledExpectation with AtMostMatcher"
31
+
32
+ it "returns true when attempted less than expected times" do
33
+ 2.times {@expectation.attempt!}
34
+ @expectation.should be_attempt
35
+ end
36
+
37
+ it "returns false when attempted expected times" do
38
+ 3.times {@expectation.attempt!}
39
+ @expectation.should_not be_attempt
40
+ end
41
+
42
+ it "raises error before attempted more than expected times" do
43
+ 3.times {@expectation.attempt!}
44
+ proc {@expectation.attempt!}.should raise_error(
45
+ Errors::TimesCalledError
46
+ )
47
+ end
48
+ end
49
+
50
+ describe TimesCalledExpectation, "#attempt! with AtMostMatcher" do
51
+ it_should_behave_like "RR::Expectations::TimesCalledExpectation with AtMostMatcher"
52
+
53
+ it "fails when times called more than times" do
54
+ 3.times {@expectation.attempt!}
55
+ proc do
56
+ @expectation.attempt!
57
+ end.should raise_error(Errors::TimesCalledError, "Called 4 times. Expected at most 3 times.")
58
+ end
59
+
60
+ it "passes when times called == times" do
61
+ 3.times {@expectation.attempt!}
62
+ end
63
+
64
+ it "passes when times called < times" do
65
+ @expectation.attempt!
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,18 @@
1
+ module RR
2
+ module Expectations
3
+ describe TimesCalledExpectation, :shared => true do
4
+ before do
5
+ @space = Space.new
6
+ @object = Object.new
7
+ @method_name = :foobar
8
+ @double = @space.create_double(@object, @method_name)
9
+ @scenario = @space.create_scenario(@double)
10
+ @scenario.with_any_args
11
+ end
12
+
13
+ def raises_expectation_error(&block)
14
+ proc {block.call}.should raise_error(Errors::TimesCalledError)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,102 @@
1
+ require "examples/example_helper"
2
+
3
+ module RR
4
+ module Expectations
5
+ describe TimesCalledExpectation, " with IntegerMatcher", :shared => true do
6
+ it_should_behave_like "RR::Expectations::TimesCalledExpectation"
7
+
8
+ before do
9
+ @expectation = TimesCalledExpectation.new(2)
10
+ @expected_line = __LINE__ - 1
11
+ end
12
+ end
13
+
14
+ describe TimesCalledExpectation, "#verify" do
15
+ it_should_behave_like "RR::Expectations::TimesCalledExpectation with IntegerMatcher"
16
+
17
+ it "returns true when times called exactly matches an integer" do
18
+ @expectation.verify.should == false
19
+ @expectation.attempt!
20
+ @expectation.verify.should == false
21
+ @expectation.attempt!
22
+ @expectation.verify.should == true
23
+ end
24
+ end
25
+
26
+ describe TimesCalledExpectation, "#verify! when passed an Integer (2)" do
27
+ it_should_behave_like "RR::Expectations::TimesCalledExpectation with IntegerMatcher"
28
+
29
+ it "passes after attempt! called 2 times" do
30
+ @expectation.attempt!
31
+ @expectation.attempt!
32
+ @expectation.verify!
33
+ end
34
+
35
+ it "fails after attempt! called 1 time" do
36
+ @expectation.attempt!
37
+ proc {@expectation.verify!}.should raise_error(
38
+ Errors::TimesCalledError,
39
+ "Called 1 time. Expected 2 times."
40
+ )
41
+ end
42
+
43
+ it "can't be called when attempt! is called 3 times" do
44
+ @expectation.attempt!
45
+ @expectation.attempt!
46
+ proc do
47
+ @expectation.attempt!
48
+ end.should raise_error(Errors::TimesCalledError, "Called 3 times. Expected 2 times.")
49
+ end
50
+
51
+ it "has a backtrace to where the TimesCalledExpectation was instantiated on failure" do
52
+ error = nil
53
+ begin
54
+ @expectation.verify!
55
+ rescue Errors::TimesCalledError => e
56
+ error = e
57
+ end
58
+ e.backtrace.first.should include(__FILE__)
59
+ e.backtrace.first.should include(":#{@expected_line}")
60
+ end
61
+
62
+ it "has an error message that includes the number of times called and expected number of times" do
63
+ proc do
64
+ @expectation.verify!
65
+ end.should raise_error(Errors::TimesCalledError, "Called 0 times. Expected 2 times.")
66
+ end
67
+ end
68
+
69
+ describe TimesCalledExpectation, "#attempt? with IntegerMatcher" do
70
+ it_should_behave_like "RR::Expectations::TimesCalledExpectation with IntegerMatcher"
71
+
72
+ it "returns true when attempted less than expected times" do
73
+ 1.times {@expectation.attempt!}
74
+ @expectation.should be_attempt
75
+ end
76
+
77
+ it "returns false when attempted expected times" do
78
+ 2.times {@expectation.attempt!}
79
+ @expectation.should_not be_attempt
80
+ end
81
+
82
+ it "raises error before attempted more than expected times" do
83
+ 2.times {@expectation.attempt!}
84
+ proc {@expectation.attempt!}.should raise_error(
85
+ Errors::TimesCalledError
86
+ )
87
+ end
88
+ end
89
+
90
+ describe TimesCalledExpectation, "#attempt! for an IntegerMatcher" do
91
+ it_should_behave_like "RR::Expectations::TimesCalledExpectation with IntegerMatcher"
92
+
93
+ it "raises error when attempt! called more than the expected number of times" do
94
+ @expectation.attempt!
95
+ @expectation.attempt!
96
+ proc do
97
+ @expectation.attempt!
98
+ end.should raise_error(Errors::TimesCalledError)
99
+ end
100
+ end
101
+ end
102
+ end