Add integration tests for sinatra
This commit is contained in:
parent
33e853710e
commit
499dcefefe
9
Rakefile
9
Rakefile
@ -108,12 +108,17 @@ namespace :spec do
|
|||||||
task :integration do
|
task :integration do
|
||||||
Dir.chdir "spec/integration/rails" do
|
Dir.chdir "spec/integration/rails" do
|
||||||
result = system "rake test:integration"
|
result = system "rake test:integration"
|
||||||
raise "Tests failed" unless result
|
raise "Integration tests failed for rails" unless result
|
||||||
end
|
end
|
||||||
|
|
||||||
Dir.chdir "spec/integration/merb" do
|
Dir.chdir "spec/integration/merb" do
|
||||||
result = system "rake spec"
|
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
|
end
|
||||||
end
|
end
|
||||||
|
5
spec/integration/sinatra/Rakefile
Normal file
5
spec/integration/sinatra/Rakefile
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
require "rake/testtask"
|
||||||
|
|
||||||
|
Rake::TestTask.new do |t|
|
||||||
|
t.test_files = FileList["test/*_test.rb"]
|
||||||
|
end
|
41
spec/integration/sinatra/app.rb
Normal file
41
spec/integration/sinatra/app.rb
Normal file
@ -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
|
||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||||
|
<html>
|
||||||
|
<title>sinatra testing with webrat</title>
|
||||||
|
<body>
|
||||||
|
<%= yield %>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
|
@@ home
|
||||||
|
<p> visit <a href="/go">there</a></p>
|
||||||
|
|
||||||
|
@@ go
|
||||||
|
<form method="post" action="/go">
|
||||||
|
<label for="name">Name</label>
|
||||||
|
<input type="text" name="name" id="name">
|
||||||
|
<input type="submit" value="Submit" />
|
||||||
|
</form>
|
||||||
|
|
||||||
|
@@ hello
|
||||||
|
<p>Hello, <%= @user %></p>
|
17
spec/integration/sinatra/test/test_helper.rb
Normal file
17
spec/integration/sinatra/test/test_helper.rb
Normal file
@ -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
|
19
spec/integration/sinatra/test/webrat_test.rb
Normal file
19
spec/integration/sinatra/test/webrat_test.rb
Normal file
@ -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?('<form method="post" action="/go">')
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_submits_form
|
||||||
|
visit "/go"
|
||||||
|
fill_in "Name", :with => "World"
|
||||||
|
click_button "Submit"
|
||||||
|
|
||||||
|
assert response_body.include?("Hello, World")
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user