From 67628f5f683a238e007dee1d61ce781ee5739e77 Mon Sep 17 00:00:00 2001 From: Dan Croak Date: Wed, 1 Jul 2009 15:54:12 -0400 Subject: [PATCH] added cucumber --- README.markdown | 101 +++++++++++++++-------------------------------------------------------------------------------------- config/environments/cucumber.rb | 21 +++++++++++++++++++++ doc/README_FOR_TEMPLATE | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ features/step_definitions/webrat_steps.rb | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ features/support/env.rb | 24 ++++++++++++++++++++++++ features/support/paths.rb | 27 +++++++++++++++++++++++++++ lib/tasks/cucumber.rake | 16 ++++++++++++++++ script/cucumber | 8 ++++++++ 8 files changed, 320 insertions(+), 86 deletions(-) create mode 100644 config/environments/cucumber.rb create mode 100644 doc/README_FOR_TEMPLATE create mode 100644 features/step_definitions/webrat_steps.rb create mode 100644 features/support/env.rb create mode 100644 features/support/paths.rb create mode 100644 lib/tasks/cucumber.rake create mode 100755 script/cucumber diff --git a/README.markdown b/README.markdown index 4bde1e0..50e1c50 100644 --- a/README.markdown +++ b/README.markdown @@ -1,97 +1,26 @@ -This is Heroku Suspenders, the thoughtbot rails template modified to be used for deployment to Heroku. To create a new project, checkout this -repository and run: +Heroku's Suspenders +------------------- - ./script/create_project projectname +A Rails app with intelligent defaults from thoughtbot. -This will create a project in ../projectname. You should then follow the -instructions on Github to upload that project there. This script creates an -entirely new git repository, and is not meant to be used against an existing -repo. +* Rails 2.3.2 +* Clearance for authentication +* Paperclip for file uploads, set for Amazon S3 +* Cucumber, Shoulda, Factory Girl, & Mocha for testing +* Will Paginate for pagination +* RedCloth for Textile formatting +* Hoptoad Notifier for exception notification +* Email defaults configured for Heroku -When making a change to a project that was created via this template, consider -whether it's a change that should be made across all projects. If so, then -make the change in this template, and pull it into your project via: +Get the latest & greatest at anytime with: - git pull heroku_suspenders master + git pull heroku_suspenders master -About Suspenders ----------------- - -Suspenders was created for use at thoughtbot, inc. (http://thoughtbot.com) as a -baseline application setup, with reasonable default plugins that the majority (if not all) -of our applications used, as well as best-practice configuration options. - -Suspenders currently includes Rails 2.3.2 - -Gems (unpacked in vendor/gems): -------------------------------- - -For record pagination: - - will_paginate - -For text formatting: - - RedCloth - -For testing: - - mocha - factory_girl - shoulda - -Plugins (in vendor/plugins): ----------------------------- - - hoptoad_notifier - limerick_rake - -Initializers (in config/initializers) -------------------------------------- - - action_mailer_configs.rb - We use SMTP by default in all applications. - - hoptoad.rb - Get your API key at http://hoptoadapp.com - - requires.rb - Automatically requires everything in - lib/ - lib/extensions - test/mocks/RAILS_ENV (Removed in Rails 2, we decided to keep it) - Add other things you need to require in here. - - time_formats.rb - Two time formats are available by default, :short_date and :long_date. - Add other time formats here. - -Rake Tasks ----------- - -Rake tasks are contained in the limerick_rake gem. - - bootstrap - Provides rake tasks for loading data into the database. These are used for an initial application dataset needed for production. - -Testing -------- - -Testing is done utilizing Test::Unit, Shoulda, factory_girl, and mocha. - -factory_girl is a fixture replacement library, following the factory pattern. Place your -factories in test/factories.rb. The fixture directory has been removed, as fixtures are not -used. - -Shoulda is a pragmatic testing framework for TDD and BDD built on top of Test::Unit. - -jferris-mocha --version '0.9.5.0.1241126838' --source gems.github.com -thoughtbot-factory_girl --version '>= 1.2.0' --source gems.github.com -thoughtbot-shoulda --version '>= 2.10.1' --source gems.github.com +More details available in doc/README_FOR_TEMPLATE. Mascot ------ The official Suspenders mascot is Suspenders Boy: - http://media.tumblr.com/1TEAMALpseh5xzf0Jt6bcwSMo1_400.png + http://media.tumblr.com/1TEAMALpseh5xzf0Jt6bcwSMo1_400.png diff --git a/config/environments/cucumber.rb b/config/environments/cucumber.rb new file mode 100644 index 0000000..5f4ac7d --- /dev/null +++ b/config/environments/cucumber.rb @@ -0,0 +1,21 @@ +config.cache_classes = true # This must be true for Cucumber to operate correctly! + +# Log error messages when you accidentally call methods on nil. +config.whiny_nils = true + +# Show full error reports and disable caching +config.action_controller.consider_all_requests_local = true +config.action_controller.perform_caching = false + +# Disable request forgery protection in test environment +config.action_controller.allow_forgery_protection = false + +# Tell Action Mailer not to deliver emails to the real world. +# The :test delivery method accumulates sent emails in the +# ActionMailer::Base.deliveries array. +config.action_mailer.delivery_method = :test + +config.gem "cucumber", :lib => false, :version => ">=0.3.11" unless File.directory?(File.join(Rails.root, 'vendor/plugins/cucumber')) +config.gem "webrat", :lib => false, :version => ">=0.4.4" unless File.directory?(File.join(Rails.root, 'vendor/plugins/webrat')) +config.gem "rspec", :lib => false, :version => ">=1.2.6" unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec')) +config.gem "rspec-rails", :lib => 'spec/rails', :version => ">=1.2.6" unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec-rails')) diff --git a/doc/README_FOR_TEMPLATE b/doc/README_FOR_TEMPLATE new file mode 100644 index 0000000..1426497 --- /dev/null +++ b/doc/README_FOR_TEMPLATE @@ -0,0 +1,90 @@ +This is Heroku Suspenders, the thoughtbot rails template modified to be used for deployment to Heroku. To create a new project, checkout this +repository and run: + + ./script/create_project projectname + +This will create a project in ../projectname. You should then follow the +instructions on Github to upload that project there. This script creates an +entirely new git repository, and is not meant to be used against an existing +repo. + +When making a change to a project that was created via this template, consider +whether it's a change that should be made across all projects. If so, then +make the change in this template, and pull it into your project via: + + git pull heroku_suspenders master + +About Suspenders +---------------- + +Suspenders was created for use at thoughtbot, inc. (http://thoughtbot.com) as a +baseline application setup, with reasonable default plugins that the majority (if not all) of our applications used, as well as best-practice configuration options. + +Suspenders currently includes Rails 2.3.2 + +Gems (unpacked in vendor/gems): +------------------------------- + +For record pagination: + + will_paginate + +For text formatting: + + RedCloth + +For testing: + + mocha + factory_girl + shoulda + +Plugins (in vendor/plugins): +---------------------------- + + hoptoad_notifier + limerick_rake + +Initializers (in config/initializers) +------------------------------------- + +We use SMTP by default in all applications. + + action_mailer_configs.rb + +Get your API key at http://hoptoadapp.com + + hoptoad.rb + +Two time formats are available by default, :short_date and :long_date. Add other time formats here. + + time_formats.rb + +Rake Tasks +---------- + +Rake tasks are contained in the limerick_rake gem. Provides rake tasks for loading data into the database. These are used for an initial application dataset needed for production. + + bootstrap + +Testing +------- + +Testing is done utilizing Test::Unit, Shoulda, factory_girl, and mocha. + +factory_girl is a fixture replacement library, following the factory pattern. Place your +factories in test/factories.rb. The fixture directory has been removed, as fixtures are not +used. + +Shoulda is a pragmatic testing framework for TDD and BDD built on top of Test::Unit. + + jferris-mocha --version '0.9.5.0.1241126838' --source gems.github.com + thoughtbot-factory_girl --version '>= 1.2.0' --source gems.github.com + thoughtbot-shoulda --version '>= 2.10.1' --source gems.github.com + +Mascot +------ + +The official Suspenders mascot is Suspenders Boy: + + http://media.tumblr.com/1TEAMALpseh5xzf0Jt6bcwSMo1_400.png diff --git a/features/step_definitions/webrat_steps.rb b/features/step_definitions/webrat_steps.rb new file mode 100644 index 0000000..28130ae --- /dev/null +++ b/features/step_definitions/webrat_steps.rb @@ -0,0 +1,119 @@ +require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths")) + +# Commonly used webrat steps +# http://github.com/brynary/webrat + +Given /^I am on (.+)$/ do |page_name| + visit path_to(page_name) +end + +When /^I go to (.+)$/ do |page_name| + visit path_to(page_name) +end + +When /^I press "([^\"]*)"$/ do |button| + click_button(button) +end + +When /^I follow "([^\"]*)"$/ do |link| + click_link(link) +end + +When /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value| + fill_in(field, :with => value) +end + +When /^I select "([^\"]*)" from "([^\"]*)"$/ do |value, field| + select(value, :from => field) +end + +# Use this step in conjunction with Rail's datetime_select helper. For example: +# When I select "December 25, 2008 10:00" as the date and time +When /^I select "([^\"]*)" as the date and time$/ do |time| + select_datetime(time) +end + +# Use this step when using multiple datetime_select helpers on a page or +# you want to specify which datetime to select. Given the following view: +# <%= f.label :preferred %>
+# <%= f.datetime_select :preferred %> +# <%= f.label :alternative %>
+# <%= f.datetime_select :alternative %> +# The following steps would fill out the form: +# When I select "November 23, 2004 11:20" as the "Preferred" date and time +# And I select "November 25, 2004 10:30" as the "Alternative" date and time +When /^I select "([^\"]*)" as the "([^\"]*)" date and time$/ do |datetime, datetime_label| + select_datetime(datetime, :from => datetime_label) +end + +# Use this step in conjunction with Rail's time_select helper. For example: +# When I select "2:20PM" as the time +# Note: Rail's default time helper provides 24-hour time-- not 12 hour time. Webrat +# will convert the 2:20PM to 14:20 and then select it. +When /^I select "([^\"]*)" as the time$/ do |time| + select_time(time) +end + +# Use this step when using multiple time_select helpers on a page or you want to +# specify the name of the time on the form. For example: +# When I select "7:30AM" as the "Gym" time +When /^I select "([^\"]*)" as the "([^\"]*)" time$/ do |time, time_label| + select_time(time, :from => time_label) +end + +# Use this step in conjunction with Rail's date_select helper. For example: +# When I select "February 20, 1981" as the date +When /^I select "([^\"]*)" as the date$/ do |date| + select_date(date) +end + +# Use this step when using multiple date_select helpers on one page or +# you want to specify the name of the date on the form. For example: +# When I select "April 26, 1982" as the "Date of Birth" date +When /^I select "([^\"]*)" as the "([^\"]*)" date$/ do |date, date_label| + select_date(date, :from => date_label) +end + +When /^I check "([^\"]*)"$/ do |field| + check(field) +end + +When /^I uncheck "([^\"]*)"$/ do |field| + uncheck(field) +end + +When /^I choose "([^\"]*)"$/ do |field| + choose(field) +end + +When /^I attach the file at "([^\"]*)" to "([^\"]*)"$/ do |path, field| + attach_file(field, path) +end + +Then /^I should see "([^\"]*)"$/ do |text| + response.should contain(text) +end + +Then /^I should not see "([^\"]*)"$/ do |text| + response.should_not contain(text) +end + +Then /^the "([^\"]*)" field should contain "([^\"]*)"$/ do |field, value| + field_labeled(field).value.should =~ /#{value}/ +end + +Then /^the "([^\"]*)" field should not contain "([^\"]*)"$/ do |field, value| + field_labeled(field).value.should_not =~ /#{value}/ +end + +Then /^the "([^\"]*)" checkbox should be checked$/ do |label| + field_labeled(label).should be_checked +end + +Then /^the "([^\"]*)" checkbox should not be checked$/ do |label| + field_labeled(label).should_not be_checked +end + +Then /^I should be on (.+)$/ do |page_name| + URI.parse(current_url).path.should == path_to(page_name) +end diff --git a/features/support/env.rb b/features/support/env.rb new file mode 100644 index 0000000..dd985f3 --- /dev/null +++ b/features/support/env.rb @@ -0,0 +1,24 @@ +# Sets up the Rails environment for Cucumber +ENV["RAILS_ENV"] ||= "cucumber" +require File.expand_path(File.dirname(__FILE__) + '/../../config/environment') +require 'cucumber/rails/world' + +# Comment out the next line if you don't want Cucumber Unicode support +require 'cucumber/formatter/unicode' + +# Comment out the next line if you don't want transactions to +# open/roll back around each scenario +Cucumber::Rails.use_transactional_fixtures + +# Comment out the next line if you want Rails' own error handling +# (e.g. rescue_action_in_public / rescue_responses / rescue_from) +Cucumber::Rails.bypass_rescue + +require 'webrat' + +Webrat.configure do |config| + config.mode = :rails +end + +require 'cucumber/rails/rspec' +require 'webrat/core/matchers' diff --git a/features/support/paths.rb b/features/support/paths.rb new file mode 100644 index 0000000..f2a9232 --- /dev/null +++ b/features/support/paths.rb @@ -0,0 +1,27 @@ +module NavigationHelpers + # Maps a name to a path. Used by the + # + # When /^I go to (.+)$/ do |page_name| + # + # step definition in webrat_steps.rb + # + def path_to(page_name) + case page_name + + when /the homepage/ + '/' + + # Add more mappings here. + # Here is a more fancy example: + # + # when /^(.*)'s profile page$/i + # user_profile_path(User.find_by_login($1)) + + else + raise "Can't find mapping from \"#{page_name}\" to a path.\n" + + "Now, go and add a mapping in #{__FILE__}" + end + end +end + +World(NavigationHelpers) diff --git a/lib/tasks/cucumber.rake b/lib/tasks/cucumber.rake new file mode 100644 index 0000000..8744327 --- /dev/null +++ b/lib/tasks/cucumber.rake @@ -0,0 +1,16 @@ +$LOAD_PATH.unshift(RAILS_ROOT + '/vendor/plugins/cucumber/lib') if File.directory?(RAILS_ROOT + '/vendor/plugins/cucumber/lib') + +begin + require 'cucumber/rake/task' + + Cucumber::Rake::Task.new(:features) do |t| + t.fork = true + t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'pretty')] + end + task :features => 'db:test:prepare' +rescue LoadError + desc 'Cucumber rake task not available' + task :features do + abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin' + end +end diff --git a/script/cucumber b/script/cucumber new file mode 100755 index 0000000..7f2b6a3 --- /dev/null +++ b/script/cucumber @@ -0,0 +1,8 @@ +#!/usr/bin/env ruby +begin + load File.expand_path(File.dirname(__FILE__) + "/../vendor/plugins/cucumber/bin/cucumber") +rescue LoadError => e + raise unless e.to_s =~ /cucumber/ + require "rubygems" + load File.join(Gem.bindir, "cucumber") +end \ No newline at end of file -- libgit2 0.21.2