-
-
Notifications
You must be signed in to change notification settings - Fork 277
/
current_path_expectation_spec.rb
82 lines (67 loc) · 3.14 KB
/
current_path_expectation_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
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::RSpec::Capybara::CurrentPathExpectation do
it 'flags violations for `expect(current_path)`' do
expect_offense(<<-RUBY)
expect(current_path).to eq("/callback")
^^^^^^ Do not set an RSpec expectation on `current_path` in Capybara feature specs - instead, use the `have_current_path` matcher on `page`
RUBY
end
it 'flags violations for `expect(page.current_path)`' do
expect_offense(<<-RUBY)
expect(page.current_path).to eq("/callback")
^^^^^^ Do not set an RSpec expectation on `current_path` in Capybara feature specs - instead, use the `have_current_path` matcher on `page`
RUBY
end
it "doesn't flag a violation for other expectations" do
expect_no_offenses(<<-RUBY)
expect(current_user).to eq(user)
RUBY
end
it "doesn't flag a violation for other references to `current_path`" do
expect_no_offenses(<<-RUBY)
current_path = WalkingRoute.last.path
RUBY
end
include_examples 'autocorrect',
'expect(current_path).to eq expected_path',
'expect(page).to have_current_path expected_path, '\
'ignore_query: true'
include_examples 'autocorrect',
'expect(current_path).to eq(expected_path)',
'expect(page).to have_current_path(expected_path, '\
'ignore_query: true)'
include_examples 'autocorrect',
'expect(current_path).to(eq(expected_path))',
'expect(page).to(have_current_path(expected_path, '\
'ignore_query: true))'
include_examples 'autocorrect',
'expect(current_path).to eq(expected_path(f: :b))',
'expect(page).to have_current_path(expected_path(f: :b), '\
'ignore_query: true)'
include_examples 'autocorrect',
'expect(page.current_path).to eq(foo(bar).path)',
'expect(page).to have_current_path(foo(bar).path, '\
'ignore_query: true)'
include_examples 'autocorrect',
'expect(current_path).not_to eq expected_path',
'expect(page).to have_no_current_path expected_path, '\
'ignore_query: true'
include_examples 'autocorrect',
'expect(current_path).to_not eq expected_path',
'expect(page).to have_no_current_path expected_path, '\
'ignore_query: true'
include_examples 'autocorrect',
'expect(page.current_path).to match(/regexp/i)',
'expect(page).to have_current_path(/regexp/i)'
include_examples 'autocorrect',
'expect(page.current_path).to match("string/")',
'expect(page).to have_current_path(/string\//)'
# Unsupported, no change.
include_examples 'autocorrect',
'expect(page.current_path).to match(variable)',
'expect(page.current_path).to match(variable)'
# Unsupported, no change.
include_examples 'autocorrect',
'expect(page.current_path)',
'expect(page.current_path)'
end