Closed MattRogish closed 11 years ago
If you're using RSpec, request specs are a good way to test the behavior of webhook handlers. Only the id
parameter needs to be passed to the post
request because StripeEvent discards the rest.
# spec/requests/stripe_webhooks_spec.rb
require "spec_helper"
describe "POST /your-webhook-path" do
context "charge.failed" do
it "emails the user" do
# setup models
# stub api request to retrieve the event object from Stripe (I like webmock or vcr+webmock)
post "/your-webhook-path", :id => "evt_some_charge_failed_event"
# assert that the system behaved appropriately
end
end
end
Here's a handy curl command for manual testing.
$ curl -X POST -H "Content-type: application/json" -H "Accept: application/json" -d '{"id":"evt_REPLACEME"}' localhost:3000/your-webhook-path
I hope this helps. Let me know if I can expand on or clarify anything.
Sorry, didn't see that - but it works great. THANKS!
Awesome. I'm planning to put the wiki together for this repo at some point. I'll be sure to mention this.
I'm curious - is there a way to test the webhooks in my app? I basically copied your stripe_event_spec and used the fixtures, which "works" but feels terrible. Is there a DRY'er way?
Thanks,
Matt