Move everything in BeComparison to TruthyMatcher

This is to match RSpec's ability to use "be" by itself.
For instance: `expect(foo).to be`
This commit is contained in:
Michael Miller 2019-01-23 22:10:03 -07:00
parent 28c13cd175
commit c31557e8ff
5 changed files with 164 additions and 167 deletions

View file

@ -1,102 +0,0 @@
require "../spec_helper"
# This is a terrible hack,
# but I don't want to expose `ValueMatcher#expected` publicly
# just for this spec.
module Spectator::Matchers
struct ValueMatcher(ExpectedType)
def expected_value
expected
end
end
end
def be_comparison
Spectator::Matchers::BeComparison.new
end
describe Spectator::Matchers::BeComparison do
describe "#<" do
it "returns a LessThanMatcher" do
value = 0
matcher = be_comparison < value
matcher.should be_a(Spectator::Matchers::LessThanMatcher(typeof(value)))
end
it "passes along the expected value" do
value = 42
matcher = be_comparison < value
matcher.expected_value.should eq(value)
end
end
describe "#<=" do
it "returns a LessThanEqualMatcher" do
value = 0
matcher = be_comparison <= value
matcher.should be_a(Spectator::Matchers::LessThanEqualMatcher(typeof(value)))
end
it "passes along the expected value" do
value = 42
matcher = be_comparison <= value
matcher.expected_value.should eq(value)
end
end
describe "#>" do
it "returns a GreaterThanMatcher" do
value = 0
matcher = be_comparison > value
matcher.should be_a(Spectator::Matchers::GreaterThanMatcher(typeof(value)))
end
it "passes along the expected value" do
value = 42
matcher = be_comparison > value
matcher.expected_value.should eq(value)
end
end
describe "#>=" do
it "returns a GreaterThanEqualMatcher" do
value = 0
matcher = be_comparison >= value
matcher.should be_a(Spectator::Matchers::GreaterThanEqualMatcher(typeof(value)))
end
it "passes along the expected value" do
value = 42
matcher = be_comparison >= value
matcher.expected_value.should eq(value)
end
end
describe "#==" do
it "returns an EqualityMatcher" do
value = 0
matcher = be_comparison == value
matcher.should be_a(Spectator::Matchers::EqualityMatcher(typeof(value)))
end
it "passes along the expected value" do
value = 42
matcher = be_comparison == value
matcher.expected_value.should eq(value)
end
end
describe "#!=" do
it "returns an InequalityMatcher" do
value = 0
matcher = be_comparison != value
matcher.should be_a(Spectator::Matchers::InequalityMatcher(typeof(value)))
end
it "passes along the expected value" do
value = 42
matcher = be_comparison != value
matcher.expected_value.should eq(value)
end
end
end

View file

@ -1,5 +1,20 @@
require "../spec_helper"
# This is a terrible hack,
# but I don't want to expose `ValueMatcher#expected` publicly
# just for this spec.
module Spectator::Matchers
struct ValueMatcher(ExpectedType)
def expected_value
expected
end
end
end
def be_comparison
Spectator::Matchers::TruthyMatcher.new(true)
end
describe Spectator::Matchers::TruthyMatcher do
context "truthy" do
describe "#match?" do
@ -134,4 +149,88 @@ describe Spectator::Matchers::TruthyMatcher do
end
end
end
describe "#<" do
it "returns a LessThanMatcher" do
value = 0
matcher = be_comparison < value
matcher.should be_a(Spectator::Matchers::LessThanMatcher(typeof(value)))
end
it "passes along the expected value" do
value = 42
matcher = be_comparison < value
matcher.expected_value.should eq(value)
end
end
describe "#<=" do
it "returns a LessThanEqualMatcher" do
value = 0
matcher = be_comparison <= value
matcher.should be_a(Spectator::Matchers::LessThanEqualMatcher(typeof(value)))
end
it "passes along the expected value" do
value = 42
matcher = be_comparison <= value
matcher.expected_value.should eq(value)
end
end
describe "#>" do
it "returns a GreaterThanMatcher" do
value = 0
matcher = be_comparison > value
matcher.should be_a(Spectator::Matchers::GreaterThanMatcher(typeof(value)))
end
it "passes along the expected value" do
value = 42
matcher = be_comparison > value
matcher.expected_value.should eq(value)
end
end
describe "#>=" do
it "returns a GreaterThanEqualMatcher" do
value = 0
matcher = be_comparison >= value
matcher.should be_a(Spectator::Matchers::GreaterThanEqualMatcher(typeof(value)))
end
it "passes along the expected value" do
value = 42
matcher = be_comparison >= value
matcher.expected_value.should eq(value)
end
end
describe "#==" do
it "returns an EqualityMatcher" do
value = 0
matcher = be_comparison == value
matcher.should be_a(Spectator::Matchers::EqualityMatcher(typeof(value)))
end
it "passes along the expected value" do
value = 42
matcher = be_comparison == value
matcher.expected_value.should eq(value)
end
end
describe "#!=" do
it "returns an InequalityMatcher" do
value = 0
matcher = be_comparison != value
matcher.should be_a(Spectator::Matchers::InequalityMatcher(typeof(value)))
end
it "passes along the expected value" do
value = 42
matcher = be_comparison != value
matcher.expected_value.should eq(value)
end
end
end