Use system specs instead of feature specs
We get rid of database cleaner, and JavaScript tests are faster because between tests we now rollback transactions instead of truncating the database.
This commit is contained in:
2
Gemfile
2
Gemfile
@@ -82,7 +82,6 @@ group :test do
|
|||||||
gem "capybara", "~> 3.29.0"
|
gem "capybara", "~> 3.29.0"
|
||||||
gem "capybara-webmock", "~> 0.5.3"
|
gem "capybara-webmock", "~> 0.5.3"
|
||||||
gem "coveralls", "~> 0.8.22", require: false
|
gem "coveralls", "~> 0.8.22", require: false
|
||||||
gem "database_cleaner", "~> 1.7.0"
|
|
||||||
gem "email_spec", "~> 2.2.0"
|
gem "email_spec", "~> 2.2.0"
|
||||||
gem "rspec-rails", "~> 3.8"
|
gem "rspec-rails", "~> 3.8"
|
||||||
gem "selenium-webdriver", "~> 3.141"
|
gem "selenium-webdriver", "~> 3.141"
|
||||||
@@ -94,6 +93,7 @@ group :development do
|
|||||||
gem "capistrano-rails", "~> 1.4.0", require: false
|
gem "capistrano-rails", "~> 1.4.0", require: false
|
||||||
gem "capistrano3-delayed-job", "~> 1.7.3"
|
gem "capistrano3-delayed-job", "~> 1.7.3"
|
||||||
gem "capistrano3-puma", "~> 4.0.0"
|
gem "capistrano3-puma", "~> 4.0.0"
|
||||||
|
gem "database_cleaner", "~> 1.7.0"
|
||||||
gem "erb_lint", require: false
|
gem "erb_lint", require: false
|
||||||
gem "github_changelog_generator", "~> 1.15.0"
|
gem "github_changelog_generator", "~> 1.15.0"
|
||||||
gem "mdl", "~> 0.5.0", require: false
|
gem "mdl", "~> 0.5.0", require: false
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
unless Rails.env.test?
|
||||||
require "database_cleaner"
|
require "database_cleaner"
|
||||||
DatabaseCleaner.clean_with :truncation
|
DatabaseCleaner.clean_with :truncation
|
||||||
|
end
|
||||||
@logger = Logger.new(STDOUT)
|
@logger = Logger.new(STDOUT)
|
||||||
@logger.formatter = proc do |_severity, _datetime, _progname, msg|
|
@logger.formatter = proc do |_severity, _datetime, _progname, msg|
|
||||||
msg unless @avoid_log
|
msg unless @avoid_log
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe "rake sitemap:create", type: :feature do
|
describe "rake sitemap:create", type: :system do
|
||||||
let(:file) { Rails.root.join("public", "sitemap.xml") }
|
let(:file) { Rails.root.join("public", "sitemap.xml") }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
|||||||
@@ -26,10 +26,6 @@ RSpec.configure do |config|
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Capybara.register_driver :chrome do |app|
|
|
||||||
Capybara::Selenium::Driver.new(app, browser: :chrome)
|
|
||||||
end
|
|
||||||
|
|
||||||
Capybara.register_driver :headless_chrome do |app|
|
Capybara.register_driver :headless_chrome do |app|
|
||||||
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
|
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
|
||||||
"goog:chromeOptions" => {
|
"goog:chromeOptions" => {
|
||||||
@@ -44,8 +40,6 @@ Capybara.register_driver :headless_chrome do |app|
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
Capybara.javascript_driver = :headless_chrome
|
|
||||||
|
|
||||||
Capybara.exact = true
|
Capybara.exact = true
|
||||||
|
|
||||||
OmniAuth.config.test_mode = true
|
OmniAuth.config.test_mode = true
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
require "factory_bot_rails"
|
require "factory_bot_rails"
|
||||||
require "database_cleaner"
|
|
||||||
require "email_spec"
|
require "email_spec"
|
||||||
require "devise"
|
require "devise"
|
||||||
require "knapsack_pro"
|
require "knapsack_pro"
|
||||||
@@ -9,7 +8,7 @@ Dir["./spec/support/**/*.rb"].sort.each { |f| require f }
|
|||||||
Dir["./spec/shared/**/*.rb"].sort.each { |f| require f }
|
Dir["./spec/shared/**/*.rb"].sort.each { |f| require f }
|
||||||
|
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
config.use_transactional_fixtures = false
|
config.use_transactional_fixtures = true
|
||||||
|
|
||||||
config.filter_run :focus
|
config.filter_run :focus
|
||||||
config.run_all_when_everything_filtered = true
|
config.run_all_when_everything_filtered = true
|
||||||
@@ -21,29 +20,7 @@ RSpec.configure do |config|
|
|||||||
config.include(CommonActions)
|
config.include(CommonActions)
|
||||||
config.include(ActiveSupport::Testing::TimeHelpers)
|
config.include(ActiveSupport::Testing::TimeHelpers)
|
||||||
|
|
||||||
config.before(:suite) do
|
|
||||||
DatabaseCleaner.clean_with :truncation
|
|
||||||
end
|
|
||||||
|
|
||||||
config.before(:suite) do
|
|
||||||
if config.use_transactional_fixtures?
|
|
||||||
raise(<<-MSG)
|
|
||||||
Delete line `config.use_transactional_fixtures = true` from rails_helper.rb
|
|
||||||
(or set it to false) to prevent uncommitted transactions being used in
|
|
||||||
JavaScript-dependent specs.
|
|
||||||
|
|
||||||
During testing, the app-under-test that the browser driver connects to
|
|
||||||
uses a different database connection to the database connection used by
|
|
||||||
the spec. The app's database connection would not be able to access
|
|
||||||
uncommitted transaction data setup over the spec's database connection.
|
|
||||||
MSG
|
|
||||||
end
|
|
||||||
|
|
||||||
DatabaseCleaner.clean_with(:truncation)
|
|
||||||
end
|
|
||||||
|
|
||||||
config.before do |example|
|
config.before do |example|
|
||||||
DatabaseCleaner.strategy = :transaction
|
|
||||||
I18n.locale = :en
|
I18n.locale = :en
|
||||||
Globalize.locale = nil
|
Globalize.locale = nil
|
||||||
Globalize.set_fallbacks_to_all_available_locales
|
Globalize.set_fallbacks_to_all_available_locales
|
||||||
@@ -51,20 +28,7 @@ RSpec.configure do |config|
|
|||||||
Setting["feature.user.skip_verification"] = nil
|
Setting["feature.user.skip_verification"] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
config.before(:each, type: :feature) do
|
config.before(:each, type: :system) do
|
||||||
# :rack_test driver's Rack app under test shares database connection
|
|
||||||
# with the specs, so continue to use transaction strategy for speed.
|
|
||||||
driver_shares_db_connection_with_specs = Capybara.current_driver == :rack_test
|
|
||||||
|
|
||||||
unless driver_shares_db_connection_with_specs
|
|
||||||
# Driver is probably for an external browser with an app
|
|
||||||
# under test that does *not* share a database connection with the
|
|
||||||
# specs, so use truncation strategy.
|
|
||||||
DatabaseCleaner.strategy = :truncation
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
config.before(:each, type: :feature) do
|
|
||||||
Capybara::Webmock.start
|
Capybara::Webmock.start
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -76,20 +40,20 @@ RSpec.configure do |config|
|
|||||||
page.driver.reset!
|
page.driver.reset!
|
||||||
end
|
end
|
||||||
|
|
||||||
config.before do
|
config.before(:each, type: :system) do |example|
|
||||||
DatabaseCleaner.start
|
driven_by :rack_test
|
||||||
end
|
end
|
||||||
|
|
||||||
config.append_after do
|
config.before(:each, type: :system, js: true) do
|
||||||
DatabaseCleaner.clean
|
driven_by :headless_chrome
|
||||||
end
|
end
|
||||||
|
|
||||||
config.before(:each, type: :feature) do
|
config.before(:each, type: :system) do
|
||||||
Bullet.start_request
|
Bullet.start_request
|
||||||
allow(InvisibleCaptcha).to receive(:timestamp_threshold).and_return(0)
|
allow(InvisibleCaptcha).to receive(:timestamp_threshold).and_return(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
config.after(:each, type: :feature) do
|
config.after(:each, type: :system) do
|
||||||
Bullet.perform_out_of_channel_notifications if Bullet.notification?
|
Bullet.perform_out_of_channel_notifications if Bullet.notification?
|
||||||
Bullet.end_request
|
Bullet.end_request
|
||||||
end
|
end
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user