rspec 1.1.3 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. data/CHANGES +35 -0
  2. data/MIT-LICENSE +1 -1
  3. data/README +9 -44
  4. data/Rakefile +34 -51
  5. data/TODO +0 -1
  6. data/UPGRADE +0 -24
  7. data/bin/spec +0 -0
  8. data/bin/spec_translator +0 -0
  9. data/examples/pure/behave_as_example.rb +0 -0
  10. data/examples/pure/partial_mock_example.rb +1 -0
  11. data/examples/stories/calculator.rb +1 -1
  12. data/lib/autotest/rspec.rb +7 -9
  13. data/lib/spec/example.rb +1 -1
  14. data/lib/spec/example/configuration.rb +30 -16
  15. data/lib/spec/example/example_group.rb +2 -1
  16. data/lib/spec/example/example_group_factory.rb +23 -21
  17. data/lib/spec/example/example_group_methods.rb +18 -5
  18. data/lib/spec/example/example_matcher.rb +0 -0
  19. data/lib/spec/example/example_methods.rb +6 -0
  20. data/lib/spec/example/module_inclusion_warnings.rb +37 -0
  21. data/lib/spec/expectations/differs/default.rb +1 -1
  22. data/lib/spec/expectations/extensions/object.rb +4 -12
  23. data/lib/spec/expectations/handler.rb +8 -0
  24. data/lib/spec/extensions.rb +1 -0
  25. data/lib/spec/extensions/metaclass.rb +7 -0
  26. data/lib/spec/extensions/object.rb +0 -4
  27. data/lib/spec/matchers/change.rb +1 -1
  28. data/lib/spec/matchers/has.rb +1 -11
  29. data/lib/spec/matchers/operator_matcher.rb +0 -0
  30. data/lib/spec/matchers/raise_error.rb +53 -30
  31. data/lib/spec/mocks.rb +1 -1
  32. data/lib/spec/mocks/argument_constraint_matchers.rb +5 -1
  33. data/lib/spec/mocks/argument_expectation.rb +26 -0
  34. data/lib/spec/mocks/extensions.rb +1 -0
  35. data/lib/spec/mocks/framework.rb +15 -0
  36. data/lib/spec/mocks/message_expectation.rb +29 -5
  37. data/lib/spec/mocks/mock.rb +9 -7
  38. data/lib/spec/mocks/proxy.rb +26 -12
  39. data/lib/spec/rake/spectask.rb +5 -5
  40. data/lib/spec/runner/backtrace_tweaker.rb +1 -1
  41. data/lib/spec/runner/formatter/base_formatter.rb +2 -3
  42. data/lib/spec/runner/formatter/base_text_formatter.rb +2 -2
  43. data/lib/spec/runner/formatter/failing_example_groups_formatter.rb +4 -8
  44. data/lib/spec/runner/formatter/html_formatter.rb +18 -14
  45. data/lib/spec/runner/formatter/nested_text_formatter.rb +65 -0
  46. data/lib/spec/runner/formatter/profile_formatter.rb +4 -0
  47. data/lib/spec/runner/formatter/progress_bar_formatter.rb +5 -1
  48. data/lib/spec/runner/formatter/specdoc_formatter.rb +1 -1
  49. data/lib/spec/runner/formatter/story/plain_text_formatter.rb +18 -7
  50. data/lib/spec/runner/option_parser.rb +17 -15
  51. data/lib/spec/runner/options.rb +37 -14
  52. data/lib/spec/runner/reporter.rb +15 -11
  53. data/lib/spec/story/extensions/regexp.rb +2 -2
  54. data/lib/spec/story/extensions/string.rb +2 -2
  55. data/lib/spec/story/runner.rb +9 -5
  56. data/lib/spec/story/runner/plain_text_story_runner.rb +2 -2
  57. data/lib/spec/story/runner/scenario_runner.rb +8 -0
  58. data/lib/spec/story/runner/story_mediator.rb +1 -1
  59. data/lib/spec/story/runner/story_runner.rb +3 -1
  60. data/lib/spec/story/step.rb +4 -4
  61. data/lib/spec/story/story.rb +8 -11
  62. data/lib/spec/story/world.rb +0 -1
  63. data/lib/spec/version.rb +2 -2
  64. data/plugins/mock_frameworks/rspec.rb +2 -0
  65. data/spec/autotest/rspec_spec.rb +12 -10
  66. data/spec/spec/example/configuration_spec.rb +0 -0
  67. data/spec/spec/example/example_group/described_module_spec.rb +20 -0
  68. data/spec/spec/example/example_group/warning_messages_spec.rb +76 -0
  69. data/spec/spec/example/example_group_factory_spec.rb +117 -102
  70. data/spec/spec/example/example_group_methods_spec.rb +51 -17
  71. data/spec/spec/example/example_group_spec.rb +13 -1
  72. data/spec/spec/example/example_methods_spec.rb +28 -6
  73. data/spec/spec/example/nested_example_group_spec.rb +12 -0
  74. data/spec/spec/example/predicate_matcher_spec.rb +0 -0
  75. data/spec/spec/expectations/differs/default_spec.rb +27 -9
  76. data/spec/spec/matchers/be_spec.rb +24 -0
  77. data/spec/spec/matchers/has_spec.rb +16 -0
  78. data/spec/spec/matchers/raise_error_spec.rb +124 -0
  79. data/spec/spec/mocks/{bug_report_10263.rb → bug_report_10263_spec.rb} +0 -0
  80. data/spec/spec/mocks/bug_report_11545_spec.rb +2 -0
  81. data/spec/spec/mocks/failing_mock_argument_constraints_spec.rb +8 -0
  82. data/spec/spec/mocks/hash_including_matcher_spec.rb +32 -0
  83. data/spec/spec/mocks/mock_spec.rb +56 -37
  84. data/spec/spec/mocks/partial_mock_spec.rb +41 -5
  85. data/spec/spec/mocks/passing_mock_argument_constraints_spec.rb +6 -0
  86. data/spec/spec/runner/execution_context_spec.rb +7 -1
  87. data/spec/spec/runner/formatter/failing_example_groups_formatter_spec.rb +3 -2
  88. data/spec/spec/runner/formatter/html_formatted-1.8.6.html +30 -25
  89. data/spec/spec/runner/formatter/html_formatter_spec.rb +0 -3
  90. data/spec/spec/runner/formatter/nested_text_formatter_spec.rb +333 -0
  91. data/spec/spec/runner/formatter/progress_bar_formatter_spec.rb +12 -2
  92. data/spec/spec/runner/formatter/spec_mate_formatter_spec.rb +2 -2
  93. data/spec/spec/runner/formatter/specdoc_formatter_spec.rb +110 -78
  94. data/spec/spec/runner/formatter/story/plain_text_formatter_spec.rb +105 -1
  95. data/spec/spec/runner/formatter/text_mate_formatted-1.8.6.html +33 -28
  96. data/spec/spec/runner/option_parser_spec.rb +65 -49
  97. data/spec/spec/runner/options_spec.rb +103 -17
  98. data/spec/spec/runner/reporter_spec.rb +10 -7
  99. data/spec/spec/runner/spec_drb.opts +1 -0
  100. data/spec/spec/runner/spec_parser_spec.rb +10 -4
  101. data/spec/spec/story/runner/plain_text_story_runner_spec.rb +14 -13
  102. data/spec/spec/story/runner/scenario_runner_spec.rb +124 -52
  103. data/spec/spec/story/runner/story_mediator_spec.rb +2 -2
  104. data/spec/spec/story/runner/story_runner_spec.rb +40 -2
  105. data/spec/spec/story/runner_spec.rb +59 -72
  106. data/spec/spec/story/step_spec.rb +20 -1
  107. data/spec/spec/story/story_spec.rb +2 -2
  108. data/stories/all.rb +1 -1
  109. data/stories/example_groups/stories.rb +4 -3
  110. data/stories/mock_framework_integration/stories.rb +7 -0
  111. data/stories/mock_framework_integration/use_flexmock.story +9 -0
  112. data/stories/resources/spec/spec_with_flexmock.rb +18 -0
  113. metadata +21 -18
  114. data/pre_commit/lib/pre_commit.rb +0 -4
  115. data/pre_commit/lib/pre_commit/core.rb +0 -50
  116. data/pre_commit/lib/pre_commit/pre_commit.rb +0 -54
  117. data/pre_commit/lib/pre_commit/rspec.rb +0 -111
  118. data/pre_commit/lib/pre_commit/rspec_on_rails.rb +0 -313
  119. data/pre_commit/spec/pre_commit/pre_commit_spec.rb +0 -15
  120. data/pre_commit/spec/pre_commit/rspec_on_rails_spec.rb +0 -36
  121. data/pre_commit/spec/spec_helper.rb +0 -3
  122. data/pre_commit/spec/spec_suite.rb +0 -11
