integrallis / stripe_event

Stripe webhook integration for Rails applications.
https://rubygems.org/gems/stripe_event
MIT License
840 stars 107 forks source link

RSpec running within CircleCI: No route matches [POST] #74

Closed peco8 closed 7 years ago

peco8 commented 7 years ago

I've been writing mock tests with RSpec. The problem is the end point I specified doesn't seem to accept the POST request within CircleCI container. (The test works fine locally.)

 1) stripe_invoice_created_webhook responds 404 to invoice_created webhook with invalid endpoint
     Failure/Error: post '/stripe-hogehoge', event.as_json

     ActionController::RoutingError:
       No route matches [POST] "/stripe-hogehoge"

In config/routes.rb

Rails.application.routes.draw do

  # Handle Stripe Webhooks
  mount StripeEvent::Engine, at:'/stripe-events'

I use

Hatcher19 commented 7 years ago

@peco8 I'm having the same issue, same code in in routes file. Did you fix this?

peco8 commented 7 years ago

@Hatcher19

Hi I could fixed this problem.

Actually this is not specific for Stripe_event gem.

Under config/environments/test.rb, please check the following option:

#Raise exceptions instead of rendering exception templates.
config.action_dispatch.show_exceptions = false

By default, this option is set to false, which will raise the exception instead of rendering the template.

Your test assumes that the template will be rendered even if an exception is raised.

You can do

config.action_dispatch.show_exceptions = true

Alternatively, if you don't want to change this value you can write the following test:

expect { 
  post '/hogehoge', {}
}.to raise_error(ActionController::RoutingError)
invisiblefunnel commented 7 years ago

Hello @peco8! I'm a bit confused about why your tests are using /stripe-hogehoge when you've specified /stripe-events in your routes.rb file. What is the behavior under test? What do you expect to be the result of the test?

I'm happy to help but need some more clarity on what you're trying to accomplish. Cheers!

Would you mind closing the issue if you've resolved it on your end?