Created
September 2, 2021 22:13
-
-
Save thisismydesign/a27ac86e1afe72882e6566599edd0023 to your computer and use it in GitHub Desktop.
Ruby: Use factories for your webmocks /4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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