From 77d0b2d5c910c4e178eccfc3611b82e6a5bbb7e3 Mon Sep 17 00:00:00 2001 From: Denny Bresch Date: Wed, 7 Aug 2019 14:55:54 +0200 Subject: [PATCH] Maintenance: Improve RSpec 'text modules group dependency examples' --- spec/support/capybara/selectors.rb | 4 +++ .../text_modules_group_dependency_examples.rb | 27 ++++++------------- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/spec/support/capybara/selectors.rb b/spec/support/capybara/selectors.rb index 0e2c7da51..a32e91a9c 100644 --- a/spec/support/capybara/selectors.rb +++ b/spec/support/capybara/selectors.rb @@ -19,3 +19,7 @@ end Capybara.add_selector(:richtext) do css { |name| "div[data-name=#{name || 'body'}]" } end + +Capybara.add_selector(:text_module) do + css { |id| %(.shortcut > ul > li[data-id="#{id}"]) } +end diff --git a/spec/system/examples/text_modules_group_dependency_examples.rb b/spec/system/examples/text_modules_group_dependency_examples.rb index 3d716bcdb..488f53467 100644 --- a/spec/system/examples/text_modules_group_dependency_examples.rb +++ b/spec/system/examples/text_modules_group_dependency_examples.rb @@ -22,30 +22,19 @@ RSpec.shared_examples 'group-dependent text modules' do |path:| visit path within(:active_content) do - - selector_group_select = 'select[name="group_id"]' - selector_text_module_selection = '.shortcut' - selector_text_module_item = ".shortcut > ul > li[data-id='%s']" - - # exercise - find(selector_group_select).find(:option, group1.name).select_option + find('select[name="group_id"]').select(group1.name) find(:richtext).send_keys('::') - # expectations - expect(page).to have_css(selector_text_module_selection, wait: 3) - expect(page).to have_css(format(selector_text_module_item, text_module_without_group.id)) - expect(page).to have_css(format(selector_text_module_item, text_module_group1.id)) - expect(page).to have_no_css(format(selector_text_module_item, text_module_group2.id)) + expect(page).to have_selector(:text_module, text_module_without_group.id) + expect(page).to have_selector(:text_module, text_module_group1.id) + expect(page).to have_no_selector(:text_module, text_module_group2.id) - # exercise - find(selector_group_select).find(:option, group2.name).select_option + find('select[name="group_id"]').select(group2.name) find(:richtext).send_keys('::') - # expectations - expect(page).to have_css(selector_text_module_selection, wait: 3) - expect(page).to have_css(format(selector_text_module_item, text_module_without_group.id)) - expect(page).to have_no_css(format(selector_text_module_item, text_module_group1.id)) - expect(page).to have_css(format(selector_text_module_item, text_module_group2.id)) + expect(page).to have_selector(:text_module, text_module_without_group.id) + expect(page).to have_no_selector(:text_module, text_module_group1.id) + expect(page).to have_selector(:text_module, text_module_group2.id) end end end