stripe-ruby/test/api_fixtures.rb
Brandur 4d7019bee6 Move OpenAPI spec from spec/ to openapi/
Naming a directory `spec` in a Ruby project is terribly ambiguous. This
clarifies the purpose of this directory and makes it easier to find if
you know that you're looking for OpenAPI.
2017-03-14 17:07:50 -07:00

30 lines
607 B
Ruby

# APIFixtures loads fixture data generated by the core Stripe API so that we
# can have slightly more accurate and up-to-date resource information in our
# tests.
class APIFixtures
def initialize
@fixtures = ::JSON.parse(File.read("#{PROJECT_ROOT}/openapi/fixtures.json"),
symbolize_names: true)
freeze_recursively(@fixtures)
end
def [](name)
@fixtures[name]
end
def fetch(*args)
@fixtures.fetch(*args)
end
private
def freeze_recursively(data)
data.each do |k, v|
if v.is_a?(Hash)
freeze_recursively(v)
end
end
data.freeze
end
end