Created
August 26, 2015 13:13
-
-
Save tygern/1c667b9dca8552b7e60c to your computer and use it in GitHub Desktop.
Testing External Services - ZippyEnvironment
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
class ZippyEnvironment | |
def initialize | |
@account_ids = [] | |
yield self | |
ensure | |
clean_up | |
end | |
def create_account(data) | |
account = Zippy::Account.create(data) | |
if account.errors.empty? | |
@account_ids << account.id | |
else | |
raise "Failed to create: #{account.errors.inspect}" | |
end | |
account | |
end | |
private | |
def clean_up | |
delete_accounts | |
end | |
def delete_accounts | |
failed_deletions = [] | |
@account_ids.each do |id| | |
success = Zippy::Account.delete(id) | |
failed_deletions << id unless success | |
end | |
if failed_deletions.present? | |
raise "Failed to delete: #{failed_deletions.inspect}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment