diff --git a/Rakefile b/Rakefile index df8279c..581fdc5 100644 --- a/Rakefile +++ b/Rakefile @@ -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" @@ -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 diff --git a/spec/integration/mechanize/Rakefile b/spec/integration/mechanize/Rakefile new file mode 100644 index 0000000..c9c04c9 --- /dev/null +++ b/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 \ No newline at end of file diff --git a/spec/integration/mechanize/config.ru b/spec/integration/mechanize/config.ru new file mode 100644 index 0000000..1bdb607 --- /dev/null +++ b/spec/integration/mechanize/config.ru @@ -0,0 +1,2 @@ +require "sample_app" +run SampleApp \ No newline at end of file diff --git a/spec/integration/mechanize/sample_app.rb b/spec/integration/mechanize/sample_app.rb new file mode 100644 index 0000000..13a4b78 --- /dev/null +++ b/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 diff --git a/spec/integration/mechanize/spec/mechanize_spec.rb b/spec/integration/mechanize/spec/mechanize_spec.rb new file mode 100644 index 0000000..0c21da3 --- /dev/null +++ b/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 diff --git a/spec/integration/mechanize/spec/spec_helper.rb b/spec/integration/mechanize/spec/spec_helper.rb new file mode 100644 index 0000000..038ae76 --- /dev/null +++ b/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 +