From 861a2a43797f769f5d102569a60b8b8472ccc5df Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Fri, 9 Oct 2009 13:55:27 -0300 Subject: [PATCH] Upgrading to cucumber 0.4.x --- config/environments/cucumber.rb | 13 +++++++++---- features/step_definitions/webrat_steps.rb | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- features/support/env.rb | 51 ++++++++++++++++++++++++++++++++++----------------- features/support/fixtures.rb | 6 ++++++ features/support/version_check.rb | 29 +++++++++++++++++++++++++++++ lib/tasks/cucumber.rake | 40 ++++++++++++++++++++++++++++++++++------ script/cucumber | 17 +++++++++++++++++ 7 files changed, 207 insertions(+), 35 deletions(-) create mode 100644 features/support/fixtures.rb create mode 100644 features/support/version_check.rb create mode 100755 script/cucumber diff --git a/config/environments/cucumber.rb b/config/environments/cucumber.rb index b57f986..90100ea 100644 --- a/config/environments/cucumber.rb +++ b/config/environments/cucumber.rb @@ -1,3 +1,7 @@ +# IMPORTANT: This file was generated by Cucumber 0.4.0 +# Edit at your own peril - it's recommended to regenerate this file +# in the future when you upgrade to a newer version of Cucumber. + config.cache_classes = true # This must be true for Cucumber to operate correctly! # Log error messages when you accidentally call methods on nil. @@ -15,7 +19,8 @@ config.action_controller.allow_forgery_protection = false # 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 => 'spec', :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')) +config.gem 'cucumber', :lib => false, :version => '>=0.4.0' unless File.directory?(File.join(Rails.root, 'vendor/plugins/cucumber')) +config.gem 'webrat', :lib => false, :version => '>=0.5.0' unless File.directory?(File.join(Rails.root, 'vendor/plugins/webrat')) +config.gem 'rspec', :lib => 'spec', :version => '>=1.2.8' unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec')) +config.gem 'rspec-rails', :lib => 'spec/rails', :version => '>=1.2.7.1' unless File.directory?(File.join(Rails.root, 'vendor/plugins/rspec-rails')) + diff --git a/features/step_definitions/webrat_steps.rb b/features/step_definitions/webrat_steps.rb index 28130ae..5fe991d 100644 --- a/features/step_definitions/webrat_steps.rb +++ b/features/step_definitions/webrat_steps.rb @@ -1,3 +1,8 @@ +# IMPORTANT: This file was generated by Cucumber 0.4.0 +# Edit at your own peril - it's recommended to regenerate this file +# in the future when you upgrade to a newer version of Cucumber. +# Consider adding your own code to a new file instead of editing this one. + require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths")) # Commonly used webrat steps @@ -19,21 +24,46 @@ When /^I follow "([^\"]*)"$/ do |link| click_link(link) end +When /^I follow "([^\"]*)" within "([^\"]*)"$/ do |link, parent| + click_link_within(parent, link) +end + When /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value| - fill_in(field, :with => value) + fill_in(field, :with => value) +end + +When /^I fill in "([^\"]*)" for "([^\"]*)"$/ do |value, field| + fill_in(field, :with => value) +end + +# Use this to fill in an entire form with data from a table. Example: +# +# When I fill in the following: +# | Account Number | 5002 | +# | Expiry date | 2009-11-01 | +# | Note | Nice guy | +# | Wants Email? | | +# +# TODO: Add support for checkbox, select og option +# based on naming conventions. +# +When /^I fill in the following:$/ do |fields| + fields.rows_hash.each do |name, value| + When %{I fill in "#{name}" with "#{value}"} + end end When /^I select "([^\"]*)" from "([^\"]*)"$/ do |value, field| - select(value, :from => 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 "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 +# 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 %> @@ -49,7 +79,7 @@ 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. +# will convert the 2:20PM to 14:20 and then select it. When /^I select "([^\"]*)" as the time$/ do |time| select_time(time) end @@ -75,11 +105,11 @@ When /^I select "([^\"]*)" as the "([^\"]*)" date$/ do |date, date_label| end When /^I check "([^\"]*)"$/ do |field| - check(field) + check(field) end When /^I uncheck "([^\"]*)"$/ do |field| - uncheck(field) + uncheck(field) end When /^I choose "([^\"]*)"$/ do |field| @@ -94,10 +124,46 @@ Then /^I should see "([^\"]*)"$/ do |text| response.should contain(text) end +Then /^I should see "([^\"]*)" within "([^\"]*)"$/ do |text, selector| + within(selector) do |content| + content.should contain(text) + end +end + +Then /^I should see \/([^\/]*)\/$/ do |regexp| + regexp = Regexp.new(regexp) + response.should contain(regexp) +end + +Then /^I should see \/([^\/]*)\/ within "([^\"]*)"$/ do |regexp, selector| + within(selector) do |content| + regexp = Regexp.new(regexp) + content.should contain(regexp) + end +end + Then /^I should not see "([^\"]*)"$/ do |text| response.should_not contain(text) end +Then /^I should not see "([^\"]*)" within "([^\"]*)"$/ do |text, selector| + within(selector) do |content| + content.should_not contain(text) + end +end + +Then /^I should not see \/([^\/]*)\/$/ do |regexp| + regexp = Regexp.new(regexp) + response.should_not contain(regexp) +end + +Then /^I should not see \/([^\/]*)\/ within "([^\"]*)"$/ do |regexp, selector| + within(selector) do |content| + regexp = Regexp.new(regexp) + content.should_not contain(regexp) + end +end + Then /^the "([^\"]*)" field should contain "([^\"]*)"$/ do |field, value| field_labeled(field).value.should =~ /#{value}/ end @@ -105,7 +171,7 @@ 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 @@ -117,3 +183,7 @@ end Then /^I should be on (.+)$/ do |page_name| URI.parse(current_url).path.should == path_to(page_name) end + +Then /^show me the page$/ do + save_and_open_page +end \ No newline at end of file diff --git a/features/support/env.rb b/features/support/env.rb index 56ffec0..20cb4a1 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -1,30 +1,47 @@ +# IMPORTANT: This file was generated by Cucumber 0.4.0 +# Edit at your own peril - it's recommended to regenerate this file +# in the future when you upgrade to a newer version of Cucumber. +# Consider adding your own code to a new file instead of editing this one. + # 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' +# If you set this to true, each scenario will run in a database transaction. +# You can still turn off transactions on a per-scenario basis, simply tagging +# a feature or scenario with the @no-txn tag. +# +# If you set this to false, transactions will be off for all scenarios, +# regardless of whether you use @no-txn or not. +# +# Beware that turning transactions off will leave data in your database +# after each scenario, which can lead to hard-to-debug failures in +# subsequent scenarios. If you do this, we recommend you create a Before +# block that will explicitly put your database in a known state. +Cucumber::Rails::World.use_transactional_fixtures = true -# Comment out the next line if you don't want transactions to -# open/roll back around each scenario -Cucumber::Rails.use_transactional_fixtures +# If you set this to false, any error raised from within your app will bubble +# up to your step definition and out to cucumber unless you catch it somewhere +# on the way. You can make Rails rescue errors and render error pages on a +# per-scenario basis by tagging a scenario or feature with the @allow-rescue tag. +# +# If you set this to true, Rails will rescue all errors and render error +# pages, more or less in the same way your application would behave in the +# default production environment. It's not recommended to do this for all +# of your scenarios, as this makes it hard to discover errors in your application. +ActionController::Base.allow_rescue = false -# 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 'cucumber' +# Comment out the next line if you don't want Cucumber Unicode support +require 'cucumber/formatter/unicode' +require 'cucumber/webrat/element_locator' # Lets you do table.diff!(element_at('#my_table_or_dl_or_ul_or_ol').to_table) +require 'cucumber/rails/rspec' require 'webrat' - +require 'webrat/core/matchers' Webrat.configure do |config| config.mode = :rails + config.open_error_files = false # Set to true if you want error pages to pop up in the browser end -require 'cucumber/rails/rspec' -require 'webrat/core/matchers' - -# set the very basic fixtures for Noosfero -Fixtures.reset_cache -fixtures_folder = File.join(RAILS_ROOT, 'test', 'fixtures') -fixtures = ['environments', 'roles'] -Fixtures.create_fixtures(fixtures_folder, fixtures) diff --git a/features/support/fixtures.rb b/features/support/fixtures.rb new file mode 100644 index 0000000..60ef4c9 --- /dev/null +++ b/features/support/fixtures.rb @@ -0,0 +1,6 @@ +# set the very basic fixtures for Noosfero +Fixtures.reset_cache +fixtures_folder = File.join(RAILS_ROOT, 'test', 'fixtures') +fixtures = ['environments', 'roles'] +Fixtures.create_fixtures(fixtures_folder, fixtures) + diff --git a/features/support/version_check.rb b/features/support/version_check.rb new file mode 100644 index 0000000..7245c94 --- /dev/null +++ b/features/support/version_check.rb @@ -0,0 +1,29 @@ +if Cucumber::VERSION::STRING != '0.4.0' +warning = <<-WARNING +(::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) + + (::) R O T T E N C U C U M B E R A L E R T (::) + +Your #{__FILE__.gsub(/version_check.rb$/, 'env.rb')} file was generated with Cucumber 0.4.0, +but you seem to be running Cucumber #{Cucumber::VERSION::STRING}. If you're running an older +version than #{Cucumber::VERSION::STRING}, just upgrade your gem. If you're running a newer +version than #{Cucumber::VERSION::STRING} you should: + + 1) Read http://wiki.github.com/aslakhellesoy/cucumber/upgrading + + 2) Regenerate your cucumber environment with the following command: + + ruby script/generate cucumber + +If you get prompted to replace a file, hit 'd' to see the difference. +When you're sure you have captured any personal edits, confirm that you +want to overwrite #{__FILE__.gsub(/version_check.rb$/, 'env.rb')} by pressing 'y'. Then reapply any +personal changes that may have been overwritten. + +This message will then self destruct. + +(::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) +WARNING +warn(warning) +at_exit {warn(warning)} +end \ No newline at end of file diff --git a/lib/tasks/cucumber.rake b/lib/tasks/cucumber.rake index 8744327..c537159 100644 --- a/lib/tasks/cucumber.rake +++ b/lib/tasks/cucumber.rake @@ -1,16 +1,44 @@ +# This file was generated by $LOAD_PATH.unshift(RAILS_ROOT + '/vendor/plugins/cucumber/lib') if File.directory?(RAILS_ROOT + '/vendor/plugins/cucumber/lib') +unless ARGV.any? {|a| a =~ /^gems/} + begin require 'cucumber/rake/task' - Cucumber::Rake::Task.new(:features) do |t| - t.fork = true - t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'pretty')] + # Use vendored cucumber binary if possible. If it's not vendored, + # Cucumber::Rake::Task will automatically use installed gem's cucumber binary + vendored_cucumber_binary = Dir["#{RAILS_ROOT}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first + + namespace :cucumber do + Cucumber::Rake::Task.new({:ok => 'db:test:prepare'}, 'Run features that should pass') do |t| + t.binary = vendored_cucumber_binary + t.fork = true # You may get faster startup if you set this to false + t.cucumber_opts = "--color --tags ~@wip --strict --format #{ENV['CUCUMBER_FORMAT'] || 'pretty'}" + end + + Cucumber::Rake::Task.new({:wip => 'db:test:prepare'}, 'Run features that are being worked on') do |t| + t.binary = vendored_cucumber_binary + t.fork = true # You may get faster startup if you set this to false + t.cucumber_opts = "--color --tags @wip:2 --wip --format #{ENV['CUCUMBER_FORMAT'] || 'pretty'}" + end + + desc 'Run all features' + task :all => [:ok, :wip] + end + desc 'Alias for cucumber:ok' + task :cucumber => 'cucumber:ok' + + task :default => :cucumber + + task :features => :cucumber do + STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***" end - task :features => 'db:test:prepare' rescue LoadError - desc 'Cucumber rake task not available' - task :features do + desc 'cucumber rake task not available (cucumber not installed)' + task :cucumber do abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin' end end + +end diff --git a/script/cucumber b/script/cucumber new file mode 100755 index 0000000..9dd05ab --- /dev/null +++ b/script/cucumber @@ -0,0 +1,17 @@ +#!/usr/bin/env ruby + +vendored_cucumber_binary = Dir[File.join(File.dirname(__FILE__), + '..', + 'vendor', + '{gems,plugins}', + 'cucumber*', + 'bin', + 'cucumber')].first + +if vendored_cucumber_binary + load File.expand_path(vendored_cucumber_binary) +else + require 'rubygems' unless ENV['NO_RUBYGEMS'] + require 'cucumber' + load Cucumber::BINARY +end -- libgit2 0.21.2