Add RSpec have_attributes matcher spec

This commit is contained in:
Michael Miller 2020-01-06 22:33:52 -07:00
parent f23141b3e1
commit 6ad861365c

View file

@ -0,0 +1,37 @@
require "../../spec_helper"
# Examples taken from:
# https://relishapp.com/rspec/rspec-expectations/v/3-8/docs/built-in-matchers/have-attributes-matcher
# and modified to fit Spectator and Crystal.
Spectator.describe "`have_attributes` matcher" do
context "basic usage" do
# Use `record` instead of `Struct.new`.
record Person, name : String, age : Int32
describe Person.new("Jim", 32) do
# Changed some syntax for Ruby hashes to Crystal named tuples.
# Spectator doesn't support helper matchers like `a_string_starting_with` and `a_value <`.
# But maybe in the future it will.
it { is_expected.to have_attributes(name: "Jim") }
# it { is_expected.to have_attributes(name: a_string_starting_with("J") ) }
it { is_expected.to have_attributes(age: 32) }
# it { is_expected.to have_attributes(age: (a_value > 30) ) }
it { is_expected.to have_attributes(name: "Jim", age: 32) }
# it { is_expected.to have_attributes(name: a_string_starting_with("J"), age: (a_value > 30) ) }
it { is_expected.not_to have_attributes(name: "Bob") }
it { is_expected.not_to have_attributes(age: 10) }
# it { is_expected.not_to have_attributes(age: (a_value < 30) ) }
# deliberate failures
# TODO: Add support for expected failures.
xit { is_expected.to have_attributes(name: "Bob") }
xit { is_expected.to have_attributes(name: 10) }
# fails if any of the attributes don't match
xit { is_expected.to have_attributes(name: "Bob", age: 32) }
xit { is_expected.to have_attributes(name: "Jim", age: 10) }
xit { is_expected.to have_attributes(name: "Bob", age: 10) }
end
end
end