Skip to content

Commit 6620766

Browse files
authored
Merge pull request #350 from solidusio/kennyadsl/align-with-testing-guide
Cleanup test files copied over the host application
2 parents 09c253e + dc83686 commit 6620766

15 files changed

Lines changed: 83 additions & 91 deletions

template.rb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,25 @@
117117
if defined?(FactoryBotRails)
118118
initializer after: "factory_bot.set_factory_paths" do
119119
require 'spree/testing_support/factory_bot'
120-
FactoryBot.definition_file_paths = [
121-
*Spree::TestingSupport::FactoryBot.definition_file_paths,
122-
Rails.root.join('spec/fixtures/factories'),
120+
121+
# The paths for Solidus' core factories.
122+
solidus_paths = Spree::TestingSupport::FactoryBot.definition_file_paths
123+
124+
# Optional: Any factories you want to require from extensions.
125+
extension_paths = [
126+
# MySolidusExtension::Engine.root.join("lib/my_solidus_extension/testing_support/factories"),
127+
# or individually:
128+
# MySolidusExtension::Engine.root.join("lib/my_solidus_extension/testing_support/factories/resource.rb"),
129+
]
130+
131+
# Your application's own factories.
132+
app_paths = [
133+
Rails.root.join('spec/factories'),
123134
]
135+
136+
FactoryBot.definition_file_paths = solidus_paths + extension_paths + app_paths
124137
end
125138
end
126-
127139
RUBY
128140

129141
directory 'spec', verbose: false

templates/spec/solidus_starter_frontend_spec_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ module SolidusStarterFrontend; end
8585

8686
example.run
8787

88+
Rails.cache.clear
8889
ActionController::Base.cache_store = original_cache_store
8990
end
9091
end

templates/spec/support/solidus_starter_frontend/capybara.rb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,6 @@
88

99
Capybara.default_max_wait_time = 10
1010

11-
# Fix a selenium deprecation warning.
12-
# Ref: https://github.com/rails/rails/pull/47117
13-
require 'action_dispatch/system_testing/driver'
14-
ActionDispatch::SystemTesting::Driver.class_eval do
15-
def browser_options
16-
@options.merge(options: @browser.options).compact
17-
end
18-
end
19-
2011
RSpec.configure do |config|
2112
config.before(:each, type: :system) do
2213
driven_by((ENV['CAPYBARA_DRIVER'] || :rack_test).to_sym)

templates/spec/support/solidus_starter_frontend/features/fill_addresses_fields.rb

Lines changed: 0 additions & 29 deletions
This file was deleted.

templates/spec/support/solidus_starter_frontend/solidus.rb

Lines changed: 0 additions & 16 deletions
This file was deleted.

templates/spec/support/solidus_starter_frontend/features/assets.rb renamed to templates/spec/support/solidus_starter_frontend/system/assets.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
RSpec.configure do |config|
2-
config.when_first_matching_example_defined(type: :feature) do
3-
config.before(:suite) { Rails.application.precompiled_assets }
4-
end
5-
62
config.when_first_matching_example_defined(type: :system) do
73
config.before(:suite) { Rails.application.precompiled_assets }
84
end
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
module SolidusStarterFrontend
2+
module System
3+
module CheckoutHelpers
4+
#
5+
# Authentication
6+
#
7+
def checkout_as_guest
8+
click_button "Checkout"
9+
10+
within '#guest_checkout' do
11+
fill_in 'Email', with: 'test@example.com'
12+
end
13+
14+
click_on 'Continue'
15+
end
16+
17+
#
18+
# Address
19+
#
20+
def fill_addresses_fields_with(address)
21+
fields = %w[
22+
address1
23+
city
24+
zipcode
25+
phone
26+
]
27+
fields += if SolidusSupport.combined_first_and_last_name_in_address?
28+
%w[name]
29+
else
30+
%w[firstname lastname]
31+
end
32+
33+
fields.each do |field|
34+
fill_in "order_bill_address_attributes_#{field}", with: address.send(field).to_s
35+
end
36+
select 'United States', from: "order_bill_address_attributes_country_id"
37+
select address.state.name.to_s, from: "order_bill_address_attributes_state_id"
38+
39+
check 'order_use_billing'
40+
end
41+
42+
#
43+
# Payment
44+
#
45+
def find_existing_payment_radio(wallet_source_id)
46+
find("[name='order[wallet_payment_source_id]'][value='#{wallet_source_id}']")
47+
end
48+
49+
def find_payment_radio(payment_method_id)
50+
find("[name='order[payments_attributes][][payment_method_id]'][value='#{payment_method_id}']")
51+
end
52+
53+
def find_payment_fieldset(payment_method_id)
54+
find("fieldset[name='payment-method-#{payment_method_id}']")
55+
end
56+
end
57+
end
58+
end

templates/spec/support/solidus_starter_frontend/system_helpers.rb

Lines changed: 0 additions & 23 deletions
This file was deleted.

templates/spec/system/address_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require 'solidus_starter_frontend_spec_helper'
44

55
RSpec.describe 'Address', type: :system, inaccessible: true do
6-
include SolidusStarterFrontend::SystemHelpers
6+
include SolidusStarterFrontend::System::CheckoutHelpers
77

88
let!(:product) { create(:product, name: "RoR Mug") }
99
let!(:order) { create(:order_with_totals, state: 'cart') }

templates/spec/system/authentication/checkout_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
require 'solidus_starter_frontend_spec_helper'
44

55
RSpec.feature 'Checkout', :js, type: :system do
6+
include SolidusStarterFrontend::System::CheckoutHelpers
7+
68
given!(:store) { create(:store) }
79
given!(:country) { create(:country, name: 'United States', states_required: true) }
810
given!(:state) { create(:state, name: 'Maryland', country: country) }

0 commit comments

Comments
 (0)