expect(a: 1, b: Time.now, c: 'wow').to include({a: be_a(Integer)})
# => true
expect(a: 1, b: Time.now, c: 'wow').to include({b: be_a(Time)})
# => true
expect(a: 1, b: Time.now, c: 'wow').to include({c: be_a(String)})
# => true
expect(a: 1, b: Time.now, c: 'wow').to include({c: be_a(Integer)})
# => [#<RSpec::Expectations::ExpectationNotMetError: expected {:a => 1, :b => 2019-12-13 02:08:55.283922100 +0000, :c => "wow"} to include {:c => (be a kind of Integer)}
# Diff:
# @@ -1,2 +1,4 @@
# -:c => (be a kind of Integer),
# +:a => 1,
# +:b => 2019-12-13 02:08:55.283922100 +0000,
# +:c => "wow",
# >]
ref
ruby - Testing hash contents using RSpec - Stack Overflow
https://stackoverflow.com/questions/8392884/testing-hash-contents-using-rspec
Original by Github issue
チャットメンバー募集
何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。