2010-04-13 02:30:56 +00:00
|
|
|
require "rubygems"
|
2009-06-24 16:18:46 +00:00
|
|
|
require File.dirname(__FILE__) + "/helper"
|
2009-04-15 02:19:57 +00:00
|
|
|
|
|
|
|
class WebratRackTest < Test::Unit::TestCase
|
2009-06-24 21:26:13 +00:00
|
|
|
include Rack::Test::Methods
|
|
|
|
include Webrat::Methods
|
|
|
|
include Webrat::Matchers
|
|
|
|
include Webrat::HaveTagMatcher
|
|
|
|
|
2009-06-26 01:13:54 +00:00
|
|
|
def build_rack_mock_session
|
|
|
|
Rack::MockSession.new(app, "www.example.com")
|
|
|
|
end
|
|
|
|
|
2009-06-24 16:18:46 +00:00
|
|
|
def test_visits_pages
|
|
|
|
visit "/"
|
|
|
|
click_link "there"
|
2009-05-11 05:27:04 +00:00
|
|
|
|
2009-06-24 16:18:46 +00:00
|
|
|
assert_have_tag("form[@method='post'][@action='/go']")
|
2009-04-15 02:19:57 +00:00
|
|
|
end
|
2009-05-11 05:27:04 +00:00
|
|
|
|
2009-06-24 00:43:32 +00:00
|
|
|
def test_submits_form
|
|
|
|
visit "/go"
|
|
|
|
fill_in "Name", :with => "World"
|
|
|
|
fill_in "Email", :with => "world@example.org"
|
|
|
|
click_button "Submit"
|
|
|
|
|
|
|
|
assert_contain "Hello, World"
|
|
|
|
assert_contain "Your email is: world@example.org"
|
|
|
|
end
|
2009-06-24 16:18:46 +00:00
|
|
|
|
|
|
|
def test_check_value_of_field
|
2009-04-15 02:19:57 +00:00
|
|
|
visit "/"
|
2009-06-24 16:18:46 +00:00
|
|
|
assert_equal field_labeled("Prefilled").value, "text"
|
2009-04-15 02:19:57 +00:00
|
|
|
end
|
|
|
|
|
2009-06-24 16:18:46 +00:00
|
|
|
def test_follows_internal_redirects
|
|
|
|
visit "/internal_redirect"
|
|
|
|
assert_contain "visit"
|
2009-06-24 13:19:06 +00:00
|
|
|
end
|
2009-05-11 05:27:04 +00:00
|
|
|
|
2009-06-24 16:18:46 +00:00
|
|
|
def test_does_not_follow_external_redirects
|
|
|
|
visit "/external_redirect"
|
|
|
|
assert last_response.redirect?
|
2009-04-15 02:19:57 +00:00
|
|
|
end
|
2009-05-11 05:27:04 +00:00
|
|
|
|
2009-06-24 16:18:46 +00:00
|
|
|
def test_absolute_url_redirect
|
|
|
|
visit "/absolute_redirect"
|
|
|
|
assert_contain "spam"
|
2009-04-15 02:19:57 +00:00
|
|
|
end
|
2009-06-25 21:33:32 +00:00
|
|
|
|
|
|
|
def test_upload_file
|
|
|
|
visit "/upload"
|
|
|
|
attach_file "File", __FILE__, "text/ruby"
|
|
|
|
click_button "Upload"
|
|
|
|
|
2010-04-22 22:09:45 +00:00
|
|
|
upload = Marshal.load(response_body)
|
2009-06-25 21:33:32 +00:00
|
|
|
assert_equal "text/ruby", upload[:type]
|
|
|
|
assert_equal "webrat_rack_test.rb", upload[:filename]
|
2010-04-22 22:09:45 +00:00
|
|
|
assert_equal File.read(__FILE__), upload[:tempfile]
|
2009-06-25 21:33:32 +00:00
|
|
|
end
|
2010-04-23 21:57:11 +00:00
|
|
|
|
|
|
|
def test_open_errors
|
|
|
|
$open_pages = []
|
|
|
|
|
|
|
|
Webrat.configure do |config|
|
|
|
|
config.open_error_files = true
|
|
|
|
end
|
|
|
|
|
|
|
|
def webrat_session.open_in_browser(path)
|
|
|
|
$open_pages << path
|
|
|
|
end
|
|
|
|
|
|
|
|
5.times do
|
|
|
|
visit "/error"
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_equal 3, $open_pages.size
|
|
|
|
end
|
2009-04-15 02:19:57 +00:00
|
|
|
end
|
2009-06-24 21:26:13 +00:00
|
|
|
|
|
|
|
class WebratRackSetupTest < Test::Unit::TestCase
|
|
|
|
def test_usable_without_mixin
|
2009-06-26 01:13:54 +00:00
|
|
|
rack_test_session = Rack::Test::Session.new(Rack::MockSession.new(app))
|
2009-08-13 00:39:35 +00:00
|
|
|
adapter = Webrat::RackAdapter.new(rack_test_session)
|
2009-06-24 21:26:13 +00:00
|
|
|
session = Webrat::Session.new(adapter)
|
|
|
|
|
|
|
|
session.visit "/foo"
|
|
|
|
|
|
|
|
assert_equal "spam", session.response_body
|
|
|
|
assert_equal "spam", rack_test_session.last_response.body
|
|
|
|
end
|
|
|
|
end
|