Merge branch 'master' into release/0.10

This commit is contained in:
Michael Miller 2021-04-26 11:19:08 -06:00
commit 29594eefab
No known key found for this signature in database
GPG key ID: FB9F12F7C646A4AD
4 changed files with 35 additions and 2 deletions

View file

@ -272,7 +272,9 @@ This has been changed so that it compiles and raises an error at runtime with a
First version ready for public use.
[Unreleased]: https://gitlab.com/arctic-fox/spectator/-/compare/v0.9.34...HEAD
[Unreleased]: https://gitlab.com/arctic-fox/spectator/-/compare/v0.9.36...HEAD
[0.9.35]: https://gitlab.com/arctic-fox/spectator/-/compare/v0.9.35...v0.9.36
[0.9.35]: https://gitlab.com/arctic-fox/spectator/-/compare/v0.9.34...v0.9.35
[0.9.34]: https://gitlab.com/arctic-fox/spectator/-/compare/v0.9.33...v0.9.34
[0.9.33]: https://gitlab.com/arctic-fox/spectator/-/compare/v0.9.32...v0.9.33
[0.9.32]: https://gitlab.com/arctic-fox/spectator/-/compare/v0.9.31...v0.9.32

View file

@ -0,0 +1,26 @@
require "../spec_helper"
Spectator.describe Spectator::Matchers::TypeMatcher do
context String do # Sets `described_class` to String
def other_type
Int32
end
describe "#|" do
it "works on sets" do
super_set = (described_class | other_type)
expect(42).to be_kind_of(super_set)
expect("foo").to be_a(super_set)
end
end
it "works on described_class" do
expect("foo").to be_a_kind_of(described_class)
end
it "works on plain types" do
expect(42).to be_a(Int32)
end
end
end

View file

@ -77,7 +77,7 @@ module Spectator::DSL
# expect(x).to be_a(Int32 | String)
# ```
macro be_a(expected)
::Spectator::Matchers::TypeMatcher({{expected}}).new
::Spectator::Matchers::TypeMatcher.create({{expected}})
end
# Indicates that some value should be of a specified type.

View file

@ -4,6 +4,11 @@ module Spectator::Matchers
# Matcher that tests a value is of a specified type.
# The values are compared with the `Object#is_a?` method.
struct TypeMatcher(Expected) < StandardMatcher
# Alternate constructor that works with constant types and types from variables.
def self.create(type : T.class) forall T
TypeMatcher(T).new
end
# Short text about the matcher's purpose.
# This explains what condition satisfies the matcher.
# The description is used when the one-liner syntax is used.