mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add RSpec have_attributes
matcher spec
This commit is contained in:
parent
f23141b3e1
commit
6ad861365c
1 changed files with 37 additions and 0 deletions
37
spec/rspec/expectations/have_attributes_matcher_spec.cr
Normal file
37
spec/rspec/expectations/have_attributes_matcher_spec.cr
Normal 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
|
Loading…
Reference in a new issue