0

I am trying to test if external url active here:

class LinkSuccessTest < ActionDispatch::IntegrationTest
  ...
  def test_external_url_success
    @urls.each do |url|
      get url
      assert_response :success
    end
  end
end

but it wasn't working when there's a path parameter. For example,

$ rails console
> app.get "http://www.toms.com/"
=> 200
> app.get "http://www.toms.com/coffee"
=> 404

Here, how can I get the right response status?

kangkyu
  • 5,252
  • 3
  • 34
  • 36
  • `get` in the above context is sending a request to your app, not external sites. `> app.get "http://www.toms.com/"` is getting `/` from your app. `app.get "http://www.toms.com/coffee"` is trying to get `/coffee` from your app. Not `http://www.toms.com/`. – Prakash Murthy May 04 '15 at 23:12
  • 1
    You should use `mechanize` gem for interacting with external sites. See http://mechanize.rubyforge.org/EXAMPLES_rdoc.html for examples. – Prakash Murthy May 04 '15 at 23:14

1 Answers1

0

Thank you, I used mechanize gem and wrote above test, and it seems working.

require 'mechanize'

class LinkSuccessTest < ActionDispatch::IntegrationTest
  ...
  def test_external_url_success
    agent = Mechanize.new
    @urls.each do |url|
      assert_nothing_raised Mechanize::ResponseCodeError do
        agent.get(url)
      end
    end
  end
end
kangkyu
  • 5,252
  • 3
  • 34
  • 36