From 1ff2498ccd25e6b2c2776cc5f864deae4451fe2e Mon Sep 17 00:00:00 2001 From: Vitor Baptista Date: Fri, 10 Aug 2012 13:35:19 -0300 Subject: [PATCH] Upgrading cucumber to 1.1.0 and adding cucumber-rails 0.3.2. --- Gemfile | 9 ++++++--- Gemfile.lock | 25 ++++++++++++++----------- config/cucumber.yml | 8 ++++++++ config/environments/cucumber.rb | 8 ++++---- features/step_definitions/factory_girl_steps.rb | 33 --------------------------------- features/support/env.rb | 72 +++++++++++++++++++++++++++++++++++++++--------------------------------- lib/tasks/cucumber.rake | 51 ++++++++++++++++++++++++++++++++++++++++++++------- spec/factories.rb | 18 ------------------ vendor/cache/builder-2.1.2.gem | Bin 22528 -> 0 bytes vendor/cache/builder-3.0.0.gem | Bin 0 -> 609280 bytes vendor/cache/cucumber-0.8.5.gem | Bin 259584 -> 0 bytes vendor/cache/cucumber-1.1.0.gem | Bin 0 -> 328192 bytes vendor/cache/cucumber-rails-0.3.2.gem | Bin 0 -> 33280 bytes vendor/cache/gherkin-2.1.5.gem | Bin 765440 -> 0 bytes vendor/cache/gherkin-2.5.4.gem | Bin 0 -> 805888 bytes vendor/cache/json-1.7.4.gem | Bin 0 -> 145920 bytes vendor/cache/trollop-1.16.2.gem | Bin 22016 -> 0 bytes 17 files changed, 115 insertions(+), 109 deletions(-) create mode 100644 config/cucumber.yml delete mode 100644 features/step_definitions/factory_girl_steps.rb delete mode 100644 vendor/cache/builder-2.1.2.gem create mode 100644 vendor/cache/builder-3.0.0.gem delete mode 100644 vendor/cache/cucumber-0.8.5.gem create mode 100644 vendor/cache/cucumber-1.1.0.gem create mode 100644 vendor/cache/cucumber-rails-0.3.2.gem delete mode 100644 vendor/cache/gherkin-2.1.5.gem create mode 100644 vendor/cache/gherkin-2.5.4.gem create mode 100644 vendor/cache/json-1.7.4.gem delete mode 100644 vendor/cache/trollop-1.16.2.gem diff --git a/Gemfile b/Gemfile index 08f01fa..02ce21b 100644 --- a/Gemfile +++ b/Gemfile @@ -32,16 +32,15 @@ gem 'mysql2', '0.2.18' group :cucumber do - gem 'cucumber', '0.8.5' + gem 'cucumber', '1.1.0' + gem 'cucumber-rails', '0.3.2' gem 'webrat', "0.5.3" gem 'fakeweb', '1.2.5' - gem 'factory_girl', '1.2.3' end group :test do gem "rspec", "~>1.3.1" gem "rspec-rails", "1.3.4" - gem "factory_girl", "1.2.3" gem "shoulda", "~>2.10.1" gem "jtrupiano-timecop", "0.2.1", :require => "timecop" @@ -49,3 +48,7 @@ group :test do gem "jferris-mocha", "0.9.5.0.1241126838", :require => "mocha" end + +group :test, :cucumber do + gem 'factory_girl', '1.2.3' +end diff --git a/Gemfile.lock b/Gemfile.lock index 6b32ad9..e897282 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -13,13 +13,15 @@ GEM activesupport (= 2.3.14) activesupport (2.3.14) ambethia-smtp-tls (1.1.2) - builder (2.1.2) - cucumber (0.8.5) - builder (~> 2.1.2) - diff-lcs (~> 1.1.2) - gherkin (~> 2.1.4) - json_pure (~> 1.4.3) - term-ansicolor (~> 1.0.4) + builder (3.0.0) + cucumber (1.1.0) + builder (>= 2.1.2) + diff-lcs (>= 1.1.2) + gherkin (~> 2.5.0) + json (>= 1.4.6) + term-ansicolor (>= 1.0.6) + cucumber-rails (0.3.2) + cucumber (>= 0.8.0) daemons (1.1.9) delayed_job (2.0.6) daemons @@ -28,8 +30,8 @@ GEM fakeweb (1.2.5) fastercsv (1.5.1) formtastic (0.2.5) - gherkin (2.1.5) - trollop (~> 1.16.2) + gherkin (2.5.4) + json (>= 1.4.6) has_scope (0.4.2) hoptoad_notifier (2.4.9) activesupport @@ -39,6 +41,7 @@ GEM responders (~> 0.4.3) jferris-mocha (0.9.5.0.1241126838) rake + json (1.7.4) json_pure (1.4.6) jtrupiano-timecop (0.2.1) mime-types (1.16) @@ -70,7 +73,6 @@ GEM shoulda (2.10.3) term-ansicolor (1.0.7) thoughtbot-clearance (0.8.2) - trollop (1.16.2) webrat (0.5.3) nokogiri (>= 1.2.0) rack (>= 1.0) @@ -84,7 +86,8 @@ PLATFORMS DEPENDENCIES ambethia-smtp-tls (= 1.1.2) bundler (~> 1.1.5) - cucumber (= 0.8.5) + cucumber (= 1.1.0) + cucumber-rails (= 0.3.2) delayed_job (= 2.0.6) factory_girl (= 1.2.3) fakeweb (= 1.2.5) diff --git a/config/cucumber.yml b/config/cucumber.yml new file mode 100644 index 0000000..621a14c --- /dev/null +++ b/config/cucumber.yml @@ -0,0 +1,8 @@ +<% +rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : "" +rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}" +std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} --strict --tags ~@wip" +%> +default: <%= std_opts %> features +wip: --tags @wip:3 --wip features +rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip diff --git a/config/environments/cucumber.rb b/config/environments/cucumber.rb index 20696b9..4b4365f 100644 --- a/config/environments/cucumber.rb +++ b/config/environments/cucumber.rb @@ -1,8 +1,10 @@ -# IMPORTANT: This file was generated by Cucumber 0.4.2 # 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! +# IMPORTANT: Setting config.cache_classes to false is known to +# break Cucumber's use_transactional_fixtures method. +# For more information see https://rspec.lighthouseapp.com/projects/16211/tickets/165 +config.cache_classes = true # Log error messages when you accidentally call methods on nil. config.whiny_nils = true @@ -19,9 +21,7 @@ config.action_controller.allow_forgery_protection = false # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test - HOST = "localhost" AUTHORIZE_NET_API_LOGIN_ID = '' AUTHORIZE_NET_TRANSACTION_KEY = '' -ActiveMerchant::Billing::Base.gateway_mode = :test diff --git a/features/step_definitions/factory_girl_steps.rb b/features/step_definitions/factory_girl_steps.rb deleted file mode 100644 index 40bbd6e..0000000 --- a/features/step_definitions/factory_girl_steps.rb +++ /dev/null @@ -1,33 +0,0 @@ -Given /^the following (.*) exists?:$/ do |factory, table| - factory = factory.singularize.gsub(' ','_') - table.hashes.each do |attributes| - Factory(factory, attributes) - end -end - -Factory.factories.each do |name, factory| - if factory.build_class.respond_to?(:columns) - factory.build_class.columns.each do |column| - Given %{^an? #{name.to_s.humanize.downcase} exists with an? #{column.name.humanize.downcase} of "([^"]*)"$} do |value| - Factory(name, column.name => value) - end - - Given %{^an? #{name.to_s.humanize.downcase} exists with an? #{column.name.humanize.downcase} of "([^"]*)" and a "([^"]*)" of "([^"]*)"$} do |first_value, second_column, second_value| - Factory(name, column.name => value, second_column.downcase.to_sym => second_value) - end - end - end - - Given /^an? #{name} exists$/ do - Factory(name) - end - - Given /^(\d+) #{name.to_s.humanize.downcase.pluralize} exist with an? ([^"]*) of "([^"]*)"$/ do |count, attr, value| - count.to_i.times { Factory(name, attr.gsub(' ', '_') => value) } - end - - Given %r{^(\d+) #{name.to_s.humanize.downcase.pluralize} exist$} do |count| - count.to_i.times { Factory(name) } - end -end - diff --git a/features/support/env.rb b/features/support/env.rb index 2219996..536cac8 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -1,25 +1,26 @@ -# IMPORTANT: This file was generated by Cucumber 0.4.2 -# 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. +# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril. +# It is recommended to regenerate this file in the future when you upgrade to a +# newer version of cucumber-rails. Consider adding your own code to a new file +# instead of editing this one. Cucumber will automatically load all features/**/*.rb +# files. -# Sets up the Rails environment for Cucumber ENV["RAILS_ENV"] ||= "cucumber" require File.expand_path(File.dirname(__FILE__) + '/../../config/environment') + +require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support +require 'cucumber/rails/rspec' require 'cucumber/rails/world' +require 'cucumber/rails/active_record' +require 'cucumber/web/tableish' + +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 -# 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 # 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 @@ -32,20 +33,25 @@ Cucumber::Rails::World.use_transactional_fixtures = true # of your scenarios, as this makes it hard to discover errors in your application. ActionController::Base.allow_rescue = false -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 '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 +# 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 are using Capybara, +# tagging with @culerity or @javascript will also turn transactions off. +# +# 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 +# How to clean your database when transactions are turned off. See +# http://github.com/bmabey/database_cleaner for more info. +if defined?(ActiveRecord::Base) + begin + require 'database_cleaner' + DatabaseCleaner.strategy = :truncation + rescue LoadError => ignore_if_database_cleaner_not_present + end end - -require 'factory_girl/step_definitions' -FakeWeb.allow_net_connect = false - -Dir[File.join(Rails.root, "test", "support", "**", "*.rb")].each { |file| require(file) } - diff --git a/lib/tasks/cucumber.rake b/lib/tasks/cucumber.rake index 8744327..7db1a55 100644 --- a/lib/tasks/cucumber.rake +++ b/lib/tasks/cucumber.rake @@ -1,16 +1,53 @@ -$LOAD_PATH.unshift(RAILS_ROOT + '/vendor/plugins/cucumber/lib') if File.directory?(RAILS_ROOT + '/vendor/plugins/cucumber/lib') +# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril. +# It is recommended to regenerate this file in the future when you upgrade to a +# newer version of cucumber-rails. Consider adding your own code to a new file +# instead of editing this one. Cucumber will automatically load all features/**/*.rb +# files. + + +unless ARGV.any? {|a| a =~ /^gems/} # Don't load anything when running the gems:* tasks + +vendored_cucumber_bin = Dir["#{Rails.root}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first +$LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + '/../lib') unless vendored_cucumber_bin.nil? begin require 'cucumber/rake/task' - Cucumber::Rake::Task.new(:features) do |t| - t.fork = true - t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'pretty')] + namespace :cucumber do + Cucumber::Rake::Task.new({:ok => 'db:test:prepare'}, 'Run features that should pass') do |t| + t.binary = vendored_cucumber_bin # If nil, the gem's binary is used. + t.fork = true # You may get faster startup if you set this to false + t.profile = 'default' + end + + Cucumber::Rake::Task.new({:wip => 'db:test:prepare'}, 'Run features that are being worked on') do |t| + t.binary = vendored_cucumber_bin + t.fork = true # You may get faster startup if you set this to false + t.profile = 'wip' + end + + Cucumber::Rake::Task.new({:rerun => 'db:test:prepare'}, 'Record failing features and run only them if any exist') do |t| + t.binary = vendored_cucumber_bin + t.fork = true # You may get faster startup if you set this to false + t.profile = 'rerun' + 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/spec/factories.rb b/spec/factories.rb index 76b334a..686a41e 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -1,8 +1,3 @@ -Factory.define(:item) do |f| - f.sequence(:data) { |i| "Item #{i}" } -end - - Factory.define(:question) do |f| f.sequence(:name) { |i| "Name #{i}" } f.site {|s| s.association(:user)} @@ -99,16 +94,3 @@ Factory.define(:appearance_new_user, :parent => :appearance) do |f| f.voter {|a| Factory.build(:visitor, :site => a.question.site)} end -Factory.sequence :email do |n| - "user#{n}@example.com" -end - -Factory.define :user do |user| - user.email { Factory.next :email } - user.password { "password" } - user.password_confirmation { "password" } -end - -Factory.define :email_confirmed_user, :parent => :user do |user| - user.email_confirmed { true } -end diff --git a/vendor/cache/builder-2.1.2.gem b/vendor/cache/builder-2.1.2.gem deleted file mode 100644 index c901697..0000000 Binary files a/vendor/cache/builder-2.1.2.gem and /dev/null differ diff --git a/vendor/cache/builder-3.0.0.gem b/vendor/cache/builder-3.0.0.gem new file mode 100644 index 0000000..a2c6d16 Binary files /dev/null and b/vendor/cache/builder-3.0.0.gem differ diff --git a/vendor/cache/cucumber-0.8.5.gem b/vendor/cache/cucumber-0.8.5.gem deleted file mode 100644 index c0d80bb..0000000 Binary files a/vendor/cache/cucumber-0.8.5.gem and /dev/null differ diff --git a/vendor/cache/cucumber-1.1.0.gem b/vendor/cache/cucumber-1.1.0.gem new file mode 100644 index 0000000..95e400d Binary files /dev/null and b/vendor/cache/cucumber-1.1.0.gem differ diff --git a/vendor/cache/cucumber-rails-0.3.2.gem b/vendor/cache/cucumber-rails-0.3.2.gem new file mode 100644 index 0000000..3b14b54 Binary files /dev/null and b/vendor/cache/cucumber-rails-0.3.2.gem differ diff --git a/vendor/cache/gherkin-2.1.5.gem b/vendor/cache/gherkin-2.1.5.gem deleted file mode 100644 index 2ac0e54..0000000 Binary files a/vendor/cache/gherkin-2.1.5.gem and /dev/null differ diff --git a/vendor/cache/gherkin-2.5.4.gem b/vendor/cache/gherkin-2.5.4.gem new file mode 100644 index 0000000..55a859c Binary files /dev/null and b/vendor/cache/gherkin-2.5.4.gem differ diff --git a/vendor/cache/json-1.7.4.gem b/vendor/cache/json-1.7.4.gem new file mode 100644 index 0000000..bda6cfa Binary files /dev/null and b/vendor/cache/json-1.7.4.gem differ diff --git a/vendor/cache/trollop-1.16.2.gem b/vendor/cache/trollop-1.16.2.gem deleted file mode 100644 index e8ec20d..0000000 Binary files a/vendor/cache/trollop-1.16.2.gem and /dev/null differ -- libgit2 0.21.2