Skip to content

Stubbing outgoing requests from Rails server #92

@andretgregorio

Description

@andretgregorio

Hello, there.

Thanks for writing and maintaining this lib. This is some awesome work.

I'm currently trying to integrate it with my Rails app, and I've found a situation that I don't know how to work around.
My Rails app has to call some 3rd party services using standard HTTP requests. In our tests that run in rspec we can just stub those requests and provide the response body we want. But since with Cypress I'm running my application in an environment that is not rspec, is there a way to stub outgoing requests from the Rails server?

This is an example where an outgoing request is being stubbed for regular tests:

shared_context 'when using ViaCEP' do
  before do
    stub_request(:get, %r{https://viacep.com.br/ws/.*/json})
      .with(headers: { 'Host' => 'viacep.com.br' })
      .to_return(status: 200, body: viacep_response.to_json)
  end

  let(:viacep_response) { build(:viacep_address) }
end

Regards.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions