stripe-ruby/test/api_fixtures.rb
Brandur f0579950a7 Add testing infrastructure to use spec and fixtures
Adds some testing infrastructure that reads in the OpenAPI spec and its
fixtures. These changes will allow us to starting porting over each of
stripe-ruby's test suites.
2017-02-14 12:17:37 -08:00

30 lines
604 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}/spec/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