Skip to content

Instantly share code, notes, and snippets.

@thisismydesign
Created September 2, 2021 22:13
Show Gist options
  • Save thisismydesign/a27ac86e1afe72882e6566599edd0023 to your computer and use it in GitHub Desktop.
Save thisismydesign/a27ac86e1afe72882e6566599edd0023 to your computer and use it in GitHub Desktop.
Ruby: Use factories for your webmocks /4
FactoryBot.define do
factory :xyz_service_get_entities_response, class: Hash do
skip_create
initialize_with { { body: attributes[:body].to_json }.stringify_keys }
transient do
ids { [1, 2, 3] }
page { 1 }
count { ids.count }
end
body do
{
data: {
total: count,
page: page,
entities: ids.map { |id| FactoryBot.create(:entity, id: id) }
}
}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment