Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Loosen error message constraints for raise_error matcher specs.

This is in prep for #59--once I had some backtrace info, all of these would fail since they are doing exact string matches.
  • Loading branch information...
commit 2c2fdb6902ee753c6ba85f0eb7a0c1d48cb2f08e 1 parent 9814ab2
@myronmarston myronmarston authored
Showing with 46 additions and 39 deletions.
  1. +46 −39 spec/rspec/matchers/raise_error_spec.rb
View
85 spec/rspec/matchers/raise_error_spec.rb
@@ -4,7 +4,7 @@
it "passes if anything is raised" do
lambda {raise}.should raise_error
end
-
+
it "fails if nothing is raised" do
lambda {
lambda {}.should raise_error
@@ -40,11 +40,11 @@
it "passes if nothing is raised" do
lambda {}.should_not raise_error
end
-
+
it "fails if anything is raised" do
lambda {
lambda { raise RuntimeError, "example message" }.should_not raise_error
- }.should fail_with("expected no Exception, got #<RuntimeError: example message>")
+ }.should fail_with(/expected no Exception, got #<RuntimeError: example message>/)
end
end
@@ -52,21 +52,25 @@
it "passes if RuntimeError is raised with the right message" do
lambda {raise 'blah'}.should raise_error('blah')
end
+
it "passes if RuntimeError is raised with a matching message" do
lambda {raise 'blah'}.should raise_error(/blah/)
end
+
it "passes if any other error is raised with the right message" do
lambda {raise NameError.new('blah')}.should raise_error('blah')
end
+
it "fails if RuntimeError error is raised with the wrong message" do
lambda do
lambda {raise 'blarg'}.should raise_error('blah')
- end.should fail_with("expected Exception with \"blah\", got #<RuntimeError: blarg>")
+ end.should fail_with(/expected Exception with \"blah\", got #<RuntimeError: blarg>/)
end
+
it "fails if any other error is raised with the wrong message" do
lambda do
lambda {raise NameError.new('blarg')}.should raise_error('blah')
- end.should fail_with("expected Exception with \"blah\", got #<NameError: blarg>")
+ end.should fail_with(/expected Exception with \"blah\", got #<NameError: blarg>/)
end
end
@@ -74,18 +78,21 @@
it "passes if RuntimeError error is raised with the different message" do
lambda {raise 'blarg'}.should_not raise_error('blah')
end
+
it "passes if any other error is raised with the wrong message" do
lambda {raise NameError.new('blarg')}.should_not raise_error('blah')
end
+
it "fails if RuntimeError is raised with message" do
lambda do
lambda {raise 'blah'}.should_not raise_error('blah')
- end.should fail_with(%Q|expected no Exception with "blah", got #<RuntimeError: blah>|)
+ end.should fail_with(/expected no Exception with "blah", got #<RuntimeError: blah>/)
end
+
it "fails if any other error is raised with message" do
lambda do
lambda {raise NameError.new('blah')}.should_not raise_error('blah')
- end.should fail_with(%Q|expected no Exception with "blah", got #<NameError: blah>|)
+ end.should fail_with(/expected no Exception with "blah", got #<NameError: blah>/)
end
end
@@ -93,19 +100,19 @@
it "passes if named error is raised" do
lambda { non_existent_method }.should raise_error(NameError)
end
-
+
it "fails if nothing is raised" do
lambda {
lambda { }.should raise_error(NameError)
- }.should fail_with("expected NameError but nothing was raised")
+ }.should fail_with(/expected NameError but nothing was raised/)
end
-
+
it "fails if another error is raised (NameError)" do
lambda {
lambda { raise RuntimeError, "example message" }.should raise_error(NameError)
- }.should fail_with("expected NameError, got #<RuntimeError: example message>")
+ }.should fail_with(/expected NameError, got #<RuntimeError: example message>/)
end
-
+
it "fails if another error is raised (NameError)" do
lambda {
lambda { load "non/existent/file" }.should raise_error(NameError)
@@ -117,35 +124,35 @@
it "passes if nothing is raised" do
lambda { }.should_not raise_error(NameError)
end
-
+
it "passes if another error is raised" do
lambda { raise }.should_not raise_error(NameError)
end
-
+
it "fails if named error is raised" do
lambda {
lambda { 1 + 'b' }.should_not raise_error(TypeError)
}.should fail_with(/expected no TypeError, got #<TypeError: String can't be/)
- end
+ end
end
describe "should raise_error(NamedError, error_message) with String" do
it "passes if named error is raised with same message" do
lambda { raise "example message" }.should raise_error(RuntimeError, "example message")
end
-
+
it "fails if nothing is raised" do
lambda {
lambda {}.should raise_error(RuntimeError, "example message")
- }.should fail_with("expected RuntimeError with \"example message\" but nothing was raised")
+ }.should fail_with(/expected RuntimeError with \"example message\" but nothing was raised/)
end
-
+
it "fails if incorrect error is raised" do
lambda {
lambda { raise RuntimeError, "example message" }.should raise_error(NameError, "example message")
- }.should fail_with("expected NameError with \"example message\", got #<RuntimeError: example message>")
+ }.should fail_with(/expected NameError with \"example message\", got #<RuntimeError: example message>/)
end
-
+
it "fails if correct error is raised with incorrect message" do
lambda {
lambda { raise RuntimeError.new("not the example message") }.should raise_error(RuntimeError, "example message")
@@ -192,7 +199,7 @@
lambda {}.should raise_error(RuntimeError, "example message") { |err|
ran = true
}
- }.should fail_with("expected RuntimeError with \"example message\" but nothing was raised")
+ }.should fail_with(/expected RuntimeError with \"example message\" but nothing was raised/)
ran.should == false
end
@@ -206,7 +213,7 @@
}.should raise_error(SyntaxError, "example message") { |err|
ran = true
}
- }.should fail_with("expected SyntaxError with \"example message\", got #<RuntimeError: example message>")
+ }.should fail_with(/expected SyntaxError with \"example message\", got #<RuntimeError: example message>/)
ran.should == false
end
@@ -220,7 +227,7 @@
}.should raise_error(RuntimeError, "different message") { |err|
ran = true
}
- }.should fail_with("expected RuntimeError with \"different message\", got #<RuntimeError: example message>")
+ }.should fail_with(/expected RuntimeError with \"different message\", got #<RuntimeError: example message>/)
ran.should == false
end
@@ -268,7 +275,7 @@
}.should_not raise_error(RuntimeError, "example message") { |err|
ran = true
}
- }.should fail_with("expected no RuntimeError with \"example message\", got #<RuntimeError: example message>")
+ }.should fail_with(/expected no RuntimeError with \"example message\", got #<RuntimeError: example message>/)
ran.should == false
end
@@ -282,7 +289,7 @@
}.not_to raise_error(RuntimeError, "example message") { |err|
ran = true
}
- }.to fail_with("expected no RuntimeError with \"example message\", got #<RuntimeError: example message>")
+ }.to fail_with(/expected no RuntimeError with \"example message\", got #<RuntimeError: example message>/)
ran.should == false
end
@@ -292,19 +299,19 @@
it "passes if nothing is raised" do
lambda {}.should_not raise_error(RuntimeError, "example message")
end
-
+
it "passes if a different error is raised" do
lambda { raise }.should_not raise_error(NameError, "example message")
end
-
+
it "passes if same error is raised with different message" do
lambda { raise RuntimeError.new("not the example message") }.should_not raise_error(RuntimeError, "example message")
end
-
+
it "fails if named error is raised with same message" do
lambda {
lambda { raise "example message" }.should_not raise_error(RuntimeError, "example message")
- }.should fail_with("expected no RuntimeError with \"example message\", got #<RuntimeError: example message>")
+ }.should fail_with(/expected no RuntimeError with \"example message\", got #<RuntimeError: example message>/)
end
end
@@ -312,23 +319,23 @@
it "passes if named error is raised with matching message" do
lambda { raise "example message" }.should raise_error(RuntimeError, /ample mess/)
end
-
+
it "fails if nothing is raised" do
lambda {
lambda {}.should raise_error(RuntimeError, /ample mess/)
- }.should fail_with("expected RuntimeError with message matching /ample mess/ but nothing was raised")
+ }.should fail_with(/expected RuntimeError with message matching \/ample mess\/ but nothing was raised/)
end
-
+
it "fails if incorrect error is raised" do
lambda {
lambda { raise RuntimeError, "example message" }.should raise_error(NameError, /ample mess/)
- }.should fail_with("expected NameError with message matching /ample mess/, got #<RuntimeError: example message>")
+ }.should fail_with(/expected NameError with message matching \/ample mess\/, got #<RuntimeError: example message>/)
end
-
+
it "fails if correct error is raised with incorrect message" do
lambda {
lambda { raise RuntimeError.new("not the example message") }.should raise_error(RuntimeError, /less than ample mess/)
- }.should fail_with("expected RuntimeError with message matching /less than ample mess/, got #<RuntimeError: not the example message>")
+ }.should fail_with(/expected RuntimeError with message matching \/less than ample mess\/, got #<RuntimeError: not the example message>/)
end
end
@@ -336,18 +343,18 @@
it "passes if nothing is raised" do
lambda {}.should_not raise_error(RuntimeError, /ample mess/)
end
-
+
it "passes if a different error is raised" do
lambda { raise }.should_not raise_error(NameError, /ample mess/)
end
-
+
it "passes if same error is raised with non-matching message" do
lambda { raise RuntimeError.new("non matching message") }.should_not raise_error(RuntimeError, /ample mess/)
end
-
+
it "fails if named error is raised with matching message" do
lambda {
lambda { raise "example message" }.should_not raise_error(RuntimeError, /ample mess/)
- }.should fail_with("expected no RuntimeError with message matching /ample mess/, got #<RuntimeError: example message>")
+ }.should fail_with(/expected no RuntimeError with message matching \/ample mess\/, got #<RuntimeError: example message>/)
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.