micronaut 0.2.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.
Files changed (79) hide show
  1. data/History.txt +15 -0
  2. data/LICENSE +45 -0
  3. data/README.markdown +66 -0
  4. data/RSPEC-LICENSE +23 -0
  5. data/Rakefile +78 -0
  6. data/VERSION.yml +4 -0
  7. data/bin/micronaut +4 -0
  8. data/examples/example_helper.rb +54 -0
  9. data/examples/lib/micronaut/behaviour_example.rb +351 -0
  10. data/examples/lib/micronaut/configuration_example.rb +133 -0
  11. data/examples/lib/micronaut/example_example.rb +67 -0
  12. data/examples/lib/micronaut/expectations/extensions/object_example.rb +146 -0
  13. data/examples/lib/micronaut/expectations/fail_with_example.rb +17 -0
  14. data/examples/lib/micronaut/expectations/wrap_expectation_example.rb +27 -0
  15. data/examples/lib/micronaut/formatters/base_formatter_example.rb +117 -0
  16. data/examples/lib/micronaut/formatters/documentation_formatter_example.rb +5 -0
  17. data/examples/lib/micronaut/formatters/progress_formatter_example.rb +29 -0
  18. data/examples/lib/micronaut/kernel_extensions_example.rb +13 -0
  19. data/examples/lib/micronaut/matchers/be_close_example.rb +52 -0
  20. data/examples/lib/micronaut/matchers/be_example.rb +298 -0
  21. data/examples/lib/micronaut/matchers/change_example.rb +360 -0
  22. data/examples/lib/micronaut/matchers/description_generation_example.rb +175 -0
  23. data/examples/lib/micronaut/matchers/eql_example.rb +35 -0
  24. data/examples/lib/micronaut/matchers/equal_example.rb +35 -0
  25. data/examples/lib/micronaut/matchers/has_example.rb +69 -0
  26. data/examples/lib/micronaut/matchers/have_example.rb +392 -0
  27. data/examples/lib/micronaut/matchers/include_example.rb +103 -0
  28. data/examples/lib/micronaut/matchers/match_example.rb +43 -0
  29. data/examples/lib/micronaut/matchers/matcher_methods_example.rb +78 -0
  30. data/examples/lib/micronaut/matchers/operator_matcher_example.rb +193 -0
  31. data/examples/lib/micronaut/matchers/raise_error_example.rb +348 -0
  32. data/examples/lib/micronaut/matchers/respond_to_example.rb +54 -0
  33. data/examples/lib/micronaut/matchers/satisfy_example.rb +36 -0
  34. data/examples/lib/micronaut/matchers/simple_matcher_example.rb +93 -0
  35. data/examples/lib/micronaut/matchers/throw_symbol_example.rb +125 -0
  36. data/examples/lib/micronaut/mocha_example.rb +29 -0
  37. data/examples/lib/micronaut/runner_example.rb +41 -0
  38. data/examples/lib/micronaut/world_example.rb +98 -0
  39. data/examples/lib/micronaut_example.rb +43 -0
  40. data/examples/resources/example_classes.rb +67 -0
  41. data/lib/micronaut.rb +40 -0
  42. data/lib/micronaut/behaviour.rb +217 -0
  43. data/lib/micronaut/configuration.rb +162 -0
  44. data/lib/micronaut/example.rb +112 -0
  45. data/lib/micronaut/expectations.rb +45 -0
  46. data/lib/micronaut/expectations/extensions/object.rb +92 -0
  47. data/lib/micronaut/expectations/handler.rb +51 -0
  48. data/lib/micronaut/expectations/wrap_expectation.rb +52 -0
  49. data/lib/micronaut/formatters.rb +12 -0
  50. data/lib/micronaut/formatters/base_formatter.rb +127 -0
  51. data/lib/micronaut/formatters/base_text_formatter.rb +139 -0
  52. data/lib/micronaut/formatters/documentation_formatter.rb +78 -0
  53. data/lib/micronaut/formatters/progress_formatter.rb +30 -0
  54. data/lib/micronaut/kernel_extensions.rb +11 -0
  55. data/lib/micronaut/matchers.rb +141 -0
  56. data/lib/micronaut/matchers/be.rb +204 -0
  57. data/lib/micronaut/matchers/be_close.rb +37 -0
  58. data/lib/micronaut/matchers/change.rb +148 -0
  59. data/lib/micronaut/matchers/eql.rb +26 -0
  60. data/lib/micronaut/matchers/equal.rb +26 -0
  61. data/lib/micronaut/matchers/generated_descriptions.rb +36 -0
  62. data/lib/micronaut/matchers/has.rb +19 -0
  63. data/lib/micronaut/matchers/have.rb +153 -0
  64. data/lib/micronaut/matchers/include.rb +80 -0
  65. data/lib/micronaut/matchers/match.rb +22 -0
  66. data/lib/micronaut/matchers/method_missing.rb +9 -0
  67. data/lib/micronaut/matchers/operator_matcher.rb +50 -0
  68. data/lib/micronaut/matchers/raise_error.rb +128 -0
  69. data/lib/micronaut/matchers/respond_to.rb +50 -0
  70. data/lib/micronaut/matchers/satisfy.rb +50 -0
  71. data/lib/micronaut/matchers/simple_matcher.rb +135 -0
  72. data/lib/micronaut/matchers/throw_symbol.rb +108 -0
  73. data/lib/micronaut/mocking/with_absolutely_nothing.rb +11 -0
  74. data/lib/micronaut/mocking/with_mocha.rb +15 -0
  75. data/lib/micronaut/mocking/with_rr.rb +24 -0
  76. data/lib/micronaut/rake_task.rb +84 -0
  77. data/lib/micronaut/runner.rb +60 -0
  78. data/lib/micronaut/world.rb +75 -0
  79. metadata +165 -0
