Commit 3d6e34d575b182408cbfd8e1a79c89b9d6d95dcf

Authored by Antonio Terceiro
1 parent 979df209

ActionItem1240: adding cucumber infrastructure

config/environments/cucumber.rb 0 → 100644
... ... @@ -0,0 +1,21 @@
  1 +config.cache_classes = true # This must be true for Cucumber to operate correctly!
  2 +
  3 +# Log error messages when you accidentally call methods on nil.
  4 +config.whiny_nils = true
  5 +
  6 +# Show full error reports and disable caching
  7 +config.action_controller.consider_all_requests_local = true
  8 +config.action_controller.perform_caching = false
  9 +
  10 +# Disable request forgery protection in test environment
  11 +config.action_controller.allow_forgery_protection = false
  12 +
  13 +# Tell Action Mailer not to deliver emails to the real world.
  14 +# The :test delivery method accumulates sent emails in the
  15 +# ActionMailer::Base.deliveries array.
  16 +config.action_mailer.delivery_method = :test
  17 +
  18 +config.gem "cucumber", :lib => false, :version => ">=0.3.11" unless File.directory?(File.join(Rails.root, 'vendor/plugins/cucumber'))
  19 +config.gem "webrat", :lib => false, :version => ">=0.4.4" unless File.directory?(File.join(Rails.root, 'vendor/plugins/webrat'))
  20 +config.gem "rspec", :lib => false, :version => ">=1.2.6" unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec'))
  21 +config.gem "rspec-rails", :lib => 'spec/rails', :version => ">=1.2.6" unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec-rails'))
... ...
features/step_definitions/webrat_steps.rb 0 → 100644
... ... @@ -0,0 +1,119 @@
  1 +require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths"))
  2 +
  3 +# Commonly used webrat steps
  4 +# http://github.com/brynary/webrat
  5 +
  6 +Given /^I am on (.+)$/ do |page_name|
  7 + visit path_to(page_name)
  8 +end
  9 +
  10 +When /^I go to (.+)$/ do |page_name|
  11 + visit path_to(page_name)
  12 +end
  13 +
  14 +When /^I press "([^\"]*)"$/ do |button|
  15 + click_button(button)
  16 +end
  17 +
  18 +When /^I follow "([^\"]*)"$/ do |link|
  19 + click_link(link)
  20 +end
  21 +
  22 +When /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value|
  23 + fill_in(field, :with => value)
  24 +end
  25 +
  26 +When /^I select "([^\"]*)" from "([^\"]*)"$/ do |value, field|
  27 + select(value, :from => field)
  28 +end
  29 +
  30 +# Use this step in conjunction with Rail's datetime_select helper. For example:
  31 +# When I select "December 25, 2008 10:00" as the date and time
  32 +When /^I select "([^\"]*)" as the date and time$/ do |time|
  33 + select_datetime(time)
  34 +end
  35 +
  36 +# Use this step when using multiple datetime_select helpers on a page or
  37 +# you want to specify which datetime to select. Given the following view:
  38 +# <%= f.label :preferred %><br />
  39 +# <%= f.datetime_select :preferred %>
  40 +# <%= f.label :alternative %><br />
  41 +# <%= f.datetime_select :alternative %>
  42 +# The following steps would fill out the form:
  43 +# When I select "November 23, 2004 11:20" as the "Preferred" date and time
  44 +# And I select "November 25, 2004 10:30" as the "Alternative" date and time
  45 +When /^I select "([^\"]*)" as the "([^\"]*)" date and time$/ do |datetime, datetime_label|
  46 + select_datetime(datetime, :from => datetime_label)
  47 +end
  48 +
  49 +# Use this step in conjunction with Rail's time_select helper. For example:
  50 +# When I select "2:20PM" as the time
  51 +# Note: Rail's default time helper provides 24-hour time-- not 12 hour time. Webrat
  52 +# will convert the 2:20PM to 14:20 and then select it.
  53 +When /^I select "([^\"]*)" as the time$/ do |time|
  54 + select_time(time)
  55 +end
  56 +
  57 +# Use this step when using multiple time_select helpers on a page or you want to
  58 +# specify the name of the time on the form. For example:
  59 +# When I select "7:30AM" as the "Gym" time
  60 +When /^I select "([^\"]*)" as the "([^\"]*)" time$/ do |time, time_label|
  61 + select_time(time, :from => time_label)
  62 +end
  63 +
  64 +# Use this step in conjunction with Rail's date_select helper. For example:
  65 +# When I select "February 20, 1981" as the date
  66 +When /^I select "([^\"]*)" as the date$/ do |date|
  67 + select_date(date)
  68 +end
  69 +
  70 +# Use this step when using multiple date_select helpers on one page or
  71 +# you want to specify the name of the date on the form. For example:
  72 +# When I select "April 26, 1982" as the "Date of Birth" date
  73 +When /^I select "([^\"]*)" as the "([^\"]*)" date$/ do |date, date_label|
  74 + select_date(date, :from => date_label)
  75 +end
  76 +
  77 +When /^I check "([^\"]*)"$/ do |field|
  78 + check(field)
  79 +end
  80 +
  81 +When /^I uncheck "([^\"]*)"$/ do |field|
  82 + uncheck(field)
  83 +end
  84 +
  85 +When /^I choose "([^\"]*)"$/ do |field|
  86 + choose(field)
  87 +end
  88 +
  89 +When /^I attach the file at "([^\"]*)" to "([^\"]*)"$/ do |path, field|
  90 + attach_file(field, path)
  91 +end
  92 +
  93 +Then /^I should see "([^\"]*)"$/ do |text|
  94 + response.should contain(text)
  95 +end
  96 +
  97 +Then /^I should not see "([^\"]*)"$/ do |text|
  98 + response.should_not contain(text)
  99 +end
  100 +
  101 +Then /^the "([^\"]*)" field should contain "([^\"]*)"$/ do |field, value|
  102 + field_labeled(field).value.should =~ /#{value}/
  103 +end
  104 +
  105 +Then /^the "([^\"]*)" field should not contain "([^\"]*)"$/ do |field, value|
  106 + field_labeled(field).value.should_not =~ /#{value}/
  107 +end
  108 +
  109 +Then /^the "([^\"]*)" checkbox should be checked$/ do |label|
  110 + field_labeled(label).should be_checked
  111 +end
  112 +
  113 +Then /^the "([^\"]*)" checkbox should not be checked$/ do |label|
  114 + field_labeled(label).should_not be_checked
  115 +end
  116 +
  117 +Then /^I should be on (.+)$/ do |page_name|
  118 + URI.parse(current_url).path.should == path_to(page_name)
  119 +end
