forked from rubocop/rubocop
-
Notifications
You must be signed in to change notification settings - Fork 2
/
uri_regexp_spec.rb
100 lines (82 loc) · 3.26 KB
/
uri_regexp_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
95
96
97
98
99
100
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::Lint::UriRegexp do
subject(:cop) { described_class.new(config) }
let(:config) { RuboCop::Config.new }
it 'does not register an offense when using `regexp` without receiver' do
expect_no_offenses(<<~RUBY)
regexp('http://example.com')
RUBY
end
it 'does not register an offense when using `regexp` with variable receiver' do
expect_no_offenses(<<~RUBY)
m.regexp('http://example.com')
RUBY
end
it 'registers an offense and corrects using `URI.regexp` with argument' do
expect_offense(<<~RUBY)
URI.regexp('http://example.com')
^^^^^^ `URI.regexp('http://example.com')` is obsolete and should not be used. Instead, use `URI::DEFAULT_PARSER.make_regexp('http://example.com')`.
RUBY
expect_correction(<<~RUBY)
URI::DEFAULT_PARSER.make_regexp('http://example.com')
RUBY
end
it 'registers an offense and corrects using `::URI.regexp` with argument' do
expect_offense(<<~RUBY)
::URI.regexp('http://example.com')
^^^^^^ `::URI.regexp('http://example.com')` is obsolete and should not be used. Instead, use `::URI::DEFAULT_PARSER.make_regexp('http://example.com')`.
RUBY
expect_correction(<<~RUBY)
::URI::DEFAULT_PARSER.make_regexp('http://example.com')
RUBY
end
it 'registers an offense and corrects using `URI.regexp` without argument' do
expect_offense(<<~RUBY)
URI.regexp
^^^^^^ `URI.regexp` is obsolete and should not be used. Instead, use `URI::DEFAULT_PARSER.make_regexp`.
RUBY
expect_correction(<<~RUBY)
URI::DEFAULT_PARSER.make_regexp
RUBY
end
it 'registers an offense and corrects using `::URI.regexp` ' \
'without argument' do
expect_offense(<<~RUBY)
::URI.regexp
^^^^^^ `::URI.regexp` is obsolete and should not be used. Instead, use `::URI::DEFAULT_PARSER.make_regexp`.
RUBY
expect_correction(<<~RUBY)
::URI::DEFAULT_PARSER.make_regexp
RUBY
end
context 'array argument' do
it 'registers an offense and corrects using `URI.regexp` with '\
'literal arrays' do
expect_offense(<<~RUBY)
URI.regexp(['http', 'https'])
^^^^^^ `URI.regexp(['http', 'https'])` is obsolete and should not be used. Instead, use `URI::DEFAULT_PARSER.make_regexp(['http', 'https'])`.
RUBY
expect_correction(<<~RUBY)
URI::DEFAULT_PARSER.make_regexp(['http', 'https'])
RUBY
end
it 'registers an offense and corrects using `URI.regexp` with %w arrays' do
expect_offense(<<~RUBY)
URI.regexp(%w[http https])
^^^^^^ `URI.regexp(%w[http https])` is obsolete and should not be used. Instead, use `URI::DEFAULT_PARSER.make_regexp(%w[http https])`.
RUBY
expect_correction(<<~RUBY)
URI::DEFAULT_PARSER.make_regexp(%w[http https])
RUBY
end
it 'registers an offense and corrects using `URI.regexp` with %i arrays' do
expect_offense(<<~RUBY)
URI.regexp(%i[http https])
^^^^^^ `URI.regexp(%i[http https])` is obsolete and should not be used. Instead, use `URI::DEFAULT_PARSER.make_regexp(%i[http https])`.
RUBY
expect_correction(<<~RUBY)
URI::DEFAULT_PARSER.make_regexp(%i[http https])
RUBY
end
end
end