0

This method redirects to an external website. How do I test this behaviour? I know that the method works correctly because I tested in the browser, but I can't get the test to pass.

  def create
    if @order.save
      redirect_to Gateway.new(@order).send
    else
      render 'new'
    end
  end

I wrote this test which fails with "Missing Template error":

describe 'User creates an order with valid info' do
  before do
    WebMock.allow_net_connect!
    stub_request(:any, "https://external-site.com/v2/checkout")
  end

  it 'creates the order and redirects to checkout page' do
    fill_in_order
    expect { click_button "Submit" }.to change(Order, :count)
  end
end

Error:

Failure/Error: click_button "Submit"
     ActionView::MissingTemplate:
       Missing template orders/create, ...
dee
  • 1,848
  • 1
  • 22
  • 34

1 Answers1

0

Set the response to return example:

Replaying raw responses recorded with curl -is

`curl -is www.example.com > /tmp/example_curl_-is_output.txt`
raw_response_file = File.new("/tmp/example_curl_-is_output.txt")

from file

stub_request(:get, "www.example.com").to_return(raw_response_file)

or string

stub_request(:get, "www.example.com").to_return(raw_response_file.read)
Sachin Singh
  • 7,107
  • 6
  • 40
  • 80