Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
89 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require "rake/testtask" | ||
|
||
Rake::TestTask.new do |t| | ||
t.test_files = FileList["test/*_test.rb"] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |