webrat/spec/integration/sinatra/app.rb

64 lines
1.0 KiB
Ruby
Raw Permalink Normal View History

2008-12-29 08:41:50 +00:00
require "rubygems"
require "sinatra"
2009-01-05 04:56:52 +00:00
2008-12-29 08:41:50 +00:00
use_in_file_templates!
2009-01-05 04:56:52 +00:00
2008-12-29 08:41:50 +00:00
get "/" do
erb :home
end
2009-01-05 04:56:52 +00:00
2008-12-29 08:41:50 +00:00
get "/go" do
erb :go
end
2009-01-05 04:56:52 +00:00
get "/internal_redirect" do
redirect "/"
end
2009-01-05 04:56:52 +00:00
get "/external_redirect" do
redirect "http://google.com"
end
2008-12-29 08:41:50 +00:00
post "/go" do
@user = params[:name]
@email = params[:email]
2008-12-29 08:41:50 +00:00
erb :hello
end
2009-01-05 04:56:52 +00:00
2008-12-29 08:41:50 +00:00
__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>
2009-01-05 04:56:52 +00:00
2008-12-29 08:41:50 +00:00
@@ home
<p> visit <a href="/go">there</a></p>
2009-01-05 04:56:52 +00:00
<form>
<label>
Prefilled
<input type="text" name="prefilled" value="text" />
</label>
</form>
2008-12-29 08:41:50 +00:00
@@ go
<form method="post" action="/go">
<div>
<label for="name">Name</label>
<input type="text" name="name" id="name">
</div>
<div>
<label for="email">Email</label>
<input type="text" name="email" id="email">
</div>
2008-12-29 08:41:50 +00:00
<input type="submit" value="Submit" />
</form>
2009-01-05 04:56:52 +00:00
2008-12-29 08:41:50 +00:00
@@ hello
<p>Hello, <%= @user %></p>
<p>Your email is: <%= @email %></p>