Add should keywords to examples

Allows short-hand like:
it { should be_empty }
This commit is contained in:
Michael Miller 2020-01-19 22:12:06 -07:00
parent 8381c08b05
commit b1984b343a
2 changed files with 19 additions and 4 deletions

View file

@ -11,8 +11,7 @@ Spectator.describe "One-liner syntax" do
# subject.should be_empty
# end
# TODO: Define `should` method on example to be `is_expected`.
# it { should be_empty }
it { should be_empty }
# or
it { is_expected.to be_empty }
end
@ -22,8 +21,8 @@ Spectator.describe "One-liner syntax" do
describe Array(Int32) do
describe "with 3 items" do
subject { [1, 2, 3] }
# TODO: Define `should_not` method on example to be `is_expected.not_to`.
# it { should_not be_empty }
it { should_not be_empty }
# or
it { is_expected.not_to be_empty }
end

View file

@ -184,6 +184,22 @@ module Spectator
is_expected.to_not eq({{expected}})
end
macro should(matcher)
is_expected.to({{matcher}})
end
macro should_not(matcher)
is_expected.to_not({{matcher}})
end
macro should_eventuall(matcher)
is_expected.to_eventually({{matcher}})
end
macro should_never(matcher)
is_expected.to_never({{matcher}})
end
# Immediately fail the current test.
# A reason can be passed,
# which is reported in the output.