From 268643c7de5200a34b7b84b128b344083a3be556 Mon Sep 17 00:00:00 2001 From: Daniel Cunha Date: Fri, 23 Nov 2012 00:34:56 -0300 Subject: [PATCH] changing cucumber version and adding capybara to Gemfile --- Gemfile | 20 +++++++++++++------- Gemfile.lock | 62 +++++++++++++++++++++++++++++++++++++++++--------------------- config/cucumber.yml | 10 ++++++++-- config/environments/cucumber.rb | 11 +++++++++-- features/support/env.rb | 82 ++++++++++++++++++++++++++++++++++++++++++---------------------------------------- features/support/selenium.rb | 20 ++++++++++++++------ lib/tasks/cucumber.rake | 35 ++++++++++++++++++++--------------- script/cucumber | 13 +++---------- 8 files changed, 150 insertions(+), 103 deletions(-) diff --git a/Gemfile b/Gemfile index bf53e96..9931190 100644 --- a/Gemfile +++ b/Gemfile @@ -1,14 +1,20 @@ source :rubygems -gem 'cucumber', '0.4.0' -gem 'webrat', '0.5.1' -gem 'rspec', '1.2.9' -gem 'rspec-rails', '1.2.9' -gem 'Selenium', '>= 1.1.14' -gem 'selenium-client', '>= 1.2.17' -gem 'database_cleaner' + gem 'exception_notification', '1.0.20090728' gem 'system_timer' +group :test do + gem 'rspec', '1.2.9' + gem 'rspec-rails', '1.2.9' +end + +group :cucumber do + gem 'cucumber-rails', '0.3.2' + gem 'capybara', '1.1.1' + gem 'cucumber', '1.1.0' + gem 'database_cleaner' +end + def program(name) unless system("which #{name} > /dev/null") puts "W: Program #{name} is needed, but was not found in your PATH" diff --git a/Gemfile.lock b/Gemfile.lock index 0a42c0b..963482e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,44 +1,64 @@ GEM remote: http://rubygems.org/ specs: - Selenium (1.1.14) - builder (3.0.0) - cucumber (0.4.0) + builder (3.1.4) + capybara (1.1.1) + mime-types (>= 1.16) + nokogiri (>= 1.3.3) + rack (>= 1.0.0) + rack-test (>= 0.5.4) + selenium-webdriver (~> 2.0) + xpath (~> 0.1.4) + childprocess (0.3.6) + ffi (~> 1.0, >= 1.0.6) + cucumber (1.1.0) builder (>= 2.1.2) diff-lcs (>= 1.1.2) - polyglot (>= 0.2.9) - term-ansicolor (>= 1.0.3) - treetop (>= 1.4.2) - database_cleaner (0.7.0) + gherkin (~> 2.5.0) + json (>= 1.4.6) + term-ansicolor (>= 1.0.6) + cucumber-rails (0.3.2) + cucumber (>= 0.8.0) + database_cleaner (0.9.1) diff-lcs (1.1.3) exception_notification (1.0.20090728) - nokogiri (1.5.0) - polyglot (0.3.3) - rack (1.3.5) + ffi (1.2.0) + gherkin (2.5.4) + json (>= 1.4.6) + json (1.7.5) + libwebsocket (0.1.6.1) + websocket + mime-types (1.19) + multi_json (1.3.7) + nokogiri (1.5.5) + rack (1.1.0) + rack-test (0.6.2) + rack (>= 1.0) rspec (1.2.9) rspec-rails (1.2.9) rack (>= 1.0.0) rspec (>= 1.2.9) - selenium-client (1.2.18) + rubyzip (0.9.9) + selenium-webdriver (2.26.0) + childprocess (>= 0.2.5) + libwebsocket (~> 0.1.3) + multi_json (~> 1.0) + rubyzip system_timer (1.2.4) term-ansicolor (1.0.7) - treetop (1.4.10) - polyglot - polyglot (>= 0.3.1) - webrat (0.5.1) - nokogiri (>= 1.2.0) - rack (>= 1.0) + websocket (1.0.4) + xpath (0.1.4) + nokogiri (~> 1.3) PLATFORMS ruby DEPENDENCIES - Selenium (>= 1.1.14) - cucumber (= 0.4.0) + capybara (= 1.1.1) + cucumber (= 1.1.0) + cucumber-rails (= 0.3.2) database_cleaner exception_notification (= 1.0.20090728) rspec (= 1.2.9) rspec-rails (= 1.2.9) - selenium-client (>= 1.2.17) system_timer - webrat (= 0.5.1) diff --git a/config/cucumber.yml b/config/cucumber.yml index b20b547..621a14c 100644 --- a/config/cucumber.yml +++ b/config/cucumber.yml @@ -1,2 +1,8 @@ -default: --tags ~@selenium,~@wip --exclude features/support/selenium.rb --exclude features/step_definitions/selenium_steps.rb -r features/support -r features/step_definitions -selenium: --tags @selenium,~@wip -r features/support -r features/step_definitions +<% +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 773bb1b..957492f 100644 --- a/config/environments/cucumber.rb +++ b/config/environments/cucumber.rb @@ -1,8 +1,10 @@ -# 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! +# 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 @@ -18,3 +20,8 @@ config.action_controller.allow_forgery_protection = false # The :test delivery method accumulates sent emails in the # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test + +config.gem 'cucumber-rails', :lib => false, :version => '>=0.3.2' unless File.directory?(File.join(Rails.root, 'vendor/plugins/cucumber-rails')) +config.gem 'database_cleaner', :lib => false, :version => '>=0.5.0' unless File.directory?(File.join(Rails.root, 'vendor/plugins/database_cleaner')) +config.gem 'capybara', :lib => false, :version => '>=0.3.5' unless File.directory?(File.join(Rails.root, 'vendor/plugins/capybara')) + diff --git a/features/support/env.rb b/features/support/env.rb index 11776e0..d60ccdf 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -1,35 +1,28 @@ -# 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. +# 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" - -# Start/stop Solr -if not $cucumber_env_loaded - abort unless system 'rake solr:start' - at_exit { system 'rake solr:stop' } - $cucumber_env_loaded = true -end - require File.expand_path(File.dirname(__FILE__) + '/../../config/environment') -require 'cucumber/rails/world' - -# 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 +require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support +require 'cucumber/rails/world' +require 'cucumber/rails/active_record' +require 'cucumber/web/tableish' + +require 'capybara/rails' +require 'capybara/cucumber' +require 'capybara/session' +require 'cucumber/rails/capybara_javascript_emulation' # Lets you click links with onclick javascript handlers without using @culerity or @javascript +# Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In +# order to ease the transition to Capybara we set the default here. If you'd +# prefer to use XPath just remove this line and adjust any selectors in your +# steps to use the XPath syntax. +Capybara.default_selector = :css + +# 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. @@ -40,16 +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 '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 +# 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 - diff --git a/features/support/selenium.rb b/features/support/selenium.rb index 8b04b7b..e160c6a 100644 --- a/features/support/selenium.rb +++ b/features/support/selenium.rb @@ -1,14 +1,20 @@ -Webrat.configure do |config| - config.mode = :selenium - config.application_environment = :cucumber - config.selenium_browser_startup_timeout = 30000 -end +require 'rbconfig' +require 'cucumber/formatter/unicode' -Cucumber::Rails::World.use_transactional_fixtures = false +require 'capybara' +require 'capybara/dsl' +require "capybara/cucumber" require 'database_cleaner' require 'database_cleaner/cucumber' +Cucumber::Rails::World.use_transactional_fixtures = false + +Capybara.default_driver = :selenium +Capybara.register_driver :selenium do |app| + Capybara::Selenium::Driver.new(app, :browser => :firefox) +end + DatabaseCleaner.clean_with :truncation DatabaseCleaner.strategy = :truncation @@ -25,3 +31,5 @@ After do sleep 2 DatabaseCleaner.clean end + +World(Capybara) diff --git a/lib/tasks/cucumber.rake b/lib/tasks/cucumber.rake index 3c553cf..7db1a55 100644 --- a/lib/tasks/cucumber.rake +++ b/lib/tasks/cucumber.rake @@ -1,39 +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') +# 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/} + +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' - # 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.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.cucumber_opts = "--color --tags ~@wip --strict --format #{ENV['CUCUMBER_FORMAT'] || 'progress'}" + 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_binary + t.binary = vendored_cucumber_bin 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'] || 'progress'}" + t.profile = 'wip' end - Cucumber::Rake::Task.new({:selenium => 'db:test:prepare'}, 'Run features with selenium') do |t| - t.binary = vendored_cucumber_binary + 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.cucumber_opts = "--color -p selenium --format #{ENV['CUCUMBER_FORMAT'] || 'pretty'}" + t.profile = 'rerun' end desc 'Run all features' task :all => [:ok, :wip] end desc 'Alias for cucumber:ok' - task :cucumber => ['cucumber:ok'] + task :cucumber => 'cucumber:ok' + + task :default => :cucumber task :features => :cucumber do STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***" diff --git a/script/cucumber b/script/cucumber index 9dd05ab..7fa5c92 100755 --- a/script/cucumber +++ b/script/cucumber @@ -1,15 +1,8 @@ #!/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) +vendored_cucumber_bin = Dir["#{File.dirname(__FILE__)}/../vendor/{gems,plugins}/cucumber*/bin/cucumber"].first +if vendored_cucumber_bin + load File.expand_path(vendored_cucumber_bin) else require 'rubygems' unless ENV['NO_RUBYGEMS'] require 'cucumber' -- libgit2 0.21.2