Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
167 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module Webrat | ||
class RackTestSession < Session | ||
|
||
def initialize(rack_test_session) #:nodoc: | ||
super() | ||
@rack_test_session = rack_test_session | ||
end | ||
|
||
def response_body | ||
response.body | ||
end | ||
|
||
def response_code | ||
response.status | ||
end | ||
|
||
def response | ||
@rack_test_session.last_response | ||
end | ||
|
||
protected | ||
|
||
def process_request(http_method, url, data = {}, headers = {}) | ||
headers ||= {} | ||
data ||= {} | ||
|
||
env = headers.merge(:params => data, :method => http_method.to_s.upcase) | ||
@rack_test_session.request(url, env) | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require "rake/testtask" | ||
|
||
Rake::TestTask.new do |t| | ||
t.test_files = FileList["test/*_test.rb"] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require "rubygems" | ||
require "sinatra/base" | ||
|
||
class RackApp < Sinatra::Default | ||
get "/" do | ||
"Hello World" | ||
end | ||
|
||
get "/redirect_absolute_url" do | ||
redirect URI.join(request.url, "foo").to_s | ||
end | ||
|
||
get "/foo" do | ||
"spam" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require "rubygems" | ||
require "test/unit" | ||
require "rack/test" | ||
require "redgreen" | ||
|
||
require File.dirname(__FILE__) + "/../../../../lib/webrat" | ||
|
||
Webrat.configure do |config| | ||
config.mode = :rack_test | ||
end | ||
|
||
class Test::Unit::TestCase | ||
include Rack::Test::Methods | ||
include Webrat::Methods | ||
include Webrat::Matchers | ||
|
||
def app | ||
RackApp.new | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
require File.dirname(__FILE__) + "/test_helper" | ||
require File.dirname(__FILE__) + "/../rack_app" | ||
|
||
class WebratRackTest < Test::Unit::TestCase | ||
def test_visit_returns_response | ||
response = visit "/" | ||
assert response.ok? | ||
end | ||
|
||
def test_last_response_is_available | ||
visit "/" | ||
assert last_response.ok? | ||
end | ||
|
||
def test_last_request_is_available | ||
visit "/" | ||
assert_equal "/", last_request.env["PATH_INFO"] | ||
end | ||
|
||
def test_redirects | ||
visit "/redirect_absolute_url" | ||
assert_equal "spam", response_body | ||
end | ||
|
||
def test_assertions_after_visit | ||
visit "/" | ||
assert_contain "Hello World" | ||
end | ||
|
||
def test_assertions_after_visit | ||
get "/" | ||
assert_contain "Hello World" | ||
end | ||
|
||
# def test_visits_pages | ||
# visit "/" | ||
# assert response_body.include?("visit") | ||
# | ||
# click_link "there" | ||
# assert response_body.include?('<form method="post" action="/go">') | ||
# end | ||
# | ||
# def test_submits_form | ||
# visit "/go" | ||
# fill_in "Name", :with => "World" | ||
# fill_in "Email", :with => "world@example.org" | ||
# click_button "Submit" | ||
# | ||
# assert response_body.include?("Hello, World") | ||
# assert response_body.include?("Your email is: world@example.org") | ||
# end | ||
# | ||
# def test_check_value_of_field | ||
# visit "/" | ||
# assert field_labeled("Prefilled").value, "text" | ||
# end | ||
# | ||
# def test_follows_internal_redirects | ||
# visit "/internal_redirect" | ||
# assert response_body.include?("visit") | ||
# end | ||
# | ||
# def test_does_not_follow_external_redirects | ||
# visit "/external_redirect" | ||
# assert response_code == 302 | ||
# end | ||
end |