Skip to content

Instantly share code, notes, and snippets.

@michiel
Last active December 26, 2015 12:28
Show Gist options
  • Save michiel/7150956 to your computer and use it in GitHub Desktop.
Save michiel/7150956 to your computer and use it in GitHub Desktop.
Testing Mechanize apps
require 'rubygems'
require 'mechanize'
require 'test/unit'
require 'fakeweb'
def find_links
Mechanize.new.get('http://www.google.com').links
end
class TestGoogle < Test::Unit::TestCase
def test_should_pass
page = File.read("google_page.html")
FakeWeb.register_uri :get ,
"http://www.google.com" ,
:body => page,
:content_type => "text/html"
assert_equal 'Images' , find_links.first.text
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment