Merge commit 'upstream/master'
This commit is contained in:
commit
73f4c441c1
|
@ -2,6 +2,7 @@
|
|||
|
||||
* Minor enhancements
|
||||
|
||||
* Support for "modular" Sinatra app style (Simon Rozet)
|
||||
* When faced with a label with no for attribute, that contains a hidden field
|
||||
and another field, as can be the case in Rails 2.3's checkbox view,
|
||||
webrat now locates the non-hidden field. (Luke Melia)
|
||||
|
@ -10,6 +11,10 @@
|
|||
* Add application_framework config for Selenium mode to determine how to
|
||||
start and stop the app server (Corey Donohoe)
|
||||
|
||||
* Bug fixes
|
||||
|
||||
* Fix following of absolute redirect URL in Sinatra (Simon Rozet)
|
||||
|
||||
== 0.4.2 / 2009-02-24
|
||||
|
||||
* Major enhancements
|
||||
|
|
|
@ -1,30 +1,44 @@
|
|||
require 'webrat/rack'
|
||||
require 'sinatra'
|
||||
require 'sinatra/test'
|
||||
|
||||
class Sinatra::Application
|
||||
# Override this to prevent Sinatra from barfing on the options passed from RSpec
|
||||
def self.load_default_options_from_command_line!
|
||||
end
|
||||
end
|
||||
|
||||
disable :run
|
||||
disable :reload
|
||||
require "webrat/rack"
|
||||
require "sinatra/test"
|
||||
|
||||
module Webrat
|
||||
class SinatraSession < RackSession #:nodoc:
|
||||
class SinatraSession < RackSession
|
||||
include Sinatra::Test
|
||||
|
||||
attr_reader :request, :response
|
||||
|
||||
%w(get head post put delete).each do |verb|
|
||||
alias_method "orig_#{verb}", verb
|
||||
define_method(verb) do |*args| # (path, data, headers = nil)
|
||||
path, data, headers = *args
|
||||
data = data.inject({}) {|data, (key,value)| data[key] = Rack::Utils.unescape(value); data }
|
||||
params = data.merge(:env => headers || {})
|
||||
self.__send__("orig_#{verb}", path, params)
|
||||
end
|
||||
def initialize(context = nil)
|
||||
super(context)
|
||||
|
||||
app = context.respond_to?(:app) ? context.app : Sinatra::Application
|
||||
@browser = Sinatra::TestHarness.new(app)
|
||||
end
|
||||
|
||||
%w(get head post put delete).each do |verb|
|
||||
class_eval <<-RUBY
|
||||
def #{verb}(path, data, headers = {})
|
||||
params = data.inject({}) do |data, (key,value)|
|
||||
data[key] = Rack::Utils.unescape(value)
|
||||
data
|
||||
end
|
||||
headers["HTTP_HOST"] = "www.example.com"
|
||||
@browser.#{verb}(path, params, headers)
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
def response_body
|
||||
@browser.body
|
||||
end
|
||||
|
||||
def response_code
|
||||
@browser.status
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def response
|
||||
@browser.response
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -61,4 +61,4 @@ __END__
|
|||
|
||||
@@ hello
|
||||
<p>Hello, <%= @user %></p>
|
||||
<p>Your email is: <%= @email %></p>
|
||||
<p>Your email is: <%= @email %></p>
|
|
@ -0,0 +1,16 @@
|
|||
require "rubygems"
|
||||
require "sinatra/base"
|
||||
|
||||
class MyModularApp < 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
|
|
@ -1,6 +1,7 @@
|
|||
require File.dirname(__FILE__) + "/test_helper"
|
||||
require File.dirname(__FILE__) + "/../classic_app"
|
||||
|
||||
class WebratTest < Test::Unit::TestCase
|
||||
class MyClassicAppTest < Test::Unit::TestCase
|
||||
def test_visits_pages
|
||||
visit "/"
|
||||
assert response_body.include?("visit")
|
||||
|
@ -23,7 +24,7 @@ class WebratTest < Test::Unit::TestCase
|
|||
visit "/"
|
||||
assert field_labeled("Prefilled").value, "text"
|
||||
end
|
||||
|
||||
|
||||
def test_follows_internal_redirects
|
||||
visit "/internal_redirect"
|
||||
assert response_body.include?("visit")
|
|
@ -0,0 +1,18 @@
|
|||
require File.dirname(__FILE__) + "/test_helper"
|
||||
require File.dirname(__FILE__) + "/../modular_app"
|
||||
|
||||
class MyModularAppTest < Test::Unit::TestCase
|
||||
def app
|
||||
MyModularApp
|
||||
end
|
||||
|
||||
def test_it_works
|
||||
visit "/"
|
||||
assert_contain "Hello World"
|
||||
end
|
||||
|
||||
def test_redirects
|
||||
visit "/redirect_absolute_url"
|
||||
assert_equal "spam", response_body
|
||||
end
|
||||
end
|
|
@ -1,8 +1,6 @@
|
|||
require "rubygems"
|
||||
require "test/unit"
|
||||
require "redgreen"
|
||||
require "sinatra"
|
||||
require File.dirname(__FILE__) + "/../app"
|
||||
|
||||
require File.dirname(__FILE__) + "/../../../../lib/webrat"
|
||||
|
||||
|
@ -12,6 +10,7 @@ end
|
|||
|
||||
class Test::Unit::TestCase
|
||||
include Webrat::Methods
|
||||
|
||||
include Webrat::Matchers
|
||||
|
||||
Webrat::Methods.delegate_to_session :response_code, :response_body
|
||||
end
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
||||
require "webrat/sinatra"
|
|
@ -1,28 +0,0 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/helper')
|
||||
|
||||
describe Webrat::SinatraSession, "API" do
|
||||
before :each do
|
||||
Webrat.configuration.mode = :sinatra
|
||||
@sinatra_session = Webrat::SinatraSession.new
|
||||
end
|
||||
|
||||
it "should delegate get to sinatras get" do
|
||||
@sinatra_session.should_receive(:orig_get).with("url", { :env => "headers" })
|
||||
@sinatra_session.get("url", {}, "headers")
|
||||
end
|
||||
|
||||
it "should delegate post to sinatras post" do
|
||||
@sinatra_session.should_receive(:orig_post).with("url", { :env => "headers" })
|
||||
@sinatra_session.post("url", {}, "headers")
|
||||
end
|
||||
|
||||
it "should delegate put to sinatras put" do
|
||||
@sinatra_session.should_receive(:orig_put).with("url", { :env => "headers" })
|
||||
@sinatra_session.put("url", {}, "headers")
|
||||
end
|
||||
|
||||
it "should delegate delete to sinatras delete" do
|
||||
@sinatra_session.should_receive(:orig_delete).with("url", { :env => "headers" })
|
||||
@sinatra_session.delete("url", {}, "headers")
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue