Skip to content

Commit

Permalink
Remove expect_raises without type argument (#5096)
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota authored and RX14 committed Oct 14, 2017
1 parent 3ff8e59 commit 3f99c77
Show file tree
Hide file tree
Showing 17 changed files with 34 additions and 40 deletions.
2 changes: 1 addition & 1 deletion spec/std/char_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ describe "Char" do
it { 'a'.in_set?("ab", "ac", "ad").should be_true }

it "rejects invalid ranges" do
expect_raises do
expect_raises(ArgumentError, "Invalid range c-a") do
'a'.in_set?("c-a")
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/std/dir_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ describe "Dir" do
end

it "raises" do
expect_raises do
expect_raises(Errno, "No such file or directory") do
Dir.cd("/nope")
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/std/enum_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ describe Enum do
SpecEnum.from_value(0).should eq(SpecEnum::One)
SpecEnum.from_value(1).should eq(SpecEnum::Two)
SpecEnum.from_value(2).should eq(SpecEnum::Three)
expect_raises { SpecEnum.from_value(3) }
expect_raises(Exception, "Unknown enum SpecEnum value: 3") { SpecEnum.from_value(3) }
end

it "for flags enum" do
expect_raises { SpecEnumFlags.from_value(0) }
expect_raises(Exception, "Unknown enum SpecEnumFlags value: 0") { SpecEnumFlags.from_value(0) }
SpecEnumFlags.from_value(1).should eq(SpecEnumFlags::One)
SpecEnumFlags.from_value(2).should eq(SpecEnumFlags::Two)
SpecEnumFlags.from_value(3).should eq(SpecEnumFlags::One | SpecEnumFlags::Two)
Expand Down
2 changes: 1 addition & 1 deletion spec/std/file_utils_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe "FileUtils" do
end

it "raises" do
expect_raises do
expect_raises(Errno, "No such file or directory") do
FileUtils.cd("/nope")
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/std/gc_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe "GC" do
end

it "raises if calling enable when not disabled" do
expect_raises do
expect_raises(Exception, "GC is not disabled") do
GC.enable
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/std/http/client/client_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ module HTTP
end
{% else %}
it "raises when trying to activate TLS" do
expect_raises do
expect_raises(Exception, "TLS is disabled") do
Client.new "example.org", 443, tls: true
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/std/http/server/handlers/log_handler_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe HTTP::LogHandler do
log_io = IO::Memory.new
handler = HTTP::LogHandler.new(log_io)
handler.next = ->(ctx : HTTP::Server::Context) { raise "foo" }
expect_raises do
expect_raises(Exception, "foo") do
handler.call(context)
end
(log_io.to_s =~ %r(GET / - Unhandled exception:)).should be_truthy
Expand Down
12 changes: 6 additions & 6 deletions spec/std/int_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,15 @@ describe "Int" do
it { 3843.to_s(62).should eq("ZZ") }

it "raises on base 1" do
expect_raises { 123.to_s(1) }
expect_raises(ArgumentError, "Invalid base 1") { 123.to_s(1) }
end

it "raises on base 37" do
expect_raises { 123.to_s(37) }
expect_raises(ArgumentError, "Invalid base 37") { 123.to_s(37) }
end

it "raises on base 62 with upcase" do
expect_raises { 123.to_s(62, upcase: true) }
expect_raises(ArgumentError, "upcase must be false for base 62") { 123.to_s(62, upcase: true) }
end

it { to_s_with_io(12, 2).should eq("1100") }
Expand Down Expand Up @@ -172,15 +172,15 @@ describe "Int" do
it { to_s_with_io(3843, 62).should eq("ZZ") }

it "raises on base 1 with io" do
expect_raises { to_s_with_io(123, 1) }
expect_raises(ArgumentError, "Invalid base 1") { to_s_with_io(123, 1) }
end

it "raises on base 37 with io" do
expect_raises { to_s_with_io(123, 37) }
expect_raises(ArgumentError, "Invalid base 37") { to_s_with_io(123, 37) }
end

it "raises on base 62 with upcase with io" do
expect_raises { to_s_with_io(12, 62, upcase: true) }
expect_raises(ArgumentError, "upcase must be false for base 62") { to_s_with_io(12, 62, upcase: true) }
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/std/json/serialization_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ describe "JSON serialization" do
it "does for Enum with number" do
JSONSpecEnum.from_json("1").should eq(JSONSpecEnum::One)

expect_raises do
expect_raises(Exception, "Unknown enum JSONSpecEnum value: 3") do
JSONSpecEnum.from_json("3")
end
end

it "does for Enum with string" do
JSONSpecEnum.from_json(%("One")).should eq(JSONSpecEnum::One)

expect_raises do
expect_raises(ArgumentError, "Unknown enum JSONSpecEnum value: Three") do
JSONSpecEnum.from_json(%("Three"))
end
end
Expand Down
8 changes: 4 additions & 4 deletions spec/std/object_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ describe Object do
describe "getter!" do
it "uses getter!" do
obj = TestObject.new
expect_raises do
expect_raises(Exception, "Nil assertion failed") do
obj.getter5
end
obj.getter5 = 5
Expand All @@ -173,7 +173,7 @@ describe Object do

it "uses getter! with type declaration" do
obj = TestObject.new
expect_raises do
expect_raises(Exception, "Nil assertion failed") do
obj.getter6
end
obj.getter6 = 6
Expand Down Expand Up @@ -287,7 +287,7 @@ describe Object do
describe "property!" do
it "uses property!" do
obj = TestObject.new
expect_raises do
expect_raises(Exception, "Nil assertion failed") do
obj.property5
end
obj.property5 = 5
Expand All @@ -296,7 +296,7 @@ describe Object do

it "uses property! with type declaration" do
obj = TestObject.new
expect_raises do
expect_raises(Exception, "Nil assertion failed") do
obj.property6
end
obj.property6 = 6
Expand Down
8 changes: 4 additions & 4 deletions spec/std/slice_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -369,14 +369,14 @@ describe "Slice" do

it "creates read-only slice" do
slice = Slice.new(3, 0, read_only: true)
expect_raises { slice[0] = 1 }
expect_raises { slice.copy_from(slice) }
expect_raises(Exception, "Can't write to read-only Slice") { slice[0] = 1 }
expect_raises(Exception, "Can't write to read-only Slice") { slice.copy_from(slice) }

subslice = slice[0, 1]
expect_raises { subslice[0] = 1 }
expect_raises(Exception, "Can't write to read-only Slice") { subslice[0] = 1 }

slice = Bytes[1, 2, 3, read_only: true]
expect_raises { slice[0] = 0_u8 }
expect_raises(Exception, "Can't write to read-only Slice") { slice[0] = 0_u8 }
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/std/string_builder_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe String::Builder do
builder << 123
builder.to_s.should eq("123")

expect_raises { builder.to_s }
expect_raises(Exception, "Can only invoke 'to_s' once on String::Builder") { builder.to_s }
end

it "goes back" do
Expand Down
6 changes: 3 additions & 3 deletions spec/std/string_scanner_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ describe StringScanner, "#[]" do
s = StringScanner.new("Fri Dec 12 1975 14:39")
s.scan(/this is not there/)

expect_raises { s[0] }
expect_raises(Exception, "Nil assertion failed") { s[0] }
end

it "raises when there is no subgroup" do
Expand All @@ -155,8 +155,8 @@ describe StringScanner, "#[]" do
s.scan(regex)

s[0].should_not be_nil
expect_raises { s[5] }
expect_raises { s["something"] }
expect_raises(IndexError) { s[5] }
expect_raises(KeyError, "Capture group 'something' does not exist") { s["something"] }
end
end

Expand Down
6 changes: 3 additions & 3 deletions spec/std/string_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ describe "String" do

it "gets with a string" do
"FooBar"["Bar"].should eq "Bar"
expect_raises { "FooBar"["Baz"] }
expect_raises(Exception, "Nil assertion failed") { "FooBar"["Baz"] }
"FooBar"["Bar"]?.should eq "Bar"
"FooBar"["Baz"]?.should be_nil
end

it "gets with a char" do
"foo/bar"['/'].should eq '/'
expect_raises { "foo/bar"['-'] }
expect_raises(Exception, "Nil assertion failed") { "foo/bar"['-'] }
"foo/bar"['/']?.should eq '/'
"foo/bar"['-']?.should be_nil
end
Expand Down Expand Up @@ -331,7 +331,7 @@ describe "String" do
it { expect_raises(ArgumentError, "Invalid base 1") { "12ab".to_i(1) } }
it { expect_raises(ArgumentError, "Invalid base 37") { "12ab".to_i(37) } }

it { expect_raises { "1Y2P0IJ32E8E7".to_i(36) } }
it { expect_raises(ArgumentError, "Invalid Int32") { "1Y2P0IJ32E8E7".to_i(36) } }
it { "1Y2P0IJ32E8E7".to_i64(36).should eq(9223372036854775807) }
end

Expand Down
4 changes: 2 additions & 2 deletions spec/std/yaml/serialization_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,15 @@ describe "YAML serialization" do
it "does for Enum with number" do
YAMLSpecEnum.from_yaml(%("1")).should eq(YAMLSpecEnum::One)

expect_raises do
expect_raises(Exception, "Unknown enum YAMLSpecEnum value: 3") do
YAMLSpecEnum.from_yaml(%("3"))
end
end

it "does for Enum with string" do
YAMLSpecEnum.from_yaml(%("One")).should eq(YAMLSpecEnum::One)

expect_raises do
expect_raises(ArgumentError, "Unknown enum YAMLSpecEnum value: Three") do
YAMLSpecEnum.from_yaml(%("Three"))
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/std/yaml/yaml_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe "YAML" do
end

it "raises if merging with missing alias" do
expect_raises do
expect_raises(YAML::ParseException, "Unknown anchor 'bar'") do
YAML.parse(%(---
foo:
<<: *bar
Expand Down
6 changes: 0 additions & 6 deletions src/spec/expectations.cr
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,6 @@ module Spec
Spec::BeAExpectation({{type}}).new
end

macro expect_raises
expect_raises(Exception, nil) do
{{yield}}
end
end

macro expect_raises(klass)
expect_raises({{klass}}, nil) do
{{yield}}
Expand Down

0 comments on commit 3f99c77

Please sign in to comment.