我正在尝试为user_record中定义的哈希创建匹配项。我尝试像在be_a_boolean中一样创建一个matcher.matches(),但是它只返回一个对象。 be_a_boolean不是已定义的对象,因此它当前不起作用。
def user_record
{
email_address: email_address_value,
date_of_birth: date_value,
active: boolean_value
}
end
def users(count)
Array.new(count) { user_record }
end
end
RSpec.describe DataGenerator do
def match_the_shape_of_a_user_record
# Use `be_a_boolean`, `be_a_date_before_2000` and `be_an_email_address`
# in the hash passed to `match` below to define this matcher.
match(a_hash_including(
an_object_having_attributes(:active => be_a_boolean_value),
# :date_of_birth => be_a_date_before_2000,
#:email_address => be_an_email_address
))
end
it "generates user records" do
user = DataGenerator.new.user_record
expect(user).to match_the_shape_of_a_user_record
end
def all_match_the_shape_of_a_user_record
# Combine the `all` matcher and `match_the_shape_of_a_user_record` here.
end
it "generates a list of user records" do
users = DataGenerator.new.users(4)
expect(users.to all_match_the_shape_of_a_user_record)
end
end