/
visibility_matcher_spec.rb
94 lines (83 loc) · 4.16 KB
/
visibility_matcher_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::RSpec::Capybara::VisibilityMatcher do
it 'registers an offense when using `visible: true`' do
expect_offense(<<-RUBY)
expect(page).to have_selector('.my_element', visible: true)
^^^^^^^^^^^^^ Use `:visible` instead of `true`.
RUBY
end
it 'registers an offense when using `visible: false`' do
expect_offense(<<-RUBY)
expect(page).to have_selector('.my_element', visible: false)
^^^^^^^^^^^^^^ Use `:all` or `:hidden` instead of `false`.
RUBY
end
it 'recognizes multiple matchers' do
expect_offense(<<-RUBY)
expect(page).to have_css('.profile', visible: false)
^^^^^^^^^^^^^^ Use `:all` or `:hidden` instead of `false`.
expect(page).to have_xpath('.//profile', visible: false)
^^^^^^^^^^^^^^ Use `:all` or `:hidden` instead of `false`.
expect(page).to have_link('news', visible: false)
^^^^^^^^^^^^^^ Use `:all` or `:hidden` instead of `false`.
expect(page).to have_button('login', visible: false)
^^^^^^^^^^^^^^ Use `:all` or `:hidden` instead of `false`.
expect(page).to have_field('name', visible: false)
^^^^^^^^^^^^^^ Use `:all` or `:hidden` instead of `false`.
expect(page).to have_select('sauce', visible: false)
^^^^^^^^^^^^^^ Use `:all` or `:hidden` instead of `false`.
expect(page).to have_table('arrivals', visible: false)
^^^^^^^^^^^^^^ Use `:all` or `:hidden` instead of `false`.
expect(page).to have_checked_field('cat', visible: false)
^^^^^^^^^^^^^^ Use `:all` or `:hidden` instead of `false`.
expect(page).to have_unchecked_field('cat', visible: false)
^^^^^^^^^^^^^^ Use `:all` or `:hidden` instead of `false`.
expect(page).to have_text('My homepage', visible: false)
^^^^^^^^^^^^^^ Use `:all` or `:hidden` instead of `false`.
expect(page).to have_content('Success', visible: false)
^^^^^^^^^^^^^^ Use `:all` or `:hidden` instead of `false`.
RUBY
end
it 'registers an offense when using a selector`' do
expect_offense(<<-RUBY)
expect(page).to have_selector(:css, '.my_element', visible: false)
^^^^^^^^^^^^^^ Use `:all` or `:hidden` instead of `false`.
RUBY
end
it 'registers an offense when using a using multiple options`' do
expect_offense(<<-RUBY)
expect(page).to have_selector('.my_element', count: 1, visible: false, normalize_ws: true)
^^^^^^^^^^^^^^ Use `:all` or `:hidden` instead of `false`.
RUBY
end
it 'does not register an offense when no options are given`' do
expect_no_offenses(<<~RUBY)
expect(page).to have_selector('.my_element')
RUBY
end
it 'does not register an offense when using `visible: :all`' do
expect_no_offenses(<<~RUBY)
expect(page).to have_selector('.my_element', visible: :all)
RUBY
end
it 'does not register an offense when using `visible: :visible`' do
expect_no_offenses(<<~RUBY)
expect(page).to have_selector('.my_element', visible: :visible)
RUBY
end
it 'does not register an offense when using `visible: :hidden`' do
expect_no_offenses(<<~RUBY)
expect(page).to have_selector('.my_element', visible: :hidden)
RUBY
end
it 'does not register an offense when using other options' do
expect_no_offenses(<<~RUBY)
expect(page).to have_selector('.my_element', normalize_ws: true)
RUBY
end
it 'does not register an offense when using multiple options' do
expect_no_offenses(<<~RUBY)
expect(page).to have_selector('.my_element', count: 1, normalize_ws: true)
RUBY
end
end