Add very basic spec for Mechanize
This commit is contained in:
parent
e4ea9134a7
commit
0412543e5a
10
Rakefile
10
Rakefile
@ -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
|
||||||
|
|
||||||
|
7
spec/integration/mechanize/Rakefile
Normal file
7
spec/integration/mechanize/Rakefile
Normal 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
|
2
spec/integration/mechanize/config.ru
Normal file
2
spec/integration/mechanize/config.ru
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
require "sample_app"
|
||||||
|
run SampleApp
|
20
spec/integration/mechanize/sample_app.rb
Normal file
20
spec/integration/mechanize/sample_app.rb
Normal 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
|
22
spec/integration/mechanize/spec/mechanize_spec.rb
Normal file
22
spec/integration/mechanize/spec/mechanize_spec.rb
Normal 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
|
27
spec/integration/mechanize/spec/spec_helper.rb
Normal file
27
spec/integration/mechanize/spec/spec_helper.rb
Normal 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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user