@@ -0,0 +1,103 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")
2
+
3
+ describe Micronaut::Matchers do
4
+
5
+ describe "should include(expected)" do
6
+
7
+ it "should pass if target includes expected" do
8
+ [1,2,3].should include(3)
9
+ "abc".should include("a")
10
+ end
11
+
12
+ it 'should pass if target is a Hash and has the expected as a key' do
13
+ {:key => 'value'}.should include(:key)
14
+ end
15
+
16
+ it "should fail if target does not include expected" do
17
+ lambda do
18
+ [1,2,3].should include(4)
19
+ end.should fail_with("expected [1, 2, 3] to include 4")
20
+ lambda do
21
+ "abc".should include("d")
22
+ end.should fail_with("expected \"abc\" to include \"d\"")
23
+ lambda do
24
+ {:key => 'value'}.should include(:other)
25
+ end.should fail_with(%Q|expected {:key=>"value"} to include :other|)
26
+ end
27
+
28
+ end
29
+
30
+ describe "should include(with, multiple, args)" do
31
+
32
+ it "should pass if target includes all items" do
33
+ [1,2,3].should include(1,2,3)
34
+ end
35
+
36
+ it 'should pass if target is a Hash including all items as keys' do
37
+ {:key => 'value', :other => 'value'}.should include(:key, :other)
38
+ end
39
+
40
+ it "should fail if target does not include any one of the items" do
41
+ lambda do
42
+ [1,2,3].should include(1,2,4)
43
+ end.should fail_with("expected [1, 2, 3] to include 1, 2 and 4")
44
+ end
45
+
46
+ it 'should pass if target is a Hash missing any item as a key' do
47
+ lambda do
48
+ {:key => 'value'}.should include(:key, :other)
49
+ end.should fail_with(%Q|expected {:key=>"value"} to include :key and :other|)
50
+ end
51
+
52
+ end
53
+
54
+ describe "should_not include(expected)" do
55
+
56
+ it "should pass if target does not include expected" do
57
+ [1,2,3].should_not include(4)
58
+ "abc".should_not include("d")
59
+ end
60
+
61
+ it 'should pass if target is a Hash and does not have the expected as a key' do
62
+ {:other => 'value'}.should_not include(:key)
63
+ end
64
+
65
+ it "should fail if target includes expected" do
66
+ lambda {
67
+ [1,2,3].should_not include(3)
68
+ }.should fail_with("expected [1, 2, 3] not to include 3")
69
+ lambda {
70
+ "abc".should_not include("c")
71
+ }.should fail_with("expected \"abc\" not to include \"c\"")
72
+ lambda {
73
+ {:key => 'value'}.should_not include(:key)
74
+ }.should fail_with(%Q|expected {:key=>"value"} not to include :key|)
75
+ end
76
+
77
+ end
78
+
79
+ describe "should include(:key => value)" do
80
+
81
+ it "should pass if target is a Hash and includes the key/value pair" do
82
+ {:key => 'value'}.should include(:key => 'value')
83
+ end
84
+
85
+ it "should pass if target is a Hash and includes the key/value pair among others" do
86
+ {:key => 'value', :other => 'different'}.should include(:key => 'value')
87
+ end
88
+
89
+ it "should fail if target is a Hash and has a different value for key" do
90
+ lambda {
91
+ {:key => 'different'}.should include(:key => 'value')
92
+ }.should fail_with(%Q|expected {:key=>"different"} to include {:key=>"value"}|)
93
+ end
94
+
95
+ it "should fail if target is a Hash and has a different key" do
96
+ lambda {
97
+ {:other => 'value'}.should include(:key => 'value')
98
+ }.should fail_with(%Q|expected {:other=>"value"} to include {:key=>"value"}|)
99
+ end
100
+
101
+ end
102
+
103
+ end
@@ -0,0 +1,43 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")
2
+
3
+ describe Micronaut::Matchers do
4
+
5
+ describe "should match(expected)" do
6
+
7
+ it "should pass when target (String) matches expected (Regexp)" do
8
+ "string".should match(/tri/)
9
+ end
10
+
11
+ it "should fail when target (String) does not match expected (Regexp)" do
12
+ lambda { "string".should match(/rings/) }.should fail
13
+ end
14
+
15
+ it "should provide message, expected and actual on failure" do
16
+ matcher = match(/rings/)
17
+ matcher.matches?("string")
18
+ matcher.failure_message.should == ["expected \"string\" to match /rings/", /rings/, "string"]
19
+ end
20
+
21
+ end
22
+
23
+ describe "should_not match(expected)" do
24
+
25
+ it "should pass when target (String) matches does not match (Regexp)" do
26
+ "string".should_not match(/rings/)
27
+ end
28
+
29
+ it "should fail when target (String) matches expected (Regexp)" do
30
+ lambda {
31
+ "string".should_not match(/tri/)
32
+ }.should fail
33
+ end
34
+
35
+ it "should provide message, expected and actual on failure" do
36
+ matcher = match(/tri/)
37
+ matcher.matches?("string")
38
+ matcher.negative_failure_message.should == ["expected \"string\" not to match /tri/", /tri/, "string"]
39
+ end
40
+
41
+ end
42
+
43
+ end
@@ -0,0 +1,78 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")
2
+
3
+ describe Micronaut::Matchers, "provides the following matchers to examples" do
4
+
5
+ it "be_true" do
6
+ be_true.should be_an_instance_of(Micronaut::Matchers::Be)
7
+ end
8
+
9
+ it "be_false" do
10
+ be_false.should be_an_instance_of(Micronaut::Matchers::Be)
11
+ end
12
+
13
+ it "be_nil" do
14
+ be_nil.should be_an_instance_of(Micronaut::Matchers::Be)
15
+ end
16
+
17
+ it "be_arbitrary_predicate" do
18
+ be_arbitrary_predicate.should be_an_instance_of(Micronaut::Matchers::Be)
19
+ end
20
+
21
+ it "change" do
22
+ change("target", :message).should be_an_instance_of(Micronaut::Matchers::Change)
23
+ end
24
+
25
+ it "have" do
26
+ have(0).should be_an_instance_of(Micronaut::Matchers::Have)
27
+ end
28
+
29
+ it "have_exactly" do
30
+ have_exactly(0).should be_an_instance_of(Micronaut::Matchers::Have)
31
+ end
32
+
33
+ it "have_at_least" do
34
+ have_at_least(0).should be_an_instance_of(Micronaut::Matchers::Have)
35
+ end
36
+
37
+ it "have_at_most" do
38
+ have_at_most(0).should be_an_instance_of(Micronaut::Matchers::Have)
39
+ end
40
+
41
+ it "include" do
42
+ include(:value).should be_an_instance_of(Micronaut::Matchers::Include)
43
+ end
44
+
45
+ it "raise_error" do
46
+ raise_error.should be_an_instance_of(Micronaut::Matchers::RaiseError)
47
+ raise_error(NoMethodError).should be_an_instance_of(Micronaut::Matchers::RaiseError)
48
+ raise_error(NoMethodError, "message").should be_an_instance_of(Micronaut::Matchers::RaiseError)
49
+ end
50
+
51
+ it "satisfy" do
52
+ satisfy{}.should be_an_instance_of(Micronaut::Matchers::Satisfy)
53
+ end
54
+
55
+ it "throw_symbol" do
56
+ throw_symbol.should be_an_instance_of(Micronaut::Matchers::ThrowSymbol)
57
+ throw_symbol(:sym).should be_an_instance_of(Micronaut::Matchers::ThrowSymbol)
58
+ end
59
+
60
+ it "respond_to" do
61
+ respond_to(:sym).should be_an_instance_of(Micronaut::Matchers::RespondTo)
62
+ end
63
+
64
+ describe "#method_missing" do
65
+
66
+ it "should convert be_xyz to Be(:be_xyz)" do
67
+ Micronaut::Matchers::Be.expects(:new).with(:be_whatever)
68
+ be_whatever
69
+ end
70
+
71
+ it "should convert have_xyz to Has(:have_xyz)" do
72
+ self.expects(:has).with(:have_whatever)
73
+ have_whatever
74
+ end
75
+
76
+ end
77
+
78
+ end
@@ -0,0 +1,193 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")
2
+
3
+ describe "Operator Matchers" do
4
+
5
+ describe "should ==" do
6
+
7
+ it "should delegate message to target" do
8
+ subject = "apple"
9
+ subject.expects(:==).with("apple").returns(true)
10
+ subject.should == "apple"
11
+ end
12
+
13
+ it "should return true on success" do
14
+ subject = "apple"
15
+ (subject.should == "apple").should be_true
16
+ end
17
+
18
+ it "should fail when target.==(actual) returns false" do
19
+ subject = "apple"
20
+ Micronaut::Expectations.expects(:fail_with).with(%[expected: "orange",\n got: "apple" (using ==)], "orange", "apple")
21
+ subject.should == "orange"
22
+ end
23
+
24
+ end
25
+
26
+ describe "should_not ==" do
27
+
28
+ it "should delegate message to target" do
29
+ subject = "orange"
30
+ subject.expects(:==).with("apple").returns(false)
31
+ subject.should_not == "apple"
32
+ end
33
+
34
+ it "should return true on success" do
35
+ subject = "apple"
36
+ (subject.should_not == "orange").should be_true
37
+ end
38
+
39
+ it "should fail when target.==(actual) returns false" do
40
+ subject = "apple"
41
+ Micronaut::Expectations.expects(:fail_with).with(%[expected not: == "apple",\n got: "apple"], "apple", "apple")
42
+ subject.should_not == "apple"
43
+ end
44
+
45
+ end
46
+
47
+ describe "should ===" do
48
+
49
+ it "should delegate message to target" do
50
+ subject = "apple"
51
+ subject.expects(:===).with("apple").returns(true)
52
+ subject.should === "apple"
53
+ end
54
+
55
+ it "should fail when target.===(actual) returns false" do
56
+ subject = "apple"
57
+ subject.expects(:===).with("orange").returns(false)
58
+ Micronaut::Expectations.expects(:fail_with).with(%[expected: "orange",\n got: "apple" (using ===)], "orange", "apple")
59
+ subject.should === "orange"
60
+ end
61
+
62
+ end
63
+
64
+ describe "should_not ===" do
65
+
66
+ it "should delegate message to target" do
67
+ subject = "orange"
68
+ subject.expects(:===).with("apple").returns(false)
69
+ subject.should_not === "apple"
70
+ end
71
+
72
+ it "should fail when target.===(actual) returns false" do
73
+ subject = "apple"
74
+ subject.expects(:===).with("apple").returns(true)
75
+ Micronaut::Expectations.expects(:fail_with).with(%[expected not: === "apple",\n got: "apple"], "apple", "apple")
76
+ subject.should_not === "apple"
77
+ end
78
+
79
+ end
80
+
81
+ describe "should =~" do
82
+
83
+ it "should delegate message to target" do
84
+ subject = "foo"
85
+ subject.expects(:=~).with(/oo/).returns(true)
86
+ subject.should =~ /oo/
87
+ end
88
+
89
+ it "should fail when target.=~(actual) returns false" do
90
+ subject = "fu"
91
+ subject.expects(:=~).with(/oo/).returns(false)
92
+ Micronaut::Expectations.expects(:fail_with).with(%[expected: /oo/,\n got: "fu" (using =~)], /oo/, "fu")
93
+ subject.should =~ /oo/
94
+ end
95
+
96
+ end
97
+
98
+ describe "should_not =~" do
99
+
100
+ it "should delegate message to target" do
101
+ subject = "fu"
102
+ subject.expects(:=~).with(/oo/).returns(false)
103
+ subject.should_not =~ /oo/
104
+ end
105
+
106
+ it "should fail when target.=~(actual) returns false" do
107
+ subject = "foo"
108
+ subject.expects(:=~).with(/oo/).returns(true)
109
+ Micronaut::Expectations.expects(:fail_with).with(%[expected not: =~ /oo/,\n got: "foo"], /oo/, "foo")
110
+ subject.should_not =~ /oo/
111
+ end
112
+
113
+ end
114
+
115
+ describe "should >" do
116
+
117
+ it "should pass if > passes" do
118
+ 4.should > 3
119
+ end
120
+
121
+ it "should fail if > fails" do
122
+ Micronaut::Expectations.expects(:fail_with).with(%[expected: > 5,\n got: 4], 5, 4)
123
+ 4.should > 5
124
+ end
125
+
126
+ end
127
+
128
+ describe "should >=" do
129
+
130
+ it "should pass if >= passes" do
131
+ 4.should > 3
132
+ 4.should >= 4
133
+ end
134
+
135
+ it "should fail if > fails" do
136
+ Micronaut::Expectations.expects(:fail_with).with(%[expected: >= 5,\n got: 4], 5, 4)
137
+ 4.should >= 5
138
+ end
139
+
140
+ end
141
+
142
+ describe "should <" do
143
+
144
+ it "should pass if < passes" do
145
+ 4.should < 5
146
+ end
147
+
148
+ it "should fail if > fails" do
149
+ Micronaut::Expectations.expects(:fail_with).with(%[expected: < 3,\n got: 4], 3, 4)
150
+ 4.should < 3
151
+ end
152
+
153
+ end
154
+
155
+ describe "should <=" do
156
+
157
+ it "should pass if <= passes" do
158
+ 4.should <= 5
159
+ 4.should <= 4
160
+ end
161
+
162
+ it "should fail if > fails" do
163
+ Micronaut::Expectations.expects(:fail_with).with(%[expected: <= 3,\n got: 4], 3, 4)
164
+ 4.should <= 3
165
+ end
166
+
167
+ end
168
+
169
+ describe Micronaut::Matchers::PositiveOperatorMatcher do
170
+
171
+ it "should work when the target has implemented #send" do
172
+ o = Object.new
173
+ def o.send(*args); raise "DOH! Library developers shouldn't use #send!" end
174
+ lambda {
175
+ o.should == o
176
+ }.should_not raise_error
177
+ end
178
+
179
+ end
180
+
181
+ describe Micronaut::Matchers::NegativeOperatorMatcher do
182
+
183
+ it "should work when the target has implemented #send" do
184
+ o = Object.new
185
+ def o.send(*args); raise "DOH! Library developers shouldn't use #send!" end
186
+ lambda {
187
+ o.should_not == :foo
188
+ }.should_not raise_error
189
+ end
190
+
191
+ end
192
+
193
+ end
@@ -0,0 +1,348 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")
2
+
3
+ describe Micronaut::Matchers, "raise_error" do
4
+
5
+ describe "should raise_error" do
6
+
7
+ it "should pass if anything is raised" do
8
+ lambda {raise}.should raise_error
9
+ end
10
+
11
+ it "should fail if nothing is raised" do
12
+ lambda {
13
+ lambda {}.should raise_error
14
+ }.should fail_with("expected Exception but nothing was raised")
15
+ end
16
+
17
+ end
18
+
19
+ describe "should_not raise_error" do
20
+
21
+ it "should pass if nothing is raised" do
22
+ lambda {}.should_not raise_error
23
+ end
24
+
25
+ it "should fail if anything is raised" do
26
+ lambda {
27
+ lambda {raise}.should_not raise_error
28
+ }.should fail_with("expected no Exception, got RuntimeError")
29
+ end
30
+
31
+ end
32
+
33
+ describe "should raise_error(message)" do
34
+
35
+ it "should pass if RuntimeError is raised with the right message" do
36
+ lambda {raise 'blah'}.should raise_error('blah')
37
+ end
38
+
39
+ it "should pass if RuntimeError is raised with a matching message" do
40
+ lambda {raise 'blah'}.should raise_error(/blah/)
41
+ end
42
+
43
+ it "should pass if any other error is raised with the right message" do
44
+ lambda {raise NameError.new('blah')}.should raise_error('blah')
45
+ end
46
+
47
+ it "should fail if RuntimeError error is raised with the wrong message" do
48
+ lambda do
49
+ lambda {raise 'blarg'}.should raise_error('blah')
50
+ end.should fail_with("expected Exception with \"blah\", got #<RuntimeError: blarg>")
51
+ end
52
+
53
+ it "should fail if any other error is raised with the wrong message" do
54
+ lambda do
55
+ lambda {raise NameError.new('blarg')}.should raise_error('blah')
56
+ end.should fail_with("expected Exception with \"blah\", got #<NameError: blarg>")
57
+ end
58
+
59
+ end
60
+
61
+ describe "should_not raise_error(message)" do
62
+
63
+ it "should pass if RuntimeError error is raised with the different message" do
64
+ lambda {raise 'blarg'}.should_not raise_error('blah')
65
+ end
66
+
67
+ it "should pass if any other error is raised with the wrong message" do
68
+ lambda {raise NameError.new('blarg')}.should_not raise_error('blah')
69
+ end
70
+
71
+ it "should fail if RuntimeError is raised with message" do
72
+ lambda do
73
+ lambda {raise 'blah'}.should_not raise_error('blah')
74
+ end.should fail_with(%Q|expected no Exception with "blah", got #<RuntimeError: blah>|)
75
+ end
76
+
77
+ it "should fail if any other error is raised with message" do
78
+ lambda do
79
+ lambda {raise NameError.new('blah')}.should_not raise_error('blah')
80
+ end.should fail_with(%Q|expected no Exception with "blah", got #<NameError: blah>|)
81
+ end
82
+
83
+ end
84
+
85
+ describe "should raise_error(NamedError)" do
86
+
87
+ it "should pass if named error is raised" do
88
+ lambda { non_existent_method }.should raise_error(NameError)
89
+ end
90
+
91
+ it "should fail if nothing is raised" do
92
+ lambda {
93
+ lambda { }.should raise_error(NameError)
94
+ }.should fail_with("expected NameError but nothing was raised")
95
+ end
96
+
97
+ it "should fail if another error is raised (NameError)" do
98
+ lambda {
99
+ lambda { raise }.should raise_error(NameError)
100
+ }.should fail_with("expected NameError, got RuntimeError")
101
+ end
102
+
103
+ it "should fail if another error is raised (NameError)" do
104
+ lambda {
105
+ lambda { load "non/existent/file" }.should raise_error(NameError)
106
+ }.should fail_with(/expected NameError, got #<LoadError/)
107
+ end
108
+
109
+ end
110
+
111
+ describe "should_not raise_error(NamedError)" do
112
+
113
+ it "should pass if nothing is raised" do
114
+ lambda { }.should_not raise_error(NameError)
115
+ end
116
+
117
+ it "should pass if another error is raised" do
118
+ lambda { raise }.should_not raise_error(NameError)
119
+ end
120
+
121
+ it "should fail if named error is raised" do
122
+ lambda {
123
+ lambda { non_existent_method }.should_not raise_error(NameError)
124
+ }.should fail_with(/expected no NameError, got #<NameError: undefined/)
125
+ end
126
+
127
+ end
128
+
129
+ describe "should raise_error(NamedError, error_message) with String" do
130
+
131
+ it "should pass if named error is raised with same message" do
132
+ lambda { raise "example message" }.should raise_error(RuntimeError, "example message")
133
+ end
134
+
135
+ it "should fail if nothing is raised" do
136
+ lambda {
137
+ lambda {}.should raise_error(RuntimeError, "example message")
138
+ }.should fail_with("expected RuntimeError with \"example message\" but nothing was raised")
139
+ end
140
+
141
+ it "should fail if incorrect error is raised" do
142
+ lambda {
143
+ lambda { raise }.should raise_error(NameError, "example message")
144
+ }.should fail_with("expected NameError with \"example message\", got RuntimeError")
145
+ end
146
+
147
+ it "should fail if correct error is raised with incorrect message" do
148
+ lambda {
149
+ lambda { raise RuntimeError.new("not the example message") }.should raise_error(RuntimeError, "example message")
150
+ }.should fail_with(/expected RuntimeError with \"example message\", got #<RuntimeError: not the example message/)
151
+ end
152
+
153
+ end
154
+
155
+ describe "should raise_error(NamedError, error_message) { |err| ... }" do
156
+
157
+ it "should yield exception if named error is raised with same message" do
158
+ ran = false
159
+
160
+ lambda {
161
+ raise "example message"
162
+ }.should raise_error(RuntimeError, "example message") { |err|
163
+ ran = true
164
+ err.class.should == RuntimeError
165
+ err.message.should == "example message"
166
+ }
167
+
168
+ ran.should == true
169
+ end
170
+
171
+ it "yielded block should be able to fail on it's own right" do
172
+ ran, passed = false, false
173
+
174
+ lambda {
175
+ lambda { raise "example message" }.should raise_error(RuntimeError, "example message") { |err|
176
+ ran = true
177
+ 5.should == 4
178
+ passed = true
179
+ }
180
+ }.should fail_with(/expected: 4/m)
181
+
182
+ ran.should == true
183
+ passed.should == false
184
+ end
185
+
186
+ it "should NOT yield exception if no error was thrown" do
187
+ ran = false
188
+
189
+ lambda {
190
+ lambda {}.should raise_error(RuntimeError, "example message") { |err|
191
+ ran = true
192
+ }
193
+ }.should fail_with("expected RuntimeError with \"example message\" but nothing was raised")
194
+
195
+ ran.should == false
196
+ end
197
+
198
+ it "should not yield exception if error class is not matched" do
199
+ ran = false
200
+
201
+ lambda {
202
+ lambda {
203
+ raise "example message"
204
+ }.should raise_error(SyntaxError, "example message") { |err|
205
+ ran = true
206
+ }
207
+ }.should fail_with("expected SyntaxError with \"example message\", got #<RuntimeError: example message>")
208
+
209
+ ran.should == false
210
+ end
211
+
212
+ it "should NOT yield exception if error message is not matched" do
213
+ ran = false
214
+
215
+ lambda {
216
+ lambda {
217
+ raise "example message"
218
+ }.should raise_error(RuntimeError, "different message") { |err|
219
+ ran = true
220
+ }
221
+ }.should fail_with("expected RuntimeError with \"different message\", got #<RuntimeError: example message>")
222
+
223
+ ran.should == false
224
+ end
225
+
226
+ end
227
+
228
+ describe "should_not raise_error(NamedError, error_message) { |err| ... }" do
229
+
230
+ it "should pass if nothing is raised" do
231
+ ran = false
232
+
233
+ lambda {}.should_not raise_error(RuntimeError, "example message") { |err|
234
+ ran = true
235
+ }
236
+
237
+ ran.should == false
238
+ end
239
+
240
+ it "should pass if a different error is raised" do
241
+ ran = false
242
+
243
+ lambda { raise }.should_not raise_error(NameError, "example message") { |err|
244
+ ran = true
245
+ }
246
+
247
+ ran.should == false
248
+ end
249
+
250
+ it "should pass if same error is raised with different message" do
251
+ ran = false
252
+
253
+ lambda {
254
+ raise RuntimeError.new("not the example message")
255
+ }.should_not raise_error(RuntimeError, "example message") { |err|
256
+ ran = true
257
+ }
258
+
259
+ ran.should == false
260
+ end
261
+
262
+ it "should fail if named error is raised with same message" do
263
+ ran = false
264
+
265
+ lambda {
266
+ lambda {
267
+ raise "example message"
268
+ }.should_not raise_error(RuntimeError, "example message") { |err|
269
+ ran = true
270
+ }
271
+ }.should fail_with("expected no RuntimeError with \"example message\", got #<RuntimeError: example message>")
272
+
273
+ ran.should == false
274
+ end
275
+
276
+ end
277
+
278
+ describe "should_not raise_error(NamedError, error_message) with String" do
279
+
280
+ it "should pass if nothing is raised" do
281
+ lambda {}.should_not raise_error(RuntimeError, "example message")
282
+ end
283
+
284
+ it "should pass if a different error is raised" do
285
+ lambda { raise }.should_not raise_error(NameError, "example message")
286
+ end
287
+
288
+ it "should pass if same error is raised with different message" do
289
+ lambda { raise RuntimeError.new("not the example message") }.should_not raise_error(RuntimeError, "example message")
290
+ end
291
+
292
+ it "should fail if named error is raised with same message" do
293
+ lambda {
294
+ lambda { raise "example message" }.should_not raise_error(RuntimeError, "example message")
295
+ }.should fail_with("expected no RuntimeError with \"example message\", got #<RuntimeError: example message>")
296
+ end
297
+
298
+ end
299
+
300
+ describe "should raise_error(NamedError, error_message) with Regexp" do
301
+
302
+ it "should pass if named error is raised with matching message" do
303
+ lambda { raise "example message" }.should raise_error(RuntimeError, /ample mess/)
304
+ end
305
+
306
+ it "should fail if nothing is raised" do
307
+ lambda {
308
+ lambda {}.should raise_error(RuntimeError, /ample mess/)
309
+ }.should fail_with("expected RuntimeError with message matching /ample mess/ but nothing was raised")
310
+ end
311
+
312
+ it "should fail if incorrect error is raised" do
313
+ lambda {
314
+ lambda { raise }.should raise_error(NameError, /ample mess/)
315
+ }.should fail_with("expected NameError with message matching /ample mess/, got RuntimeError")
316
+ end
317
+
318
+ it "should fail if correct error is raised with incorrect message" do
319
+ lambda {
320
+ lambda { raise RuntimeError.new("not the example message") }.should raise_error(RuntimeError, /less than ample mess/)
321
+ }.should fail_with("expected RuntimeError with message matching /less than ample mess/, got #<RuntimeError: not the example message>")
322
+ end
323
+
324
+ end
325
+
326
+ describe "should_not raise_error(NamedError, error_message) with Regexp" do
327
+
328
+ it "should pass if nothing is raised" do
329
+ lambda {}.should_not raise_error(RuntimeError, /ample mess/)
330
+ end
331
+
332
+ it "should pass if a different error is raised" do
333
+ lambda { raise }.should_not raise_error(NameError, /ample mess/)
334
+ end
335
+
336
+ it "should pass if same error is raised with non-matching message" do
337
+ lambda { raise RuntimeError.new("non matching message") }.should_not raise_error(RuntimeError, /ample mess/)
338
+ end
339
+
340
+ it "should fail if named error is raised with matching message" do
341
+ lambda {
342
+ lambda { raise "example message" }.should_not raise_error(RuntimeError, /ample mess/)
343
+ }.should fail_with("expected no RuntimeError with message matching /ample mess/, got #<RuntimeError: example message>")
344
+ end
345
+
346
+ end
347
+
348
+ end