Merge branch 'foca/master'
This commit is contained in:
commit
c3120833b0
14
Rakefile
14
Rakefile
|
@ -105,14 +105,14 @@ end
|
|||
|
||||
namespace :spec do
|
||||
desc "Run the integration specs"
|
||||
task :integration => ["integration:rails", "integration:merb"]
|
||||
task :integration => ["integration:rails", "integration:merb", "integration:sinatra"]
|
||||
|
||||
namespace :integration do
|
||||
desc "Run the Rails integration specs"
|
||||
task :rails do
|
||||
Dir.chdir "spec/integration/rails" do
|
||||
result = system "rake test:integration"
|
||||
raise "Tests failed" unless result
|
||||
raise "Rails integration tests failed" unless result
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -120,7 +120,15 @@ namespace :spec do
|
|||
task :merb do
|
||||
Dir.chdir "spec/integration/merb" do
|
||||
result = system "rake spec"
|
||||
raise "Tests failed" unless result
|
||||
raise "Merb integration tests failed" unless result
|
||||
end
|
||||
end
|
||||
|
||||
desc "Run the Sinatra integration specs"
|
||||
task :sinatra do
|
||||
Dir.chdir "spec/integration/sinatra" do
|
||||
result = system "rake test"
|
||||
raise "Sinatra tntegration tests failed" unless result
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,15 +2,27 @@ require 'webrat/rack'
|
|||
require 'sinatra'
|
||||
require 'sinatra/test/methods'
|
||||
|
||||
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
|
||||
|
||||
module Webrat
|
||||
class SinatraSession < RackSession #:nodoc:
|
||||
include Sinatra::Test::Methods
|
||||
|
||||
attr_reader :request, :response
|
||||
|
||||
%w(get head post put delete).each do |verb|
|
||||
define_method(verb) do |*args| # (path, data, headers = nil)
|
||||
path, data, headers = *args
|
||||
params = data.merge({:env => headers || {}})
|
||||
params = data.merge(:env => headers || {})
|
||||
self.__send__("#{verb}_it", path, params)
|
||||
request_page(response.location, :get, {}) while response.redirect?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
require "rake/testtask"
|
||||
|
||||
Rake::TestTask.new do |t|
|
||||
t.test_files = FileList["test/*_test.rb"]
|
||||
end
|
|
@ -0,0 +1,41 @@
|
|||
require "rubygems"
|
||||
require "sinatra"
|
||||
|
||||
use_in_file_templates!
|
||||
|
||||
get "/" do
|
||||
erb :home
|
||||
end
|
||||
|
||||
get "/go" do
|
||||
erb :go
|
||||
end
|
||||
|
||||
post "/go" do
|
||||
@user = params[:name]
|
||||
erb :hello
|
||||
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>
|
||||
|
||||
@@ go
|
||||
<form method="post" action="/go">
|
||||
<label for="name">Name</label>
|
||||
<input type="text" name="name" id="name">
|
||||
<input type="submit" value="Submit" />
|
||||
</form>
|
||||
|
||||
@@ hello
|
||||
<p>Hello, <%= @user %></p>
|
|
@ -0,0 +1,17 @@
|
|||
require "rubygems"
|
||||
require "test/unit"
|
||||
require "redgreen"
|
||||
require "sinatra"
|
||||
require File.dirname(__FILE__) + "/../app"
|
||||
|
||||
require File.dirname(__FILE__) + "/../../../../lib/webrat"
|
||||
|
||||
Webrat.configure do |config|
|
||||
config.mode = :sinatra
|
||||
end
|
||||
|
||||
class Test::Unit::TestCase
|
||||
include Webrat::Methods
|
||||
|
||||
Webrat::Methods.delegate_to_session :response_code, :response_body
|
||||
end
|
|
@ -0,0 +1,19 @@
|
|||
require File.dirname(__FILE__) + "/test_helper"
|
||||
|
||||
class WebratTest < Test::Unit::TestCase
|
||||
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"
|
||||
click_button "Submit"
|
||||
|
||||
assert response_body.include?("Hello, World")
|
||||
end
|
||||
end
|
|
@ -1,15 +1,2 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
||||
require "webrat/sinatra"
|
||||
|
||||
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
|
||||
|
||||
Sinatra::Application.default_options.merge!(
|
||||
:env => :test,
|
||||
:run => false,
|
||||
:raise_errors => true,
|
||||
:logging => false
|
||||
)
|
|
@ -1,9 +1,11 @@
|
|||
require File.expand_path(File.dirname(__FILE__) + '/helper')
|
||||
|
||||
describe Webrat::SinatraSession do
|
||||
describe Webrat::SinatraSession, "API" do
|
||||
before :each do
|
||||
Webrat.configuration.mode = :sinatra
|
||||
@sinatra_session = Webrat::SinatraSession.new
|
||||
@response = mock("response", :redirect? => false)
|
||||
@sinatra_session.stub!(:response => @response)
|
||||
end
|
||||
|
||||
it "should delegate get to get_it" do
|
||||
|
@ -25,4 +27,14 @@ describe Webrat::SinatraSession do
|
|||
@sinatra_session.should_receive(:delete_it).with("url", { :env => "headers" })
|
||||
@sinatra_session.delete("url", {}, "headers")
|
||||
end
|
||||
|
||||
it "should use Session#request_page to handle redirects" do
|
||||
@response.should_receive(:redirect?).twice.and_return(true, false)
|
||||
@response.should_receive(:location).and_return("redirect url")
|
||||
|
||||
@sinatra_session.should_receive(:get_it).with("original url", { :env => "headers" })
|
||||
@sinatra_session.should_receive(:request_page).with("redirect url", :get, {})
|
||||
|
||||
@sinatra_session.get("original url", {}, "headers")
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue