Skip to content

Commit

Permalink
small sinatra example
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Holland committed Feb 25, 2009
1 parent 4d43a92 commit 0e12d81
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 0 deletions.
6 changes: 6 additions & 0 deletions examples/sinatra/Rakefile
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions examples/sinatra/app.rb
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions examples/sinatra/features/add.feature
Original file line number Diff line number Diff line change
@@ -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'
15 changes: 15 additions & 0 deletions examples/sinatra/features/step_definitions/add_steps.rb
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions examples/sinatra/features/support/env.rb
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions examples/sinatra/views/add.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<form method='post' action='/add'>
<input name='first'/>
<input name='second'/>
<input type='submit' value='Add'/>
</form>
8 changes: 8 additions & 0 deletions examples/sinatra/views/layout.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head>
<title>Addition</title>
</head>
<body>
<%= yield %>
</body>
</html>

0 comments on commit 0e12d81

Please sign in to comment.