@@ -24,26 +24,53 @@ module Spec
24
24
  ExampleGroup.reset
25
25
  end
26
26
 
27
- describe "#describe" do
28
- attr_reader :child_example_group
29
- before do
30
- @child_example_group = @example_group.describe("Another ExampleGroup") do
31
- it "should pass" do
32
- true.should be_true
27
+ ["describe","context"].each do |method|
28
+ describe "#{method}" do
29
+ describe "when creating an ExampleGroup" do
30
+ attr_reader :child_example_group
31
+ before do
32
+ @child_example_group = @example_group.send method, "Another ExampleGroup" do
33
+ it "should pass" do
34
+ true.should be_true
35
+ end
36
+ end
37
+ end
38
+
39
+ it "should create a subclass of the ExampleGroup when passed a block" do
40
+ child_example_group.superclass.should == @example_group
41
+ @options.example_groups.should include(child_example_group)
42
+ end
43
+
44
+ it "should not inherit examples" do
45
+ child_example_group.examples.length.should == 1
33
46
  end
34
47
  end
35
- end
36
48
 
37
- it "should create a subclass of the ExampleGroup when passed a block" do
38
- child_example_group.superclass.should == @example_group
39
- @options.example_groups.should include(child_example_group)
40
- end
49
+ describe "when creating a SharedExampleGroup" do
50
+ attr_reader :name, :shared_example_group
51
+ before do
52
+ @name = "A Shared ExampleGroup"
53
+ @shared_example_group = @example_group.send method, name, :shared => true do
54
+ it "should pass" do
55
+ true.should be_true
56
+ end
57
+ end
58
+ end
59
+
60
+ after do
61
+ SharedExampleGroup.shared_example_groups.delete_if do |registered_shared_example_group|
62
+ registered_shared_example_group == shared_example_group
63
+ end
64
+ end
65
+
66
+ it "should create a SharedExampleGroup" do
67
+ SharedExampleGroup.find_shared_example_group(name).should == shared_example_group
68
+ end
69
+ end
41
70
 
