Skip to content

Commit

Permalink
Lots of work on Cucumber features, adding vendored version of webrat …
Browse files Browse the repository at this point in the history
…(rack branch)
  • Loading branch information
winton committed Jul 3, 2009
1 parent 43fa4dc commit 96ad27f
Show file tree
Hide file tree
Showing 220 changed files with 11,499 additions and 67 deletions.
4 changes: 2 additions & 2 deletions .gitignore
@@ -1,10 +1,10 @@
.DS_Store
*.gem
*.log
config/database.yml
config/deploy.rb
config/mail.yml
coverage
log
pkg
tmp
vendor
tmp
29 changes: 5 additions & 24 deletions Rakefile
@@ -1,5 +1,6 @@
require 'rubygems'
require 'rake'
require 'cucumber/rake/task'
require 'rake/gempackagetask'
require 'spec/rake/spectask'
require 'gemspec'
Expand Down Expand Up @@ -29,34 +30,14 @@ task :install do
`rm -Rf pkg`
end

desc "Package gem"
Rake::GemPackageTask.new(GEM_SPEC) do |pkg|
pkg.gem_spec = GEM_SPEC
Cucumber::Rake::Task.new do |t|
t.cucumber_opts = "--format pretty"
end

desc "Setup project"
task :setup do
name = File.basename(Dir.pwd)
`rm -Rf .git`
begin
dir = Dir['**/gem_template*']
from = dir.pop
if from
rb = from.include?('.rb')
to = File.dirname(from) + "/#{name}#{'.rb' if rb}"
FileUtils.mv(from, to)
end
end while dir.length > 0
Dir["**/*"].each do |path|
next if path.include?('Rakefile')
if File.file?(path)
`sed -i "" 's/gem_template/#{name}/g' #{path}`
end
end
`git init`
Rake::GemPackageTask.new(GEM_SPEC) do |pkg|
pkg.gem_spec = GEM_SPEC
end

desc "Run specs"
Spec::Rake::SpecTask.new do |t|
t.rcov = true
t.spec_opts = ["--format", "specdoc", "--colour"]
Expand Down
3 changes: 3 additions & 0 deletions config/externals.yml
Expand Up @@ -7,3 +7,6 @@ fetcher:
sinatra:
repo: git://github.com/sinatra/sinatra.git
path: vendor
webrat:
repo: git://github.com/brynary/webrat.git
path: vendor
14 changes: 14 additions & 0 deletions features/front_page.feature
@@ -0,0 +1,14 @@
Feature: Front page

As a user
I want to enter my information into a form
In order to submit that information

Scenario: User visits the front page
When a user visits the front page
Then they should see a form
And they should see a "savings" text field
And they should see an "income" text field
And they should see a "bills" text field
And they should see an "email" text field
And they should see a submit button
15 changes: 15 additions & 0 deletions features/step_definitions/front_page.rb
@@ -0,0 +1,15 @@
When /^a user visits the front page$/ do
visit '/'
end

Then /^they should see a form$/ do
assert_have_selector "form[action='/new'][method='post']"
end

Then /^they should see a.? "([^\"]*)" text field$/ do |field|
assert_have_selector "#user_#{field}"
end

Then /^they should see a submit button$/ do
assert_have_selector "input[type=image]"
end
51 changes: 51 additions & 0 deletions features/step_definitions/update_user.rb
@@ -0,0 +1,51 @@
When /^submits a valid form with "([^\"]*)"$/ do |input|
fill_all_with_valid_data
values = case input
when "decimals": [ "1000.00", "5000.00", "2000.00" ]
when "numbers only": [ "1000", "5000", "2000" ]
when "dollar signs": [ "$1000.00", "$5000.00", "$2000.00" ]
end
fill_in "user[savings]", :with => values.pop
fill_in "user[income]", :with => values.pop
fill_in "user[bills]", :with => values.pop
click_button
end

When /^submits an invalid "([^\"]*)".*$/ do |field|
fill_all_with_valid_data
fill_in "user[#{field}]", :with => "invalid"
click_button
end

When /^submits an empty "([^\"]*)".*$/ do |field|
fill_all_with_valid_data
fill_in "user[#{field}]", :with => ""
click_button
end

Then /^they should see a success page$/ do
assert_contain "Success!"
end

Then /^the "([^\"]*)" field should have an error$/ do |field|
assert_have_selector "#user_#{field}"
assert_have_selector ".validation"
end

Then /^the error should be "([^\"]*)"$/ do |error|
within ".validation" do
assert_contain error
end
end

