More integration specs for the rack mode
One test is still pending because form fields are double-escaped.
This commit is contained in:
parent
4c010d1c65
commit
cf8d891302
73
spec/integration/rack/app.rb
Normal file
73
spec/integration/rack/app.rb
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
require "rubygems"
|
||||||
|
require "sinatra/base"
|
||||||
|
|
||||||
|
class RackApp < Sinatra::Base
|
||||||
|
use_in_file_templates!
|
||||||
|
|
||||||
|
get "/" do
|
||||||
|
erb :home
|
||||||
|
end
|
||||||
|
|
||||||
|
get "/go" do
|
||||||
|
erb :go
|
||||||
|
end
|
||||||
|
|
||||||
|
get "/internal_redirect" do
|
||||||
|
redirect "/"
|
||||||
|
end
|
||||||
|
|
||||||
|
get "/external_redirect" do
|
||||||
|
redirect "http://google.com"
|
||||||
|
end
|
||||||
|
|
||||||
|
get "/absolute_redirect" do
|
||||||
|
redirect URI.join(request.url, "foo").to_s
|
||||||
|
end
|
||||||
|
|
||||||
|
get "/foo" do
|
||||||
|
"spam"
|
||||||
|
end
|
||||||
|
|
||||||
|
post "/go" do
|
||||||
|
@user = params[:name]
|
||||||
|
@email = params[:email]
|
||||||
|
erb :hello
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
__END__
|
||||||
|
@@ layout
|
||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||||
|
<html>
|
||||||
|
<title>sinatra testing with webrat</title>
|
||||||
|
<body>
|
||||||
|
<%= yield %>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
|
@@ home
|
||||||
|
<p> visit <a href="/go">there</a></p>
|
||||||
|
|
||||||
|
<form>
|
||||||
|
<label>
|
||||||
|
Prefilled
|
||||||
|
<input type="text" name="prefilled" value="text" />
|
||||||
|
</label>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
@@ go
|
||||||
|
<form method="post" action="/go">
|
||||||
|
<div>
|
||||||
|
<label for="name">Name</label>
|
||||||
|
<input type="text" name="name" id="name">
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label for="email">Email</label>
|
||||||
|
<input type="text" name="email" id="email">
|
||||||
|
</div>
|
||||||
|
<input type="submit" value="Submit" />
|
||||||
|
</form>
|
||||||
|
|
||||||
|
@@ hello
|
||||||
|
<p>Hello, <%= @user %></p>
|
||||||
|
<p>Your email is: <%= @email %></p>
|
@ -1,16 +0,0 @@
|
|||||||
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
|
|
@ -4,6 +4,7 @@ require "rack/test"
|
|||||||
# require "redgreen"
|
# require "redgreen"
|
||||||
|
|
||||||
require File.dirname(__FILE__) + "/../../../../lib/webrat"
|
require File.dirname(__FILE__) + "/../../../../lib/webrat"
|
||||||
|
require File.dirname(__FILE__) + "/../app"
|
||||||
|
|
||||||
Webrat.configure do |config|
|
Webrat.configure do |config|
|
||||||
config.mode = :rack
|
config.mode = :rack
|
||||||
@ -13,6 +14,7 @@ class Test::Unit::TestCase
|
|||||||
include Rack::Test::Methods
|
include Rack::Test::Methods
|
||||||
include Webrat::Methods
|
include Webrat::Methods
|
||||||
include Webrat::Matchers
|
include Webrat::Matchers
|
||||||
|
include Webrat::HaveTagMatcher
|
||||||
|
|
||||||
def app
|
def app
|
||||||
Rack::Builder.new {
|
Rack::Builder.new {
|
@ -1,67 +1,40 @@
|
|||||||
require File.dirname(__FILE__) + "/test_helper"
|
require File.dirname(__FILE__) + "/helper"
|
||||||
require File.dirname(__FILE__) + "/../rack_app"
|
|
||||||
|
|
||||||
class WebratRackTest < Test::Unit::TestCase
|
class WebratRackTest < Test::Unit::TestCase
|
||||||
def test_visit_returns_response
|
def test_visits_pages
|
||||||
response = visit "/"
|
|
||||||
assert response.ok?
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_last_response_is_available
|
|
||||||
visit "/"
|
visit "/"
|
||||||
assert last_response.ok?
|
click_link "there"
|
||||||
|
|
||||||
|
assert_have_tag("form[@method='post'][@action='/go']")
|
||||||
end
|
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
|
# def test_submits_form
|
||||||
# visit "/go"
|
# visit "/go"
|
||||||
# fill_in "Name", :with => "World"
|
# fill_in "Name", :with => "World"
|
||||||
# fill_in "Email", :with => "world@example.org"
|
# fill_in "Email", :with => "world@example.org"
|
||||||
# click_button "Submit"
|
# click_button "Submit"
|
||||||
#
|
#
|
||||||
# assert response_body.include?("Hello, World")
|
# assert_contain "Hello, World"
|
||||||
# assert response_body.include?("Your email is: world@example.org")
|
# assert_contain "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
|
||||||
|
|
||||||
|
def test_check_value_of_field
|
||||||
|
visit "/"
|
||||||
|
assert_equal field_labeled("Prefilled").value, "text"
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_follows_internal_redirects
|
||||||
|
visit "/internal_redirect"
|
||||||
|
assert_contain "visit"
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_does_not_follow_external_redirects
|
||||||
|
visit "/external_redirect"
|
||||||
|
assert last_response.redirect?
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_absolute_url_redirect
|
||||||
|
visit "/absolute_redirect"
|
||||||
|
assert_contain "spam"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user