diff --git a/Gemfile b/Gemfile index bb5aa52..5521f8a 100644 --- a/Gemfile +++ b/Gemfile @@ -5,6 +5,7 @@ gem 'acts-as-taggable-on' gem 'prototype-rails' gem 'prototype_legacy_helper', '0.0.0', :git => 'http://git.github.com/rails/prototype_legacy_helper.git' gem 'rails_autolink' +gem 'pg' # TODO needs a rebuild diff-lcs wrt wheezy @@ -12,16 +13,17 @@ gem 'rails_autolink' # with their GEM names (not the Debian package names) group :test do - #gem 'rspec' - #gem 'rspec-rails' + gem 'rspec' + gem 'rspec-rails' end group :cucumber do gem 'rake' - # TODO gem 'cucumber-rails' - # TODO gem 'capybara' - # gem 'cucumber' - # TODO gem 'database_cleaner' + gem 'cucumber-rails', :require => false + gem 'capybara' + gem 'cucumber' + gem 'database_cleaner' + gem 'selenium-webdriver' end def program(name) diff --git a/Gemfile.lock b/Gemfile.lock index a59db78..179e1cf 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -38,8 +38,31 @@ GEM rails (>= 3, < 5) arel (3.0.2) builder (3.0.0) + capybara (2.2.1) + mime-types (>= 1.16) + nokogiri (>= 1.3.3) + rack (>= 1.0.0) + rack-test (>= 0.5.4) + xpath (~> 2.0) + childprocess (0.4.0) + ffi (~> 1.0, >= 1.0.11) + cucumber (1.3.2) + builder (>= 2.1.2) + diff-lcs (>= 1.1.3) + gherkin (~> 2.12.0) + multi_json (~> 1.3) + cucumber-rails (1.4.0) + capybara (>= 1.1.2) + cucumber (>= 1.2.0) + nokogiri (>= 1.5.0) + rails (>= 3.0.0) + database_cleaner (1.2.0) + diff-lcs (1.2.5) erubis (2.7.0) fast_gettext (0.6.8) + ffi (1.9.3) + gherkin (2.12.2) + multi_json (~> 1.3) hike (1.2.1) i18n (0.6.0) journey (1.0.3) @@ -48,7 +71,11 @@ GEM mime-types (~> 1.16) treetop (~> 1.4.8) mime-types (1.19) + mini_portile (0.5.2) multi_json (1.3.6) + nokogiri (1.6.1) + mini_portile (~> 0.5.0) + pg (0.17.1) polyglot (0.3.3) prototype-rails (3.2.1) rails (~> 3.2) @@ -78,6 +105,28 @@ GEM thor (>= 0.14.6, < 2.0) rake (0.9.2.2) rdoc (3.9.4) + rspec (2.14.1) + rspec-core (~> 2.14.0) + rspec-expectations (~> 2.14.0) + rspec-mocks (~> 2.14.0) + rspec-core (2.14.7) + rspec-expectations (2.14.5) + diff-lcs (>= 1.1.3, < 2.0) + rspec-mocks (2.14.5) + rspec-rails (2.14.1) + actionpack (>= 3.0) + activemodel (>= 3.0) + activesupport (>= 3.0) + railties (>= 3.0) + rspec-core (~> 2.14.0) + rspec-expectations (~> 2.14.0) + rspec-mocks (~> 2.14.0) + rubyzip (1.1.0) + selenium-webdriver (2.39.0) + childprocess (>= 0.2.5) + multi_json (~> 1.0) + rubyzip (~> 1.0) + websocket (~> 1.0.4) sprockets (2.1.3) hike (~> 1.2) multi_json (~> 1.0) @@ -89,15 +138,26 @@ GEM polyglot polyglot (>= 0.3.1) tzinfo (0.3.33) + websocket (1.0.7) + xpath (2.0.0) + nokogiri (~> 1.3) PLATFORMS ruby DEPENDENCIES acts-as-taggable-on + capybara + cucumber + cucumber-rails + database_cleaner fast_gettext + pg prototype-rails prototype_legacy_helper (= 0.0.0)! rails rails_autolink rake + rspec + rspec-rails + selenium-webdriver diff --git a/config/environments/cucumber.rb b/config/environments/cucumber.rb index 9d6c1bc..8284910 100644 --- a/config/environments/cucumber.rb +++ b/config/environments/cucumber.rb @@ -1,26 +1,29 @@ -# Edit at your own peril - it's recommended to regenerate this file -# in the future when you upgrade to a newer version of Cucumber. +Noosfero::Application.configure do + # Edit at your own peril - it's recommended to regenerate this file + # in the future when you upgrade to a newer version of Cucumber. -# 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 + # 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 + config.active_support.deprecation = :log -# Show full error reports and disable caching -config.action_controller.perform_caching = false + # Log error messages when you accidentally call methods on nil. + config.whiny_nils = true -# Disable request forgery protection in test environment -config.action_controller.allow_forgery_protection = false + # Show full error reports and disable caching + config.action_controller.perform_caching = 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 + # Disable request forgery protection in test environment + config.action_controller.allow_forgery_protection = false -config.gem 'cucumber-rails', :lib => false, :version => '>=0.3.2' unless File.directory?(Rails.root.join('vendor/plugins/cucumber-rails')) -config.gem 'database_cleaner', :lib => false, :version => '>=0.5.0' unless File.directory?(Rails.root.join('vendor/plugins/database_cleaner')) -config.gem 'capybara', :lib => false, :version => '>=0.3.5' unless File.directory?(Rails.root.join('vendor/plugins/capybara')) + # 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-rails', :lib => false, :version => '>=0.3.2' unless File.directory?(Rails.root.join('vendor/plugins/cucumber-rails')) + config.gem 'database_cleaner', :lib => false, :version => '>=0.5.0' unless File.directory?(Rails.root.join('vendor/plugins/database_cleaner')) + config.gem 'capybara', :lib => false, :version => '>=0.3.5' unless File.directory?(Rails.root.join('vendor/plugins/capybara')) +end diff --git a/features/step_definitions/noosfero_steps.rb b/features/step_definitions/noosfero_steps.rb index 8e62fe4..6203023 100644 --- a/features/step_definitions/noosfero_steps.rb +++ b/features/step_definitions/noosfero_steps.rb @@ -324,8 +324,7 @@ end Given /^feature "(.+)" is (enabled|disabled) on environment$/ do |feature, status| e = Environment.default - status.chop! - e.send status, feature + e.send status.chop, feature e.save end diff --git a/features/support/env.rb b/features/support/env.rb index ecd2746..b857d38 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -4,56 +4,70 @@ # instead of editing this one. Cucumber will automatically load all features/**/*.rb # files. -ENV["RAILS_ENV"] ||= "cucumber" +require 'cucumber/rails' 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/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 Capybara.ignore_hidden_elements = 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 -# 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. +# Capybara defaults to CSS3 selectors rather than XPath. +# If you'd prefer to use XPath, just uncomment this line and adjust any +# selectors in your step definitions to use the XPath syntax. +# Capybara.default_selector = :xpath + +# By default, any exception happening in your Rails application will bubble up +# to Cucumber so that your scenario will fail. This is a different from how +# your application behaves in the production environment, where an error page will +# be rendered instead. +# +# Sometimes we want to override this default behaviour and allow Rails to rescue +# exceptions and display an error page (just like when the app is running in production). +# Typical scenarios where you want to do this is when you test your error pages. +# There are two ways to allow Rails to rescue exceptions: +# +# 1) Tag your scenario (or feature) with @allow-rescue +# +# 2) Set the value below to true. Beware that doing this globally is not +# recommended as it will mask a lot of errors for you! # -# 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 -# 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. +# Remove/comment out the lines below if your app doesn't have a database. +# For some databases (like MongoDB and CouchDB) you may need to use :truncation instead. +begin + DatabaseCleaner.strategy = :transaction +rescue NameError + raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it." +end + +# You may also want to configure DatabaseCleaner to use different strategies for certain features and scenarios. +# See the DatabaseCleaner documentation for details. Example: +# +# Before('@no-txn,@selenium,@culerity,@celerity,@javascript') do +# # { :except => [:widgets] } may not do what you expect here +# # as Cucumber::Rails::Database.javascript_strategy overrides +# # this setting. +# DatabaseCleaner.strategy = :truncation +# end # -# If you set this to false, transactions will be off for all scenarios, -# regardless of whether you use @no-txn or not. +# Before('~@no-txn', '~@selenium', '~@culerity', '~@celerity', '~@javascript') do +# DatabaseCleaner.strategy = :transaction +# end # -# 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. + +# Possible values are :truncation and :transaction +# The :transaction strategy is faster, but might give you threading problems. +# See https://github.com/cucumber/cucumber-rails/blob/master/features/choose_javascript_database_strategy.feature +Cucumber::Rails::Database.javascript_strategy = :truncation + 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. Before do - Fixtures.reset_cache - fixtures_folder = File.join(RAILS_ROOT, 'test', 'fixtures') + ActiveRecord::Fixtures.reset_cache + fixtures_folder = Rails.root.join('test', 'fixtures') fixtures = ['environments', 'roles'] - Fixtures.create_fixtures(fixtures_folder, fixtures) + ActiveRecord::Fixtures.create_fixtures(fixtures_folder, fixtures) end + diff --git a/features/support/fixtures.rb b/features/support/fixtures.rb deleted file mode 100644 index 84d7afa..0000000 --- a/features/support/fixtures.rb +++ /dev/null @@ -1,6 +0,0 @@ -# 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/lib/tasks/cucumber.rake b/lib/tasks/cucumber.rake index e75f59f..9f53ce4 100644 --- a/lib/tasks/cucumber.rake +++ b/lib/tasks/cucumber.rake @@ -1,32 +1,32 @@ # 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 +# 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.join('vendor', '{gems,plugins}', 'cucumber*', 'bin', 'cucumber')].first +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' namespace :cucumber do - Cucumber::Rake::Task.new({:ok => 'db:test:prepare'}, 'Run features that should pass') do |t| + Cucumber::Rake::Task.new({:ok => '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| + Cucumber::Rake::Task.new({:wip => '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| + Cucumber::Rake::Task.new({:rerun => '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' @@ -34,6 +34,12 @@ begin desc 'Run all features' task :all => [:ok, :wip] + + task :statsetup do + require 'rails/code_statistics' + ::STATS_DIRECTORIES << %w(Cucumber\ features features) if File.exist?('features') + ::CodeStatistics::TEST_TYPES << "Cucumber features" if File.exist?('features') + end end desc 'Alias for cucumber:ok' task :cucumber => 'cucumber:ok' @@ -43,6 +49,12 @@ begin task :features => :cucumber do STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***" end + + # In case we don't have the generic Rails test:prepare hook, append a no-op task that we can depend upon. + task 'test:prepare' do + end + + task :stats => 'cucumber:statsetup' rescue LoadError desc 'cucumber rake task not available (cucumber not installed)' task :cucumber do -- libgit2 0.21.2