From 48b5812a449e5d090d3529e3fbfb679cee7de5da Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Mon, 15 Aug 2016 20:57:28 -0700 Subject: [PATCH 1/4] Make Capybara finders less susceptible to timing issues --- spec/features/merge_requests/diff_notes_spec.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/features/merge_requests/diff_notes_spec.rb b/spec/features/merge_requests/diff_notes_spec.rb index 12e89742b79f..4b3de1d8f893 100644 --- a/spec/features/merge_requests/diff_notes_spec.rb +++ b/spec/features/merge_requests/diff_notes_spec.rb @@ -129,11 +129,13 @@ def get_line_components(line_holder, diff_side = nil) end def get_inline_line_components(line_holder) - { content: line_holder.first('.line_content'), num: line_holder.first('.diff-line-num') } + { content: line_holder.find('.line_content', match: :first), num: line_holder.find('.diff-line-num', match: :first) } end def get_parallel_line_components(line_holder, diff_side = nil) side_index = diff_side == 'left' ? 0 : 1 + find('.line_content', match: :first) + find('.diff-line-num', match: :first) { content: line_holder.all('.line_content')[side_index], num: line_holder.all('.diff-line-num')[side_index] } end -- GitLab From f62fb6b7d5aa2579e747454f89bce9654e0a0c52 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Mon, 15 Aug 2016 22:11:26 -0700 Subject: [PATCH 2/4] Improve specificity of Capybara find selector --- spec/features/merge_requests/diff_notes_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/features/merge_requests/diff_notes_spec.rb b/spec/features/merge_requests/diff_notes_spec.rb index 4b3de1d8f893..7f6c878ab56a 100644 --- a/spec/features/merge_requests/diff_notes_spec.rb +++ b/spec/features/merge_requests/diff_notes_spec.rb @@ -134,8 +134,8 @@ def get_inline_line_components(line_holder) def get_parallel_line_components(line_holder, diff_side = nil) side_index = diff_side == 'left' ? 0 : 1 - find('.line_content', match: :first) - find('.diff-line-num', match: :first) + line_holder.find('.line_content', match: :first) + line_holder.find('.diff-line-num', match: :first) { content: line_holder.all('.line_content')[side_index], num: line_holder.all('.diff-line-num')[side_index] } end -- GitLab From f18f513dcb5ec9619ed44b041bf05e1d426edad2 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Tue, 16 Aug 2016 06:01:05 -0700 Subject: [PATCH 3/4] Prefer `find(..., match: :first)` to `first` --- spec/features/merge_requests/diff_notes_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/spec/features/merge_requests/diff_notes_spec.rb b/spec/features/merge_requests/diff_notes_spec.rb index 7f6c878ab56a..78760e4afc5b 100644 --- a/spec/features/merge_requests/diff_notes_spec.rb +++ b/spec/features/merge_requests/diff_notes_spec.rb @@ -53,21 +53,21 @@ context 'with an unchanged line on the left and an unchanged line on the right' do it 'should allow commenting on the left side' do - should_allow_commenting(first('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7"]').find(:xpath, '..'), 'left') + should_allow_commenting(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7"]', match: :first).find(:xpath, '..'), 'left') end it 'should allow commenting on the right side' do - should_allow_commenting(first('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7"]').find(:xpath, '..'), 'right') + should_allow_commenting(find('[id="2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7"]', match: :first).find(:xpath, '..'), 'right') end end context 'with a match line' do it 'should not allow commenting on the left side' do - should_not_allow_commenting(first('.match').find(:xpath, '..'), 'left') + should_not_allow_commenting(find('.match', match: :first).find(:xpath, '..'), 'left') end it 'should not allow commenting on the right side' do - should_not_allow_commenting(first('.match').find(:xpath, '..'), 'right') + should_not_allow_commenting(find('.match', match: :first).find(:xpath, '..'), 'right') end end end @@ -98,7 +98,7 @@ context 'with a match line' do it 'should not allow commenting' do - should_not_allow_commenting(first('.match')) + should_not_allow_commenting(find('.match', match: :first)) end end end -- GitLab From a787b92f18bde0bac40c2d10b16dab3d5f6e2107 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Tue, 16 Aug 2016 07:17:41 -0700 Subject: [PATCH 4/4] Prefer `find(:xpath, ...)` to `expect(...).to have_xpath` --- spec/features/merge_requests/diff_notes_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/merge_requests/diff_notes_spec.rb b/spec/features/merge_requests/diff_notes_spec.rb index 78760e4afc5b..daf629ee04d0 100644 --- a/spec/features/merge_requests/diff_notes_spec.rb +++ b/spec/features/merge_requests/diff_notes_spec.rb @@ -141,7 +141,7 @@ def get_parallel_line_components(line_holder, diff_side = nil) def comment_on_line(line_holder, line) line[:num].find(comment_button_class).trigger 'click' - expect(line_holder).to have_xpath notes_holder_input_xpath + line_holder.find(:xpath, notes_holder_input_xpath) notes_holder_input = line_holder.find(:xpath, notes_holder_input_xpath) expect(notes_holder_input[:class]).to include(notes_holder_input_class) -- GitLab