diff --git a/Rakefile b/Rakefile index e80cd8e..db3e0d1 100644 --- a/Rakefile +++ b/Rakefile @@ -108,12 +108,17 @@ namespace :spec do task :integration do Dir.chdir "spec/integration/rails" do result = system "rake test:integration" - raise "Tests failed" unless result + raise "Integration tests failed for rails" unless result end Dir.chdir "spec/integration/merb" do result = system "rake spec" - raise "Tests failed" unless result + raise "Integration tests failed for merb" unless result + end + + Dir.chdir "spec/integration/sinatra" do + result = system "rake test" + raise "Integration tests failed for sinatra" unless result end end end diff --git a/spec/integration/sinatra/Rakefile b/spec/integration/sinatra/Rakefile new file mode 100644 index 0000000..cfba77d --- /dev/null +++ b/spec/integration/sinatra/Rakefile @@ -0,0 +1,5 @@ +require "rake/testtask" + +Rake::TestTask.new do |t| + t.test_files = FileList["test/*_test.rb"] +end diff --git a/spec/integration/sinatra/app.rb b/spec/integration/sinatra/app.rb new file mode 100644 index 0000000..4235ebf --- /dev/null +++ b/spec/integration/sinatra/app.rb @@ -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 + + + sinatra testing with webrat + + <%= yield %> + + + +@@ home +

visit there

+ +@@ go +
+ + + +
+ +@@ hello +

Hello, <%= @user %>

\ No newline at end of file diff --git a/spec/integration/sinatra/test/test_helper.rb b/spec/integration/sinatra/test/test_helper.rb new file mode 100644 index 0000000..c01c9b2 --- /dev/null +++ b/spec/integration/sinatra/test/test_helper.rb @@ -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 diff --git a/spec/integration/sinatra/test/webrat_test.rb b/spec/integration/sinatra/test/webrat_test.rb new file mode 100644 index 0000000..fe198f8 --- /dev/null +++ b/spec/integration/sinatra/test/webrat_test.rb @@ -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?('
') + end + + def test_submits_form + visit "/go" + fill_in "Name", :with => "World" + click_button "Submit" + + assert response_body.include?("Hello, World") + end +end