Open splattael opened 9 years ago
I'd also like this
Let's discuss the feature-set for this test helper:
CandyCheck::AppStore::Verifier
and CandyCheck::PlayStore::Verifier
: returning a Receipt
, a VerificationFailure
or raising an error.So thoughts on this.
I think it should be similar to how the Ruby geocoder gem does it. I know this is a Rails example but here is how we implemented stubbing out geolocation request form that gem, its similar concept in that is using a google api service. In this case, we just have two services, apple and google.
module GeocodingHelpers
def stub_location_lookup(locations)
locations.each do |query, properties|
Geocoder::Lookup::Test.add_stub(
query,
[properties.with_indifferent_access],
)
end
end
def stub_unknown_location_lookup(query)
allow(Geocoder).to receive(:coordinates).with(query).and_return(nil)
end
end
RSpec.configure do |config|
config.before(:all) { Geocoder.configure(lookup: :test) }
config.include GeocodingHelpers
end
For reference, the geolocator test app is here: https://github.com/alexreisner/geocoder_test
We could make some improvements I'm sure but might be worth looking at as a good starting point.
Also, I think if everything is written where dependency injection is requried ie: fetch libs etc, stubbing out a specific instance shouldn't be hard. It would be nice to be able to set up a 'test' mode which returns some stubbed objects of ReceiptStub
and VerificationFailureStub
I think this would be a step in the right direction. In detail the gem should not make assumptions about the test framework, but could be instrumented as in the given example.
It would be nice to streamline testing for candy check so stubbing verification gets easier.
More info to follow.