Permalink
Browse files

small sinatra example

  • Loading branch information...
Rob Holland
Rob Holland committed Feb 25, 2009
1 parent 4d43a92 commit 0e12d8100ca8541af014abe6a480c53a90b6aebd
@@ -0,0 +1,6 @@
$:.unshift(File.dirname(__FILE__) + '/../../lib')
require 'cucumber/rake/task'
Cucumber::Rake::Task.new do |t|
t.cucumber_opts = "--format pretty"
end
View
@@ -0,0 +1,9 @@
require 'sinatra'
get '/add' do
erb :add
end
post '/add' do
"Answer: #{params[:first].to_i + params[:second].to_i}"
end
@@ -0,0 +1,11 @@
Feature: Addition
In order to avoid silly mistakes
As a math idiot
I want to be told the sum of two numbers
Scenario: Add two numbers
Given I visit the calculator page
And I fill in '50' for 'first'
And I fill in '70' for 'second'
When I press 'Add'
Then I should see 'Answer: 120'
@@ -0,0 +1,15 @@
Given /^I visit the calculator page$/ do
visit '/add'
end
Given /^I fill in '(.*)' for '(.*)'$/ do |value, field|
fill_in(field, :with => value)
end
When /^I press '(.*)'$/ do |name|
click_button(name)
end
Then /^I should see '(.*)'$/ do |text|
response.body.should =~ /#{text}/m
end
@@ -0,0 +1,20 @@
# Sinatra
require File.join(File.dirname(__FILE__), *%w[.. .. app])
# Force the application name because polyglot breaks the auto-detection logic.
Sinatra::Application.app_file = File.join(File.dirname(__FILE__), *%w[.. .. app.rb])
# RSpec
require 'spec/expectations'
# Webrat
require 'webrat'
Webrat.configure do |config|
config.mode = :sinatra
end
World do
include Webrat::Matchers
include Webrat::HaveTagMatcher
Webrat::SinatraSession.new
end
@@ -0,0 +1,5 @@
<form method='post' action='/add'>
<input name='first'/>
<input name='second'/>
<input type='submit' value='Add'/>
</form>
@@ -0,0 +1,8 @@
<html>
<head>
<title>Addition</title>
</head>
<body>
<%= yield %>
</body>
</html>

0 comments on commit 0e12d81

Please sign in to comment.