Add very basic spec for Mechanize

This commit is contained in:
Bryan Helmkamp 2009-08-12 21:37:15 -04:00
parent e4ea9134a7
commit 0412543e5a
6 changed files with 87 additions and 1 deletions

View File

@ -113,7 +113,7 @@ end
namespace :spec do namespace :spec do
desc "Run the integration specs" desc "Run the integration specs"
task :integration => ["integration:rails", "integration:merb", "integration:sinatra", "integration:rack"] task :integration => ["integration:rails", "integration:merb", "integration:sinatra", "integration:rack", "integration:mechanize"]
namespace :integration do namespace :integration do
desc "Run the Rails integration specs" desc "Run the Rails integration specs"
@ -158,6 +158,14 @@ namespace :spec do
raise "Rack integration tests failed" unless result raise "Rack integration tests failed" unless result
end end
end end
desc "Run the Mechanize integration specs"
task :mechanize do
Dir.chdir "spec/integration/mechanize" do
result = system "rake spec"
raise "Mechanize integration tests failed" unless result
end
end
end end
end end

View File

@ -0,0 +1,7 @@
require 'rubygems'
require 'spec/rake/spectask'
Spec::Rake::SpecTask.new do |t|
t.spec_opts = ['--color']
t.spec_files = FileList['spec/**/*_spec.rb']
end

View File

@ -0,0 +1,2 @@
require "sample_app"
run SampleApp

View File

@ -0,0 +1,20 @@
require "rubygems"
require "sinatra/base"
class SampleApp < Sinatra::Default
get "/" do
"Hello World"
end
get "/internal_redirect" do
redirect URI.join(request.url, "redirected").to_s
end
get "/external_redirect" do
redirect "http://example.tst/"
end
get "/redirected" do
"Redirected"
end
end

View File

@ -0,0 +1,22 @@
require File.dirname(__FILE__) + "/spec_helper"
describe "Webrat's Mechanize mode" do
it "should work" do
response = visit("http://localhost:9292/")
response.should contain("Hello World")
end
it "should follow redirects" do
response = visit("http://localhost:9292/internal_redirect")
response.should contain("Redirected")
end
it "should follow links"
it "should submit forms"
it "should not follow external redirects" do
pending do
response = visit("http://localhost:9292/external_redirect")
response.should contain("Foo")
end
end
end

View File

@ -0,0 +1,27 @@
require "rubygems"
require "spec"
$LOAD_PATH.unshift File.dirname(__FILE__) + "/../../../../lib"
require "webrat"
Webrat.configure do |config|
config.mode = :mechanize
end
Spec::Runner.configure do |config|
config.include Webrat::Methods
config.include Webrat::Matchers
config.before :suite do
if File.exists?("rack.pid")
Process.kill("TERM", File.read("rack.pid").to_i)
end
system "rackup --daemonize --pid rack.pid config.ru"
end
config.after :suite do
Process.kill("TERM", File.read("rack.pid").to_i)
end
end