diff --git a/shard.yml b/shard.yml index 63aef87..71ef960 100644 --- a/shard.yml +++ b/shard.yml @@ -1,5 +1,5 @@ name: spectator -version: 0.5.2 +version: 0.5.3 description: | A feature-rich spec testing framework for Crystal with similarities to RSpec. diff --git a/src/spectator/dsl/matcher_dsl.cr b/src/spectator/dsl/matcher_dsl.cr index ac4315d..58e38af 100644 --- a/src/spectator/dsl/matcher_dsl.cr +++ b/src/spectator/dsl/matcher_dsl.cr @@ -517,7 +517,7 @@ module Spectator::DSL # expect { raise ArgumentError.new("foobar") }.to raise_error(ArgumentError, "foobar") # ``` macro raise_error(type, message) - ::Spectator::Matchers::ExceptionMatcher.new({{type}}, {{message}}, {{message.stringify}}) + ::Spectator::Matchers::ExceptionMatcher.create({{type}}, {{message}}, {{message.stringify}}) end # Indicates that some block should raise an error. diff --git a/src/spectator/matchers/exception_matcher.cr b/src/spectator/matchers/exception_matcher.cr index b35ce66..066922c 100644 --- a/src/spectator/matchers/exception_matcher.cr +++ b/src/spectator/matchers/exception_matcher.cr @@ -57,6 +57,11 @@ module Spectator::Matchers ExceptionMatcher(Exception, typeof(expected)).new(expected, label) end + # Creates a new exception matcher with a type and message check. + def self.create(exception_type : T.class, expected, label : String) forall T + ExceptionMatcher(T, typeof(expected)).new(expected, label) + end + # Match data specific to this matcher. private struct MatchData(ExceptionType, ExpectedType, ActualType) < MatchData # Creates the match data.