def fill_all_with_valid_data
valid = {
'savings' => '0',
'income' => '0',
'bills' => '0',
'email' => 'cucumber@sumapp.com'
}
valid.each do |key, value|
fill_in "user[#{key}]", :with => value
end
end
23 changes: 23 additions & 0 deletions features/support/env.rb
@@ -0,0 +1,23 @@
$testing = true
$root = File.expand_path(File.dirname(__FILE__) + "/../../")
$:.unshift "#{$root}/lib"

require 'sum'
require 'rack/test'
require 'test/unit'
require "#{$root}/vendor/webrat/lib/webrat"

Webrat.configure do |config|
config.mode = :rack
end

World do
def app
Application
end

include Rack::Test::Methods
include Test::Unit::Assertions
include Webrat::Matchers
include Webrat::Methods
end
76 changes: 76 additions & 0 deletions features/update_user.feature
@@ -0,0 +1,76 @@
Feature: Update user

As a user
I want to submit my information
In order to see a success page

Scenario: User submits a valid form with decimals
When a user visits the front page
And submits a valid form with "decimals"
Then they should see a success page

Scenario: User submits a valid form with numbers only
When a user visits the front page
And submits a valid form with "numbers only"
Then they should see a success page

Scenario: User submits a valid form with dollar signs
When a user visits the front page
And submits a valid form with "dollar signs"
Then they should see a success page

Scenario: User submits an invalid savings amount
When a user visits the front page
And submits an invalid "savings" amount
Then they should see a form
And the "savings" field should have an error
And the error should be "is not a number"

Scenario: User submits an empty savings amount
When a user visits the front page
And submits an empty "savings" amount
Then they should see a form
And the "savings" field should have an error
And the error should be "is not a number"

Scenario: User submits an invalid income amount
When a user visits the front page
And submits an invalid "income" amount
Then they should see a form
And the "income" field should have an error
And the error should be "is not a number"

Scenario: User submits an empty income amount
When a user visits the front page
And submits an empty "income" amount
Then they should see a form
And the "income" field should have an error
And the error should be "is not a number"

Scenario: User submits an invalid bills amount
When a user visits the front page
And submits an invalid "bills" amount
Then they should see a form
And the "bills" field should have an error
And the error should be "is not a number"

Scenario: User submits an empty bills amount
When a user visits the front page
And submits an empty "bills" amount
Then they should see a form
And the "bills" field should have an error
And the error should be "is not a number"

Scenario: User submits an invalid email
When a user visits the front page
And submits an invalid "email"
Then they should see a form
And the "email" field should have an error
And the error should be "is invalid"

Scenario: User submits an empty email
When a user visits the front page
And submits an empty "email"
Then they should see a form
And the "email" field should have an error
And the error should be "can't be blank"
2 changes: 1 addition & 1 deletion lib/sum/boot.rb
Expand Up @@ -4,7 +4,7 @@

# Sinatra
enable :raise_errors
set :environment, $TESTING ? :test : environment
set :environment, $testing ? :test : environment
set :root, File.expand_path("#{File.dirname(__FILE__)}/../../")
set :public, "#{root}/public"
set :logging, true
Expand Down
4 changes: 2 additions & 2 deletions lib/sum/model/user.rb
Expand Up @@ -154,7 +154,7 @@ def before_save_spending_goal
end
end

def local_5am_to_server_time
def local_12am_to_server_time
time = to_local_time(Time.now)
time = DateTime.strptime(
time.strftime("%m/%d/%Y 12:00 AM %Z"),
Expand Down Expand Up @@ -190,7 +190,7 @@ def update_send_at
if self.send_at
self.send_at = self.send_at + 1.day
else
self.send_at = local_5am_to_server_time
self.send_at = local_12am_to_server_time
end
end
end
7 changes: 6 additions & 1 deletion spec/spec_helper.rb
@@ -1,15 +1,20 @@
$TESTING=true
$testing=true
SPEC = File.dirname(__FILE__)
$:.unshift File.expand_path("#{SPEC}/../lib")

require 'sum'
require 'pp'
require 'spec/interop/test'
require 'rack/test'
require File.expand_path("#{SPEC}/../vendor/webrat/lib/webrat")

Spec::Runner.configure do |config|
end

Webrat.configure do |config|
config.mode = :rack
end

def create_valid_user
User.create(
:email => "test@test.com",
Expand Down
28 changes: 0 additions & 28 deletions spec/sum/controller/front_spec.rb

This file was deleted.

0 comments on commit 96ad27f

Please sign in to comment.