Skip to content

Commit

Permalink
Add very basic spec for Mechanize
Browse files Browse the repository at this point in the history
  • Loading branch information
brynary committed Aug 13, 2009
1 parent e4ea913 commit 0412543
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Rakefile
Expand Up @@ -113,7 +113,7 @@ end

namespace :spec do
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
desc "Run the Rails integration specs"
Expand Down Expand Up @@ -158,6 +158,14 @@ namespace :spec do
raise "Rack integration tests failed" unless result
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

Expand Down
7 changes: 7 additions & 0 deletions spec/integration/mechanize/Rakefile
@@ -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
2 changes: 2 additions & 0 deletions spec/integration/mechanize/config.ru
@@ -0,0 +1,2 @@
require "sample_app"
run SampleApp
20 changes: 20 additions & 0 deletions spec/integration/mechanize/sample_app.rb
@@ -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
22 changes: 22 additions & 0 deletions spec/integration/mechanize/spec/mechanize_spec.rb
@@ -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
27 changes: 27 additions & 0 deletions spec/integration/mechanize/spec/spec_helper.rb
@@ -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

0 comments on commit 0412543

Please sign in to comment.