... ...
features/support/env.rb 0 → 100644
... ... @@ -0,0 +1,24 @@
  1 +# Sets up the Rails environment for Cucumber
  2 +ENV["RAILS_ENV"] ||= "cucumber"
  3 +require File.expand_path(File.dirname(__FILE__) + '/../../config/environment')
  4 +require 'cucumber/rails/world'
  5 +
  6 +# Comment out the next line if you don't want Cucumber Unicode support
  7 +require 'cucumber/formatter/unicode'
  8 +
  9 +# Comment out the next line if you don't want transactions to
  10 +# open/roll back around each scenario
  11 +Cucumber::Rails.use_transactional_fixtures
  12 +
  13 +# Comment out the next line if you want Rails' own error handling
  14 +# (e.g. rescue_action_in_public / rescue_responses / rescue_from)
  15 +Cucumber::Rails.bypass_rescue
  16 +
  17 +require 'webrat'
  18 +
  19 +Webrat.configure do |config|
  20 + config.mode = :rails
  21 +end
  22 +
  23 +require 'cucumber/rails/rspec'
  24 +require 'webrat/core/matchers'
... ...
features/support/paths.rb 0 → 100644
... ... @@ -0,0 +1,27 @@
  1 +module NavigationHelpers
  2 + # Maps a name to a path. Used by the
  3 + #
  4 + # When /^I go to (.+)$/ do |page_name|
  5 + #
  6 + # step definition in webrat_steps.rb
  7 + #
  8 + def path_to(page_name)
  9 + case page_name
  10 +
  11 + when /the homepage/
  12 + '/'
  13 +
  14 + # Add more mappings here.
  15 + # Here is a more fancy example:
  16 + #
  17 + # when /^(.*)'s profile page$/i
  18 + # user_profile_path(User.find_by_login($1))
  19 +
  20 + else
  21 + raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
  22 + "Now, go and add a mapping in #{__FILE__}"
  23 + end
  24 + end
  25 +end
  26 +
  27 +World(NavigationHelpers)
... ...
lib/tasks/cucumber.rake 0 → 100644
... ... @@ -0,0 +1,16 @@
  1 +$LOAD_PATH.unshift(RAILS_ROOT + '/vendor/plugins/cucumber/lib') if File.directory?(RAILS_ROOT + '/vendor/plugins/cucumber/lib')
  2 +
  3 +begin
  4 + require 'cucumber/rake/task'
  5 +
  6 + Cucumber::Rake::Task.new(:features) do |t|
  7 + t.fork = true
  8 + t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'pretty')]
  9 + end
  10 + task :features => 'db:test:prepare'
  11 +rescue LoadError
  12 + desc 'Cucumber rake task not available'
  13 + task :features do
  14 + abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
  15 + end
  16 +end
... ...