2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen# IMPORTANT: This file is generated by cucumber-rails - edit at your own peril.
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen# It is recommended to regenerate this file in the future when you upgrade to a
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen# newer version of cucumber-rails. Consider adding your own code to a new file
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen# instead of editing this one. Cucumber will automatically load all features/**/*.rb
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen# files.
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenrequire 'simplecov'
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenrequire 'sidekiq/testing'
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainenrequire 'cucumber/rails'
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenrequire 'capybara/poltergeist'
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenrequire 'cucumber/rspec/doubles'
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenrequire 'webmock'
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenrequire 'vcr'
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo SirainenCapybara.current_driver = :poltergeist
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo SirainenCapybara.javascript_driver = :poltergeist
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo SirainenCapybara.default_max_wait_time = 5
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenclass Cucumber::Rails::World
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen require Rails.root.join('spec', 'support', 'common_helper_methods.rb')
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen require Rails.root.join('spec', 'support', 'scenario_progress_formatter.rb')
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen require Rails.root.join('spec', 'support', 'shared_helper.rb')
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen # Capybara is smart enough to wait for ajax when not finding elements.
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen # In some situations the element is already existent, but has not been updated
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen # yet. This is where you need to manually use wait_for_ajax.
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen def wait_for_ajax
300e4e43ed1ca46d0614459161ca2fb460ef661aTimo Sirainen counter = 0
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen # The condition only works with poltergeist/phantomjs.
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen while page.evaluate_script("jQuery.active").to_i > 0
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen counter += 1
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen sleep(0.1)
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen if counter >= 10 * Capybara.default_max_wait_time
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen raise "AJAX request took longer than 5 seconds."
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen end
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen end
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen end
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenend
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
300e4e43ed1ca46d0614459161ca2fb460ef661aTimo Sirainen# Capybara defaults to CSS3 selectors rather than XPath.
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen# If you'd prefer to use XPath, just uncomment this line and adjust any
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen# selectors in your step definitions to use the XPath syntax.
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen# Capybara.default_selector = :xpath
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen# By default, any exception happening in your Rails application will bubble up
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen# to Cucumber so that your scenario will fail. This is a different from how
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen# your application behaves in the production environment, where an error page will
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen# be rendered instead.
00e7c3010f7da4a49881a7feb05e413af353af0aTimo Sirainen#
# 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!
#
ActionController::Base.allow_rescue = false
# 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
#
# Before('~@no-txn', '~@selenium', '~@culerity', '~@celerity', '~@javascript') do
# DatabaseCleaner.strategy = :transaction
# end
#
# 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 = :transaction
# We need to establish the basic entries in the database
FactoryGirl.create :proof_statuses
WebMock.allow_net_connect!(:net_http_connect_on_start => true)
include Warden::Test::Helpers
Warden.test_mode!
Test::Unit::AutoRunner.need_auto_run = false if defined?(Test::Unit::AutoRunner)
Test::Unit.run = true if defined?(Test::Unit) && Test::Unit.respond_to?(:run=)