4

I want to do a test whether a user has successfully subcribed after signing up in the newsletter form in my application.

I found this similar question Testing Mailchimp 3.0 and Gibbon 2.x with Rspec and no one responded.

I have a solution in mind, and that is using the methods from gibbon like gibbon.lists(list_id).members.retrieve and check if the user exist in the resulting object.

gbertl
  • 321
  • 2
  • 16

1 Answers1

2

I don't know the details of MailChimp, but in general, your app would either poll MailChimp's API for new subscribers, or MailChimp would ping your app's endpoint to notify about it.

In any case, you'd probably want to use something like https://github.com/vcr/vcr to record the MailChimp's response and test against that.

In the first case (polling)

your test would call a method like

MailChimpFacade.new_subscribers_since(last_time_you_checked_for_subscribers)

And you can mock that method, to return data (one subscriber, zero subscribers, many subscribers).

In the second case (ping)

when MailChimp sends a request to one of your controllers - use such VCR payload and send it to the controller to test it.

That's a general idea.

There are also other considerations: what should happen when MailChimp is unavailable when it returns gibberish etc. - you may want to test against it using the techniques described above as well.

Greg
  • 5,862
  • 1
  • 25
  • 52