Commit 3b68729e391f7ce60d4cfabaf3bc458711d933cf
1 parent
504bc402
Exists in
master
and in
29 other branches
rails3: fix cucumber initialization
Showing
7 changed files
with
159 additions
and
75 deletions
Show diff stats
Gemfile
@@ -5,6 +5,7 @@ gem 'acts-as-taggable-on' | @@ -5,6 +5,7 @@ gem 'acts-as-taggable-on' | ||
5 | gem 'prototype-rails' | 5 | gem 'prototype-rails' |
6 | gem 'prototype_legacy_helper', '0.0.0', :git => 'http://git.github.com/rails/prototype_legacy_helper.git' | 6 | gem 'prototype_legacy_helper', '0.0.0', :git => 'http://git.github.com/rails/prototype_legacy_helper.git' |
7 | gem 'rails_autolink' | 7 | gem 'rails_autolink' |
8 | +gem 'pg' | ||
8 | 9 | ||
9 | # TODO needs a rebuild diff-lcs wrt wheezy | 10 | # TODO needs a rebuild diff-lcs wrt wheezy |
10 | 11 | ||
@@ -12,16 +13,17 @@ gem 'rails_autolink' | @@ -12,16 +13,17 @@ gem 'rails_autolink' | ||
12 | # with their GEM names (not the Debian package names) | 13 | # with their GEM names (not the Debian package names) |
13 | 14 | ||
14 | group :test do | 15 | group :test do |
15 | - #gem 'rspec' | ||
16 | - #gem 'rspec-rails' | 16 | + gem 'rspec' |
17 | + gem 'rspec-rails' | ||
17 | end | 18 | end |
18 | 19 | ||
19 | group :cucumber do | 20 | group :cucumber do |
20 | gem 'rake' | 21 | gem 'rake' |
21 | - # TODO gem 'cucumber-rails' | ||
22 | - # TODO gem 'capybara' | ||
23 | - # gem 'cucumber' | ||
24 | - # TODO gem 'database_cleaner' | 22 | + gem 'cucumber-rails', :require => false |
23 | + gem 'capybara' | ||
24 | + gem 'cucumber' | ||
25 | + gem 'database_cleaner' | ||
26 | + gem 'selenium-webdriver' | ||
25 | end | 27 | end |
26 | 28 | ||
27 | def program(name) | 29 | def program(name) |
Gemfile.lock
@@ -38,8 +38,31 @@ GEM | @@ -38,8 +38,31 @@ GEM | ||
38 | rails (>= 3, < 5) | 38 | rails (>= 3, < 5) |
39 | arel (3.0.2) | 39 | arel (3.0.2) |
40 | builder (3.0.0) | 40 | builder (3.0.0) |
41 | + capybara (2.2.1) | ||
42 | + mime-types (>= 1.16) | ||
43 | + nokogiri (>= 1.3.3) | ||
44 | + rack (>= 1.0.0) | ||
45 | + rack-test (>= 0.5.4) | ||
46 | + xpath (~> 2.0) | ||
47 | + childprocess (0.4.0) | ||
48 | + ffi (~> 1.0, >= 1.0.11) | ||
49 | + cucumber (1.3.2) | ||
50 | + builder (>= 2.1.2) | ||
51 | + diff-lcs (>= 1.1.3) | ||
52 | + gherkin (~> 2.12.0) | ||
53 | + multi_json (~> 1.3) | ||
54 | + cucumber-rails (1.4.0) | ||
55 | + capybara (>= 1.1.2) | ||
56 | + cucumber (>= 1.2.0) | ||
57 | + nokogiri (>= 1.5.0) | ||
58 | + rails (>= 3.0.0) | ||
59 | + database_cleaner (1.2.0) | ||
60 | + diff-lcs (1.2.5) | ||
41 | erubis (2.7.0) | 61 | erubis (2.7.0) |
42 | fast_gettext (0.6.8) | 62 | fast_gettext (0.6.8) |
63 | + ffi (1.9.3) | ||
64 | + gherkin (2.12.2) | ||
65 | + multi_json (~> 1.3) | ||
43 | hike (1.2.1) | 66 | hike (1.2.1) |
44 | i18n (0.6.0) | 67 | i18n (0.6.0) |
45 | journey (1.0.3) | 68 | journey (1.0.3) |
@@ -48,7 +71,11 @@ GEM | @@ -48,7 +71,11 @@ GEM | ||
48 | mime-types (~> 1.16) | 71 | mime-types (~> 1.16) |
49 | treetop (~> 1.4.8) | 72 | treetop (~> 1.4.8) |
50 | mime-types (1.19) | 73 | mime-types (1.19) |
74 | + mini_portile (0.5.2) | ||
51 | multi_json (1.3.6) | 75 | multi_json (1.3.6) |
76 | + nokogiri (1.6.1) | ||
77 | + mini_portile (~> 0.5.0) | ||
78 | + pg (0.17.1) | ||
52 | polyglot (0.3.3) | 79 | polyglot (0.3.3) |
53 | prototype-rails (3.2.1) | 80 | prototype-rails (3.2.1) |
54 | rails (~> 3.2) | 81 | rails (~> 3.2) |
@@ -78,6 +105,28 @@ GEM | @@ -78,6 +105,28 @@ GEM | ||
78 | thor (>= 0.14.6, < 2.0) | 105 | thor (>= 0.14.6, < 2.0) |
79 | rake (0.9.2.2) | 106 | rake (0.9.2.2) |
80 | rdoc (3.9.4) | 107 | rdoc (3.9.4) |
108 | + rspec (2.14.1) | ||
109 | + rspec-core (~> 2.14.0) | ||
110 | + rspec-expectations (~> 2.14.0) | ||
111 | + rspec-mocks (~> 2.14.0) | ||
112 | + rspec-core (2.14.7) | ||
113 | + rspec-expectations (2.14.5) | ||
114 | + diff-lcs (>= 1.1.3, < 2.0) | ||
115 | + rspec-mocks (2.14.5) | ||
116 | + rspec-rails (2.14.1) | ||
117 | + actionpack (>= 3.0) | ||
118 | + activemodel (>= 3.0) | ||
119 | + activesupport (>= 3.0) | ||
120 | + railties (>= 3.0) | ||
121 | + rspec-core (~> 2.14.0) | ||
122 | + rspec-expectations (~> 2.14.0) | ||
123 | + rspec-mocks (~> 2.14.0) | ||
124 | + rubyzip (1.1.0) | ||
125 | + selenium-webdriver (2.39.0) | ||
126 | + childprocess (>= 0.2.5) | ||
127 | + multi_json (~> 1.0) | ||
128 | + rubyzip (~> 1.0) | ||
129 | + websocket (~> 1.0.4) | ||
81 | sprockets (2.1.3) | 130 | sprockets (2.1.3) |
82 | hike (~> 1.2) | 131 | hike (~> 1.2) |
83 | multi_json (~> 1.0) | 132 | multi_json (~> 1.0) |
@@ -89,15 +138,26 @@ GEM | @@ -89,15 +138,26 @@ GEM | ||
89 | polyglot | 138 | polyglot |
90 | polyglot (>= 0.3.1) | 139 | polyglot (>= 0.3.1) |
91 | tzinfo (0.3.33) | 140 | tzinfo (0.3.33) |
141 | + websocket (1.0.7) | ||
142 | + xpath (2.0.0) | ||
143 | + nokogiri (~> 1.3) | ||
92 | 144 | ||
93 | PLATFORMS | 145 | PLATFORMS |
94 | ruby | 146 | ruby |
95 | 147 | ||
96 | DEPENDENCIES | 148 | DEPENDENCIES |
97 | acts-as-taggable-on | 149 | acts-as-taggable-on |
150 | + capybara | ||
151 | + cucumber | ||
152 | + cucumber-rails | ||
153 | + database_cleaner | ||
98 | fast_gettext | 154 | fast_gettext |
155 | + pg | ||
99 | prototype-rails | 156 | prototype-rails |
100 | prototype_legacy_helper (= 0.0.0)! | 157 | prototype_legacy_helper (= 0.0.0)! |
101 | rails | 158 | rails |
102 | rails_autolink | 159 | rails_autolink |
103 | rake | 160 | rake |
161 | + rspec | ||
162 | + rspec-rails | ||
163 | + selenium-webdriver |
config/environments/cucumber.rb
1 | -# Edit at your own peril - it's recommended to regenerate this file | ||
2 | -# in the future when you upgrade to a newer version of Cucumber. | 1 | +Noosfero::Application.configure do |
2 | + # Edit at your own peril - it's recommended to regenerate this file | ||
3 | + # in the future when you upgrade to a newer version of Cucumber. | ||
3 | 4 | ||
4 | -# IMPORTANT: Setting config.cache_classes to false is known to | ||
5 | -# break Cucumber's use_transactional_fixtures method. | ||
6 | -# For more information see https://rspec.lighthouseapp.com/projects/16211/tickets/165 | ||
7 | -config.cache_classes = true | 5 | + # IMPORTANT: Setting config.cache_classes to false is known to |
6 | + # break Cucumber's use_transactional_fixtures method. | ||
7 | + # For more information see https://rspec.lighthouseapp.com/projects/16211/tickets/165 | ||
8 | + config.cache_classes = true | ||
8 | 9 | ||
9 | -# Log error messages when you accidentally call methods on nil. | ||
10 | -config.whiny_nils = true | 10 | + config.active_support.deprecation = :log |
11 | 11 | ||
12 | -# Show full error reports and disable caching | ||
13 | -config.action_controller.perform_caching = false | 12 | + # Log error messages when you accidentally call methods on nil. |
13 | + config.whiny_nils = true | ||
14 | 14 | ||
15 | -# Disable request forgery protection in test environment | ||
16 | -config.action_controller.allow_forgery_protection = false | 15 | + # Show full error reports and disable caching |
16 | + config.action_controller.perform_caching = false | ||
17 | 17 | ||
18 | -# Tell Action Mailer not to deliver emails to the real world. | ||
19 | -# The :test delivery method accumulates sent emails in the | ||
20 | -# ActionMailer::Base.deliveries array. | ||
21 | -config.action_mailer.delivery_method = :test | 18 | + # Disable request forgery protection in test environment |
19 | + config.action_controller.allow_forgery_protection = false | ||
22 | 20 | ||
23 | -config.gem 'cucumber-rails', :lib => false, :version => '>=0.3.2' unless File.directory?(Rails.root.join('vendor/plugins/cucumber-rails')) | ||
24 | -config.gem 'database_cleaner', :lib => false, :version => '>=0.5.0' unless File.directory?(Rails.root.join('vendor/plugins/database_cleaner')) | ||
25 | -config.gem 'capybara', :lib => false, :version => '>=0.3.5' unless File.directory?(Rails.root.join('vendor/plugins/capybara')) | 21 | + # Tell Action Mailer not to deliver emails to the real world. |
22 | + # The :test delivery method accumulates sent emails in the | ||
23 | + # ActionMailer::Base.deliveries array. | ||
24 | + config.action_mailer.delivery_method = :test | ||
26 | 25 | ||
26 | + config.gem 'cucumber-rails', :lib => false, :version => '>=0.3.2' unless File.directory?(Rails.root.join('vendor/plugins/cucumber-rails')) | ||
27 | + config.gem 'database_cleaner', :lib => false, :version => '>=0.5.0' unless File.directory?(Rails.root.join('vendor/plugins/database_cleaner')) | ||
28 | + config.gem 'capybara', :lib => false, :version => '>=0.3.5' unless File.directory?(Rails.root.join('vendor/plugins/capybara')) | ||
29 | +end |
features/step_definitions/noosfero_steps.rb
@@ -324,8 +324,7 @@ end | @@ -324,8 +324,7 @@ end | ||
324 | 324 | ||
325 | Given /^feature "(.+)" is (enabled|disabled) on environment$/ do |feature, status| | 325 | Given /^feature "(.+)" is (enabled|disabled) on environment$/ do |feature, status| |
326 | e = Environment.default | 326 | e = Environment.default |
327 | - status.chop! | ||
328 | - e.send status, feature | 327 | + e.send status.chop, feature |
329 | e.save | 328 | e.save |
330 | end | 329 | end |
331 | 330 |
features/support/env.rb
@@ -4,56 +4,70 @@ | @@ -4,56 +4,70 @@ | ||
4 | # instead of editing this one. Cucumber will automatically load all features/**/*.rb | 4 | # instead of editing this one. Cucumber will automatically load all features/**/*.rb |
5 | # files. | 5 | # files. |
6 | 6 | ||
7 | -ENV["RAILS_ENV"] ||= "cucumber" | 7 | +require 'cucumber/rails' |
8 | 8 | ||
9 | require File.expand_path(File.dirname(__FILE__) + '/../../config/environment') | 9 | require File.expand_path(File.dirname(__FILE__) + '/../../config/environment') |
10 | 10 | ||
11 | -require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support | ||
12 | -require 'cucumber/rails/world' | ||
13 | -require 'cucumber/rails/active_record' | ||
14 | -require 'cucumber/web/tableish' | ||
15 | - | ||
16 | -require 'capybara/rails' | ||
17 | -require 'capybara/cucumber' | ||
18 | -require 'capybara/session' | ||
19 | -# require 'cucumber/rails/capybara_javascript_emulation' # Lets you click links with onclick javascript handlers without using @culerity or @javascript | ||
20 | -# Capybara defaults to XPath selectors rather than Webrat's default of CSS3. In | ||
21 | -# order to ease the transition to Capybara we set the default here. If you'd | ||
22 | -# prefer to use XPath just remove this line and adjust any selectors in your | ||
23 | -# steps to use the XPath syntax. | ||
24 | -Capybara.default_selector = :css | ||
25 | Capybara.ignore_hidden_elements = true | 11 | Capybara.ignore_hidden_elements = true |
26 | 12 | ||
27 | -# If you set this to false, any error raised from within your app will bubble | ||
28 | -# up to your step definition and out to cucumber unless you catch it somewhere | ||
29 | -# on the way. You can make Rails rescue errors and render error pages on a | ||
30 | -# per-scenario basis by tagging a scenario or feature with the @allow-rescue tag. | 13 | +# Capybara defaults to CSS3 selectors rather than XPath. |
14 | +# If you'd prefer to use XPath, just uncomment this line and adjust any | ||
15 | +# selectors in your step definitions to use the XPath syntax. | ||
16 | +# Capybara.default_selector = :xpath | ||
17 | + | ||
18 | +# By default, any exception happening in your Rails application will bubble up | ||
19 | +# to Cucumber so that your scenario will fail. This is a different from how | ||
20 | +# your application behaves in the production environment, where an error page will | ||
21 | +# be rendered instead. | ||
22 | +# | ||
23 | +# Sometimes we want to override this default behaviour and allow Rails to rescue | ||
24 | +# exceptions and display an error page (just like when the app is running in production). | ||
25 | +# Typical scenarios where you want to do this is when you test your error pages. | ||
26 | +# There are two ways to allow Rails to rescue exceptions: | ||
27 | +# | ||
28 | +# 1) Tag your scenario (or feature) with @allow-rescue | ||
29 | +# | ||
30 | +# 2) Set the value below to true. Beware that doing this globally is not | ||
31 | +# recommended as it will mask a lot of errors for you! | ||
31 | # | 32 | # |
32 | -# If you set this to true, Rails will rescue all errors and render error | ||
33 | -# pages, more or less in the same way your application would behave in the | ||
34 | -# default production environment. It's not recommended to do this for all | ||
35 | -# of your scenarios, as this makes it hard to discover errors in your application. | ||
36 | ActionController::Base.allow_rescue = false | 33 | ActionController::Base.allow_rescue = false |
37 | 34 | ||
38 | -# If you set this to true, each scenario will run in a database transaction. | ||
39 | -# You can still turn off transactions on a per-scenario basis, simply tagging | ||
40 | -# a feature or scenario with the @no-txn tag. If you are using Capybara, | ||
41 | -# tagging with @culerity or @javascript will also turn transactions off. | 35 | +# Remove/comment out the lines below if your app doesn't have a database. |
36 | +# For some databases (like MongoDB and CouchDB) you may need to use :truncation instead. | ||
37 | +begin | ||
38 | + DatabaseCleaner.strategy = :transaction | ||
39 | +rescue NameError | ||
40 | + raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it." | ||
41 | +end | ||
42 | + | ||
43 | +# You may also want to configure DatabaseCleaner to use different strategies for certain features and scenarios. | ||
44 | +# See the DatabaseCleaner documentation for details. Example: | ||
45 | +# | ||
46 | +# Before('@no-txn,@selenium,@culerity,@celerity,@javascript') do | ||
47 | +# # { :except => [:widgets] } may not do what you expect here | ||
48 | +# # as Cucumber::Rails::Database.javascript_strategy overrides | ||
49 | +# # this setting. | ||
50 | +# DatabaseCleaner.strategy = :truncation | ||
51 | +# end | ||
42 | # | 52 | # |
43 | -# If you set this to false, transactions will be off for all scenarios, | ||
44 | -# regardless of whether you use @no-txn or not. | 53 | +# Before('~@no-txn', '~@selenium', '~@culerity', '~@celerity', '~@javascript') do |
54 | +# DatabaseCleaner.strategy = :transaction | ||
55 | +# end | ||
45 | # | 56 | # |
46 | -# Beware that turning transactions off will leave data in your database | ||
47 | -# after each scenario, which can lead to hard-to-debug failures in | ||
48 | -# subsequent scenarios. If you do this, we recommend you create a Before | ||
49 | -# block that will explicitly put your database in a known state. | 57 | + |
58 | +# Possible values are :truncation and :transaction | ||
59 | +# The :transaction strategy is faster, but might give you threading problems. | ||
60 | +# See https://github.com/cucumber/cucumber-rails/blob/master/features/choose_javascript_database_strategy.feature | ||
61 | +Cucumber::Rails::Database.javascript_strategy = :truncation | ||
62 | + | ||
50 | Cucumber::Rails::World.use_transactional_fixtures = true | 63 | Cucumber::Rails::World.use_transactional_fixtures = true |
51 | # How to clean your database when transactions are turned off. See | 64 | # How to clean your database when transactions are turned off. See |
52 | # http://github.com/bmabey/database_cleaner for more info. | 65 | # http://github.com/bmabey/database_cleaner for more info. |
53 | 66 | ||
54 | Before do | 67 | Before do |
55 | - Fixtures.reset_cache | ||
56 | - fixtures_folder = File.join(RAILS_ROOT, 'test', 'fixtures') | 68 | + ActiveRecord::Fixtures.reset_cache |
69 | + fixtures_folder = Rails.root.join('test', 'fixtures') | ||
57 | fixtures = ['environments', 'roles'] | 70 | fixtures = ['environments', 'roles'] |
58 | - Fixtures.create_fixtures(fixtures_folder, fixtures) | 71 | + ActiveRecord::Fixtures.create_fixtures(fixtures_folder, fixtures) |
59 | end | 72 | end |
73 | + |
features/support/fixtures.rb
lib/tasks/cucumber.rake
1 | # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril. | 1 | # IMPORTANT: This file is generated by cucumber-rails - edit at your own peril. |
2 | -# It is recommended to regenerate this file in the future when you upgrade to a | ||
3 | -# newer version of cucumber-rails. Consider adding your own code to a new file | 2 | +# It is recommended to regenerate this file in the future when you upgrade to a |
3 | +# newer version of cucumber-rails. Consider adding your own code to a new file | ||
4 | # instead of editing this one. Cucumber will automatically load all features/**/*.rb | 4 | # instead of editing this one. Cucumber will automatically load all features/**/*.rb |
5 | # files. | 5 | # files. |
6 | 6 | ||
7 | 7 | ||
8 | unless ARGV.any? {|a| a =~ /^gems/} # Don't load anything when running the gems:* tasks | 8 | unless ARGV.any? {|a| a =~ /^gems/} # Don't load anything when running the gems:* tasks |
9 | 9 | ||
10 | -vendored_cucumber_bin = Dir[Rails.root.join('vendor', '{gems,plugins}', 'cucumber*', 'bin', 'cucumber')].first | 10 | +vendored_cucumber_bin = Dir["#{Rails.root}/vendor/{gems,plugins}/cucumber*/bin/cucumber"].first |
11 | $LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + '/../lib') unless vendored_cucumber_bin.nil? | 11 | $LOAD_PATH.unshift(File.dirname(vendored_cucumber_bin) + '/../lib') unless vendored_cucumber_bin.nil? |
12 | 12 | ||
13 | begin | 13 | begin |
14 | require 'cucumber/rake/task' | 14 | require 'cucumber/rake/task' |
15 | 15 | ||
16 | namespace :cucumber do | 16 | namespace :cucumber do |
17 | - Cucumber::Rake::Task.new({:ok => 'db:test:prepare'}, 'Run features that should pass') do |t| | 17 | + Cucumber::Rake::Task.new({:ok => 'test:prepare'}, 'Run features that should pass') do |t| |
18 | t.binary = vendored_cucumber_bin # If nil, the gem's binary is used. | 18 | t.binary = vendored_cucumber_bin # If nil, the gem's binary is used. |
19 | t.fork = true # You may get faster startup if you set this to false | 19 | t.fork = true # You may get faster startup if you set this to false |
20 | t.profile = 'default' | 20 | t.profile = 'default' |
21 | end | 21 | end |
22 | 22 | ||
23 | - Cucumber::Rake::Task.new({:wip => 'db:test:prepare'}, 'Run features that are being worked on') do |t| | 23 | + Cucumber::Rake::Task.new({:wip => 'test:prepare'}, 'Run features that are being worked on') do |t| |
24 | t.binary = vendored_cucumber_bin | 24 | t.binary = vendored_cucumber_bin |
25 | t.fork = true # You may get faster startup if you set this to false | 25 | t.fork = true # You may get faster startup if you set this to false |
26 | t.profile = 'wip' | 26 | t.profile = 'wip' |
27 | end | 27 | end |
28 | 28 | ||
29 | - Cucumber::Rake::Task.new({:rerun => 'db:test:prepare'}, 'Record failing features and run only them if any exist') do |t| | 29 | + Cucumber::Rake::Task.new({:rerun => 'test:prepare'}, 'Record failing features and run only them if any exist') do |t| |
30 | t.binary = vendored_cucumber_bin | 30 | t.binary = vendored_cucumber_bin |
31 | t.fork = true # You may get faster startup if you set this to false | 31 | t.fork = true # You may get faster startup if you set this to false |
32 | t.profile = 'rerun' | 32 | t.profile = 'rerun' |
@@ -34,6 +34,12 @@ begin | @@ -34,6 +34,12 @@ begin | ||
34 | 34 | ||
35 | desc 'Run all features' | 35 | desc 'Run all features' |
36 | task :all => [:ok, :wip] | 36 | task :all => [:ok, :wip] |
37 | + | ||
38 | + task :statsetup do | ||
39 | + require 'rails/code_statistics' | ||
40 | + ::STATS_DIRECTORIES << %w(Cucumber\ features features) if File.exist?('features') | ||
41 | + ::CodeStatistics::TEST_TYPES << "Cucumber features" if File.exist?('features') | ||
42 | + end | ||
37 | end | 43 | end |
38 | desc 'Alias for cucumber:ok' | 44 | desc 'Alias for cucumber:ok' |
39 | task :cucumber => 'cucumber:ok' | 45 | task :cucumber => 'cucumber:ok' |
@@ -43,6 +49,12 @@ begin | @@ -43,6 +49,12 @@ begin | ||
43 | task :features => :cucumber do | 49 | task :features => :cucumber do |
44 | STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***" | 50 | STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***" |
45 | end | 51 | end |
52 | + | ||
53 | + # In case we don't have the generic Rails test:prepare hook, append a no-op task that we can depend upon. | ||
54 | + task 'test:prepare' do | ||
55 | + end | ||
56 | + | ||
57 | + task :stats => 'cucumber:statsetup' | ||
46 | rescue LoadError | 58 | rescue LoadError |
47 | desc 'cucumber rake task not available (cucumber not installed)' | 59 | desc 'cucumber rake task not available (cucumber not installed)' |
48 | task :cucumber do | 60 | task :cucumber do |