Skip to content

Commit

Permalink
Merge pull request #3552 from blocknotes/blocknotes/system-specs-config
Browse files Browse the repository at this point in the history
Add system specs configuration
  • Loading branch information
kennyadsl authored Mar 20, 2020
2 parents d456b11 + 6ef1e7f commit 6a21551
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 31 deletions.
21 changes: 4 additions & 17 deletions backend/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
require 'spree/testing_support/url_helpers'
require 'spree/testing_support/order_walkthrough'
require 'spree/testing_support/capybara_ext'
require 'spree/testing_support/precompiled_assets'
require 'spree/testing_support/translations'

require 'capybara-screenshot/rspec'
Capybara.save_path = ENV['CIRCLE_ARTIFACTS'] if ENV['CIRCLE_ARTIFACTS']
Expand Down Expand Up @@ -79,15 +81,6 @@
DatabaseCleaner.clean_with :truncation
end

config.when_first_matching_example_defined(type: :feature) do
config.before :suite do
# Preload assets
# This should avoid capybara timeouts, and avoid counting asset compilation
# towards the timing of the first feature spec.
Rails.application.precompiled_assets
end
end

config.before do
Rails.cache.clear
if RSpec.current_example.metadata[:js] && page.driver.browser.respond_to?(:url_blacklist)
Expand All @@ -96,14 +89,7 @@
end

config.include BaseFeatureHelper, type: :feature

config.after(:each, type: :feature) do |example|
missing_translations = page.body.scan(/translation missing: #{I18n.locale}\.(.*?)[\s<\"&]/)
if missing_translations.any?
puts "Found missing translations: #{missing_translations.inspect}"
puts "In spec: #{example.location}"
end
end
config.include BaseFeatureHelper, type: :system

config.include FactoryBot::Syntax::Methods
config.include ActiveSupport::Testing::Assertions
Expand All @@ -113,6 +99,7 @@
config.include Spree::TestingSupport::UrlHelpers
config.include Spree::TestingSupport::ControllerRequests, type: :controller
config.include Spree::TestingSupport::Flash
config.include Spree::TestingSupport::Translations

config.extend WithModel

Expand Down
1 change: 1 addition & 0 deletions core/lib/spree/testing_support/authorization_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,5 @@ def custom_authorization!(&block)
config.extend Spree::TestingSupport::AuthorizationHelpers::Controller, type: :controller
config.extend Spree::TestingSupport::AuthorizationHelpers::Request, type: :feature
config.extend Spree::TestingSupport::AuthorizationHelpers::Request, type: :request
config.extend Spree::TestingSupport::AuthorizationHelpers::Request, type: :system
end
23 changes: 23 additions & 0 deletions core/lib/spree/testing_support/blacklist_urls.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

module Spree
module TestingSupport
module BlacklistUrls
def setup_url_blacklist(browser)
if browser.respond_to?(:url_blacklist)
browser.url_blacklist = ['http://fonts.googleapis.com']
end
end
end
end
end

RSpec.configure do |config|
config.before(:each, type: :feature) do
setup_url_blacklist(page.driver.browser)
end

config.before(:each, type: :system) do
setup_url_blacklist(page.driver.browser)
end
end
15 changes: 15 additions & 0 deletions core/lib/spree/testing_support/precompiled_assets.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

RSpec.configure do |config|
config.when_first_matching_example_defined(type: :feature) do
config.before :suite do
Rails.application.precompiled_assets
end
end

config.when_first_matching_example_defined(type: :system) do
config.before :suite do
Rails.application.precompiled_assets
end
end
end
25 changes: 25 additions & 0 deletions core/lib/spree/testing_support/translations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

module Spree
module TestingSupport
module Translations
def check_missing_translations(page, example)
missing_translations = page.body.scan(/translation missing: #{I18n.locale}\.(.*?)[\s<\"&]/)
if missing_translations.any?
puts "Found missing translations: #{missing_translations.inspect}"
puts "In spec: #{example.location}"
end
end
end
end
end

RSpec.configure do |config|
config.after(:each, type: :feature) do |example|
check_missing_translations(page, example)
end

config.after(:each, type: :system) do |example|
check_missing_translations(page, example)
end
end
18 changes: 4 additions & 14 deletions frontend/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
require 'spree/testing_support/url_helpers'
require 'spree/testing_support/order_walkthrough'
require 'spree/testing_support/caching'
require 'spree/testing_support/blacklist_urls'
require 'spree/testing_support/translations'

require 'capybara-screenshot/rspec'
Capybara.save_path = ENV['CIRCLE_ARTIFACTS'] if ENV['CIRCLE_ARTIFACTS']
Expand Down Expand Up @@ -77,26 +79,14 @@
Rails.cache.clear
end

config.before(:each, type: :feature) do
if page.driver.browser.respond_to?(:url_blacklist)
page.driver.browser.url_blacklist = ['http://fonts.googleapis.com']
end
end

config.after(:each, type: :feature) do |example|
missing_translations = page.body.scan(/translation missing: #{I18n.locale}\.(.*?)[\s<\"&]/)
if missing_translations.any?
puts "Found missing translations: #{missing_translations.inspect}"
puts "In spec: #{example.location}"
end
end

config.include FactoryBot::Syntax::Methods

config.include Spree::TestingSupport::Preferences
config.include Spree::TestingSupport::UrlHelpers
config.include Spree::TestingSupport::ControllerRequests, type: :controller
config.include Spree::TestingSupport::Flash
config.include Spree::TestingSupport::BlacklistUrls
config.include Spree::TestingSupport::Translations

config.example_status_persistence_file_path = "./spec/examples.txt"

Expand Down

0 comments on commit 6a21551

Please sign in to comment.