mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-02 02:11:33 +00:00
Merge pull request #3469 from kristinalim/fix/3468-intermittent_spec_failures
3468 [Flaky Spec] Check for presence of flash div before trying to get its text
This commit is contained in:
@@ -29,10 +29,13 @@ feature 'shipping methods' do
|
||||
fill_in 'shipping_method_name', with: 'Carrier Pidgeon'
|
||||
check "shipping_method_distributor_ids_#{d1.id}"
|
||||
check "shipping_method_distributor_ids_#{d2.id}"
|
||||
click_button 'Create'
|
||||
click_button I18n.t("actions.create")
|
||||
|
||||
expect(page).to have_no_button I18n.t("actions.create")
|
||||
|
||||
# Then the shipping method should have its distributor set
|
||||
flash_message.should == 'Shipping method "Carrier Pidgeon" has been successfully created!'
|
||||
message = "Shipping method \"Carrier Pidgeon\" has been successfully created!"
|
||||
expect(page).to have_flash_message message
|
||||
|
||||
sm = Spree::ShippingMethod.last
|
||||
sm.name.should == 'Carrier Pidgeon'
|
||||
@@ -98,9 +101,12 @@ feature 'shipping methods' do
|
||||
expect(page).to have_css '.tag-item'
|
||||
end
|
||||
|
||||
click_button 'Create'
|
||||
click_button I18n.t("actions.create")
|
||||
|
||||
expect(page).to have_no_button I18n.t("actions.create")
|
||||
message = "Shipping method \"Teleport\" has been successfully created!"
|
||||
expect(page).to have_flash_message message
|
||||
|
||||
flash_message.should == 'Shipping method "Teleport" has been successfully created!'
|
||||
expect(first('tags-input .tag-list ti-tag-item')).to have_content "local"
|
||||
|
||||
shipping_method = Spree::ShippingMethod.find_by_name('Teleport')
|
||||
|
||||
31
spec/support/matchers/flash_message_matchers.rb
Normal file
31
spec/support/matchers/flash_message_matchers.rb
Normal file
@@ -0,0 +1,31 @@
|
||||
RSpec::Matchers.define :have_flash_message do |message|
|
||||
match do |node|
|
||||
@message, @node = message, node
|
||||
|
||||
# Ignore leading and trailing whitespace. Later versions of Capybara have :exact_text option.
|
||||
# The :exact option is not supported in has_selector?.
|
||||
message_substring_regex = substring_match_regex(message)
|
||||
node.has_selector?(".flash", text: message_substring_regex, visible: false)
|
||||
end
|
||||
|
||||
failure_message do |actual|
|
||||
"expected to find flash message ##{@message}"
|
||||
end
|
||||
|
||||
match_when_negated do |node|
|
||||
@message, @node = message, node
|
||||
|
||||
# Ignore leading and trailing whitespace. Later versions of Capybara have :exact_text option.
|
||||
# The :exact option is not supported in has_selector?.
|
||||
message_substring_regex = substring_match_regex(message)
|
||||
node.has_no_selector?(".flash", text: message_substring_regex, visible: false)
|
||||
end
|
||||
|
||||
failure_message_when_negated do |actual|
|
||||
"expected not to find flash message ##{@message}"
|
||||
end
|
||||
|
||||
def substring_match_regex(text)
|
||||
/\A\s*#{Regexp.escape(text)}\s*\Z/
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user