How to mock JSONP call in rspec request specification with capybara?

I am working on integrating my rails application with Recurly.js.

Before I accessed my server server, I was able to complete all the integration with an excellent VCR stone ( https://github.com/myronmarston/vcr ), but Recurly.js makes a direct request to the service from javascript code using JSONP.

Question: how to mock these jsonp calls in an integration test?

I am currently using the rspec + capybara + phantomjs driver ( https://github.com/jonleighton/poltergeist )

+5
source share
2 answers

, , - javascript . Poltergeist gem javascript , , Recurly.js :

# The original 'save' function performs JSONP request to Recurly.
# A token is borrowed during the real API interaction.
page.driver.execute_script("""
  Recurly.Subscription.save = function (options) {
    Recurly.postResult('/subscription', { token: 'afc58c4895354255a422cc0405a045b0' }, options);
  }
""")

capybara-, , 'stub_recurly_js', Recurly.js.

, : http://pieoneers.tumblr.com/post/32406386853/test-recurlyjs-in-ruby-using-rspec-capybara-phantomjs

+3

puffing-billy. - URL-.

:

describe 'my recurly jsonp spec' do

  before do
    # call proxy.stub to setup a fake response
    proxy.stub 'https://api.recurly.com/v2/foo', :jsonp => { :bar => 'baz' }
  end

  it 'does something with recurly' do
    ....
  end
end
+2

All Articles