42
- it "should not inherit examples" do
43
- child_example_group.examples.length.should == 1
44
71
  end
45
72
  end
46
-
73
+
47
74
  describe "#it" do
48
75
  it "should should create an example instance" do
49
76
  lambda {
@@ -52,20 +79,25 @@ module Spec
52
79
  end
53
80
  end
54
81
 
55
- describe "#xit" do
82
+ describe "#xit and #xspecify" do
56
83
  before(:each) do
57
84
  Kernel.stub!(:warn)
58
85
  end
59
86
 
60
- it "should NOT should create an example instance" do
87
+ it "should NOT create an example instance" do
61
88
  lambda {
62
89
  @example_group.xit("")
63
90
  }.should_not change(@example_group.examples, :length)
91
+
92
+ lambda {
93
+ @example_group.xspecify("")
94
+ }.should_not change(@example_group.examples, :length)
64
95
  end
65
96
 
66
97
  it "should warn that it is disabled" do
67
- Kernel.should_receive(:warn).with("Example disabled: foo")
98
+ Kernel.should_receive(:warn).with("Example disabled: foo").twice
68
99
  @example_group.xit("foo")
100
+ @example_group.xspecify("foo")
69
101
  end
70
102
  end
71
103
 
@@ -395,6 +427,7 @@ module Spec
395
427
  it "should have accessible class methods from included module" do
396
428
  mod1_method_called = false
397
429
  mod1 = Module.new do
430
+ extend Spec::MetaClass
398
431
  class_methods = Module.new do
399
432
  define_method :mod1_method do
400
433
  mod1_method_called = true
@@ -410,6 +443,7 @@ module Spec
410
443
 
411
444
  mod2_method_called = false
412
445
  mod2 = Module.new do
446
+ extend Spec::MetaClass
413
447
  class_methods = Module.new do
414
448
  define_method :mod2_method do
415
449
  mod2_method_called = true
@@ -673,6 +673,10 @@ module Spec
673
673
  end
674
674
 
675
675
  describe Enumerable do
676
+ before(:each) do
677
+ Kernel.stub!(:warn)
678
+ end
679
+
676
680
  def each(&block)
677
681
  ["4", "2", "1"].each(&block)
678
682
  end
@@ -683,6 +687,10 @@ module Spec
683
687
  end
684
688
 
685
689
  describe "An", Enumerable, "as a second argument" do
690
+ before(:each) do
691
+ Kernel.stub!(:warn)
692
+ end
693
+
686
694
  def each(&block)
687
695
  ["4", "2", "1"].each(&block)
688
696
  end
@@ -694,6 +702,10 @@ module Spec
694
702
 
695
703
  describe Enumerable do
696
704
  describe "as the parent of nested example groups" do
705
+ before(:each) do
706
+ Kernel.stub!(:warn)
707
+ end
708
+
697
709
  it "should be included in examples because it is a module" do
698
710
  pending("need to make sure nested groups know the described type") do
699
711
  map{|e| e.to_i}.should == [4,2,1]
@@ -703,7 +715,7 @@ module Spec
703
715
  end
704
716
 
705
717
  describe String do
706
- it"should not be included in examples because it is not a module" do
718
+ it "should not be included in examples because it is not a module" do
707
719
  lambda{self.map}.should raise_error(NoMethodError, /undefined method `map' for/)
708
720
  end
709
721
  end
@@ -23,7 +23,9 @@ module Spec
23
23
 
24
24
  describe "lifecycle" do
25
25
  before do
26
+ @original_rspec_options = $rspec_options
26
27
  @options = ::Spec::Runner::Options.new(StringIO.new, StringIO.new)
28
+ $rspec_options = @options
27
29
  @options.formatters << mock("formatter", :null_object => true)
28
30
  @options.backtrace_tweaker = mock("backtrace_tweaker", :null_object => true)
29
31
  @reporter = FakeReporter.new(@options)
@@ -41,6 +43,7 @@ module Spec
41
43
  end
42
44
 
43
45
  after do
46
+ $rspec_options = @original_rspec_options
44
47
  ExampleMethods.instance_variable_set("@before_all_parts", [])
45
48
  ExampleMethods.instance_variable_set("@before_each_parts", [])
46
49
  ExampleMethods.instance_variable_set("@after_each_parts", [])
@@ -48,28 +51,36 @@ module Spec
48
51
  end
49
52
 
50
53
  it "should pass before and after callbacks to all ExampleGroup subclasses" do
51
- ExampleMethods.before(:all) do
54
+ ExampleMethods.before(:suite) do
52
55
  ExampleMethods.count.should == 1
53
56
  end
54
57
 
55
- ExampleMethods.before(:each) do
58
+ ExampleMethods.before(:all) do
56
59
  ExampleMethods.count.should == 2
57
60
  end
58
61
 
59
- ExampleMethods.after(:each) do
62
+ ExampleMethods.before(:each) do
60
63
  ExampleMethods.count.should == 3
61
64
  end
62
65
 
63
- ExampleMethods.after(:all) do
66
+ ExampleMethods.after(:each) do
64
67
  ExampleMethods.count.should == 4
65
68
  end
66
69
 
70
+ ExampleMethods.after(:all) do
71
+ ExampleMethods.count.should == 5
72
+ end
73
+
74
+ ExampleMethods.after(:suite) do
75
+ ExampleMethods.count.should == 6
76
+ end
77
+
67
78
  @example_group = Class.new(ExampleGroup) do
68
79
  it "should use ExampleMethods callbacks" do
69
80
  end
70
81
  end
71
- @example_group.run
72
- ExampleMethods.count.should == 5
82
+ @options.run_examples
83
+ ExampleMethods.count.should == 7
73
84
  end
74
85
 
75
86
  describe "run_with_description_capturing" do
@@ -99,6 +110,17 @@ module Spec
99
110
  example.implementation_backtrace.join("\n").should include("#{__FILE__}:#{__LINE__-4}")
100
111
  end
101
112
  end
113
+
114
+ describe "#__full_description" do
115
+ it "should return the full description of the ExampleGroup and Example" do
116
+ example_group = Class.new(ExampleGroup).describe("An ExampleGroup") do
117
+ it "should do something" do
118
+ end
119
+ end
120
+ example = example_group.examples.first
121
+ example.__full_description.should == "An ExampleGroup should do something"
122
+ end
123
+ end
102
124
  end
103
125
  end
104
126
  end
@@ -55,5 +55,17 @@ module Spec
55
55
  end
56
56
  end
57
57
  end
58
+
59
+ describe "Nested Example Groups" do
60
+ describe "description options", :other_options => "other options" do
61
+ it "should have a spec_path" do
62
+ self.class.description_options[:spec_path].should match(/#{__FILE__}/)
63
+ end
64
+
65
+ it "should pass other options" do
66
+ self.class.description_options[:other_options].should == "other options"
67
+ end
68
+ end
69
+ end
58
70
  end
59
71
  end
File without changes
@@ -28,7 +28,25 @@ describe "Diff" do
28
28
  it "should output unified diff of two strings" do
29
29
  expected="foo\nbar\nzap\nthis\nis\nsoo\nvery\nvery\nequal\ninsert\na\nline\n"
30
30
  actual="foo\nzap\nbar\nthis\nis\nsoo\nvery\nvery\nequal\ninsert\na\nanother\nline\n"
31
- expected_diff="\n\n@@ -1,6 +1,6 @@\n foo\n-bar\n zap\n+bar\n this\n is\n soo\n@@ -9,5 +9,6 @@\n equal\n insert\n a\n+another\n line\n"
31
+ expected_diff= <<'EOD'
32
+
33
+
34
+ @@ -1,6 +1,6 @@
35
+ foo
36
+ -zap
37
+ bar
38
+ +zap
39
+ this
40
+ is
41
+ soo
42
+ @@ -9,6 +9,5 @@
43
+ equal
44
+ insert
45
+ a
46
+ -another
47
+ line
48
+ EOD
49
+
32
50
  diff = @differ.diff_as_string(expected, actual)
33
51
  diff.should eql(expected_diff)
34
52
  end
@@ -44,11 +62,11 @@ describe "Diff" do
44
62
  :metasyntactic,
45
63
  "variable",
46
64
  :delta,
47
- - "charlie",
48
- + "tango",
65
+ - "tango",
66
+ + "charlie",
49
67
  :width,
50
- - "quite wide"]
51
- + "very wide"]
68
+ - "very wide"]
69
+ + "quite wide"]
52
70
  EOD
53
71
 
54
72
 
@@ -65,8 +83,8 @@ EOD
65
83
  @@ -1,5 +1,5 @@
66
84
  <Animal
67
85
  name=bob,
68
- - species=giraffe
69
- + species=tortoise
86
+ - species=tortoise
87
+ + species=giraffe
70
88
  >
71
89
  EOD
72
90
 
@@ -94,12 +112,12 @@ describe "Diff in context format" do
94
112
  *** 1,5 ****
95
113
  <Animal
96
114
  name=bob,
97
- ! species=giraffe
115
+ ! species=tortoise
98
116
  >
99
117
  --- 1,5 ----
100
118
  <Animal
101
119
  name=bob,
102
- ! species=tortoise
120
+ ! species=giraffe
103
121
  >
104
122
  EOD
105
123
 
@@ -222,3 +222,27 @@ describe "should be(value)" do
222
222
  lambda { 5.should be(6) }.should fail_with("expected 6, got 5")
223
223
  end
224
224
  end
225
+
226
+
227
+ describe "arbitrary predicate with DelegateClass" do
228
+ it "should access methods defined in the delegating class (LH[#48])" do
229
+ pending(%{
230
+ Looks like DelegateClass is delegating #should to the
231
+ delegate. Not sure how to fix this one. Or if we even should."
232
+ })
233
+ require 'delegate'
234
+ class ArrayDelegate < DelegateClass(Array)
235
+ def initialize(array)
236
+ @internal_array = array
237
+ super(@internal_array)
238
+ end
239
+
240
+ def large?
241
+ @internal_array.size >= 5
242
+ end
243
+ end
244
+
245
+ delegate = ArrayDelegate.new([1,2,3,4,5,6])
246
+ delegate.should be_large
247
+ end
248
+ end
@@ -16,6 +16,14 @@ describe "should have_sym(*args)" do
16
16
  Object.new.should have_key(:a)
17
17
  }.should raise_error(NoMethodError)
18
18
  end
19
+
20
+ it "should reraise an exception thrown in #has_sym?(*args)" do
21
+ o = Object.new
22
+ def o.has_sym?(*args)
23
+ raise "Funky exception"
24
+ end
25
+ lambda { o.should have_sym(:foo) }.should raise_error("Funky exception")
26
+ end
19
27
  end
20
28
 
21
29
  describe "should_not have_sym(*args)" do
@@ -34,4 +42,12 @@ describe "should_not have_sym(*args)" do
34
42
  Object.new.should have_key(:a)
35
43
  }.should raise_error(NoMethodError)
36
44
  end
45
+
46
+ it "should reraise an exception thrown in #has_sym?(*args)" do
47
+ o = Object.new
48
+ def o.has_sym?(*args)
49
+ raise "Funky exception"
50
+ end
51
+ lambda { o.should_not have_sym(:foo) }.should raise_error("Funky exception")
52
+ end
37
53
  end
@@ -28,6 +28,9 @@ describe "should raise_error(message)" do
28
28
  it "should pass if RuntimeError is raised with the right message" do
29
29
  lambda {raise 'blah'}.should raise_error('blah')
30
30
  end
31
+ it "should pass if RuntimeError is raised with a matching message" do
32
+ lambda {raise 'blah'}.should raise_error(/blah/)
33
+ end
31
34
  it "should pass if any other error is raised with the right message" do
32
35
  lambda {raise NameError.new('blah')}.should raise_error('blah')
33
36
  end
@@ -126,6 +129,127 @@ describe "should raise_error(NamedError, error_message) with String" do
126
129
  end
127
130
  end
128
131
 
132
+ describe "should raise_error(NamedError, error_message) { |err| ... }" do
133
+ it "should yield exception if named error is raised with same message" do
134
+ ran = false
135
+
136
+ lambda {
137
+ raise "example message"
138
+ }.should raise_error(RuntimeError, "example message") { |err|
139
+ ran = true
140
+ err.class.should == RuntimeError
141
+ err.message.should == "example message"
142
+ }
143
+
144
+ ran.should == true
145
+ end
146
+
147
+ it "yielded block should be able to fail on it's own right" do
148
+ ran, passed = false, false
149
+
150
+ lambda {
151
+ lambda {
152
+ raise "example message"
153
+ }.should raise_error(RuntimeError, "example message") { |err|
154
+ ran = true
155
+ 5.should == 4
156
+ passed = true
157
+ }
158
+ }.should fail_with(/expected: 4/m)
159
+
160
+ ran.should == true
161
+ passed.should == false
162
+ end
163
+
164
+ it "should NOT yield exception if no error was thrown" do
165
+ ran = false
166
+
167
+ lambda {
168
+ lambda {}.should raise_error(RuntimeError, "example message") { |err|
169
+ ran = true
170
+ }
171
+ }.should fail_with("expected RuntimeError with \"example message\" but nothing was raised")
172
+
173
+ ran.should == false
174
+ end
175
+
176
+ it "should not yield exception if error class is not matched" do
177
+ ran = false
178
+
179
+ lambda {
180
+ lambda {
181
+ raise "example message"
182
+ }.should raise_error(SyntaxError, "example message") { |err|
183
+ ran = true
184
+ }
185
+ }.should fail_with("expected SyntaxError with \"example message\", got #<RuntimeError: example message>")
186
+
187
+ ran.should == false
188
+ end
189
+
190
+ it "should NOT yield exception if error message is not matched" do
191
+ ran = false
192
+
193
+ lambda {
194
+ lambda {
195
+ raise "example message"
196
+ }.should raise_error(RuntimeError, "different message") { |err|
197
+ ran = true
198
+ }
199
+ }.should fail_with("expected RuntimeError with \"different message\", got #<RuntimeError: example message>")
200
+
201
+ ran.should == false
202
+ end
203
+ end
204
+
205
+ describe "should_not raise_error(NamedError, error_message) { |err| ... }" do
206
+ it "should pass if nothing is raised" do
207
+ ran = false
208
+
209
+ lambda {}.should_not raise_error(RuntimeError, "example message") { |err|
210
+ ran = true
211
+ }
212
+
213
+ ran.should == false
214
+ end
215
+
216
+ it "should pass if a different error is raised" do
217
+ ran = false
218
+
219
+ lambda { raise }.should_not raise_error(NameError, "example message") { |err|
220
+ ran = true
221
+ }
222
+
223
+ ran.should == false
224
+ end
225
+
226
+ it "should pass if same error is raised with different message" do
227
+ ran = false
228
+
229
+ lambda {
230
+ raise RuntimeError.new("not the example message")
231
+ }.should_not raise_error(RuntimeError, "example message") { |err|
232
+ ran = true
233
+ }
234
+
235
+ ran.should == false
236
+ end
237
+
238
+ it "should fail if named error is raised with same message" do
239
+ ran = false
240
+
241
+ lambda {
242
+ lambda {
243
+ raise "example message"
244
+ }.should_not raise_error(RuntimeError, "example message") { |err|
245
+ ran = true
246
+ }
247
+ }.should fail_with("expected no RuntimeError with \"example message\", got #<RuntimeError: example message>")
248
+
249
+ ran.should == false
250
+ end
251
+ end
252
+
129
253
  describe "should_not raise_error(NamedError, error_message) with String" do
130
254
  it "should pass if nothing is raised" do
131
255
  lambda {}.should_not raise_error(RuntimeError, "example message")