-
-
Notifications
You must be signed in to change notification settings - Fork 269
/
http_status_spec.rb
88 lines (72 loc) · 3.14 KB
/
http_status_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
# frozen_string_literal: true
RSpec.describe RuboCop::Cop::RSpec::Rails::HttpStatus, :config do
context 'when EnforcedStyle is `symbolic`' do
let(:cop_config) { { 'EnforcedStyle' => 'symbolic' } }
it 'registers an offense when using numeric value' do
expect_offense(<<-RUBY)
it { is_expected.to have_http_status 200 }
^^^ Prefer `:ok` over `200` to describe HTTP status code.
RUBY
end
it 'does not register an offense when using symbolic value' do
expect_no_offenses(<<-RUBY)
it { is_expected.to have_http_status :ok }
RUBY
end
it 'does not register an offense when using custom HTTP code' do
expect_no_offenses(<<-RUBY)
it { is_expected.to have_http_status 550 }
RUBY
end
include_examples 'autocorrect',
'it { is_expected.to have_http_status 200 }',
'it { is_expected.to have_http_status :ok }'
include_examples 'autocorrect',
'it { is_expected.to have_http_status 404 }',
'it { is_expected.to have_http_status :not_found }'
context 'with parenthesis' do
include_examples 'autocorrect',
'it { is_expected.to have_http_status(200) }',
'it { is_expected.to have_http_status(:ok) }'
include_examples 'autocorrect',
'it { is_expected.to have_http_status(404) }',
'it { is_expected.to have_http_status(:not_found) }'
end
end
context 'when EnforcedStyle is `numeric`' do
let(:cop_config) { { 'EnforcedStyle' => 'numeric' } }
it 'registers an offense when using symbolic value' do
expect_offense(<<-RUBY)
it { is_expected.to have_http_status :ok }
^^^ Prefer `200` over `:ok` to describe HTTP status code.
RUBY
end
it 'does not register an offense when using numeric value' do
expect_no_offenses(<<-RUBY)
it { is_expected.to have_http_status 200 }
RUBY
end
it 'does not register an offense when using allowed symbols' do
expect_no_offenses(<<-RUBY)
it { is_expected.to have_http_status :error }
it { is_expected.to have_http_status :success }
it { is_expected.to have_http_status :missing }
it { is_expected.to have_http_status :redirect }
RUBY
end
include_examples 'autocorrect',
'it { is_expected.to have_http_status :ok }',
'it { is_expected.to have_http_status 200 }'
include_examples 'autocorrect',
'it { is_expected.to have_http_status :not_found }',
'it { is_expected.to have_http_status 404 }'
context 'with parenthesis' do
include_examples 'autocorrect',
'it { is_expected.to have_http_status(:ok) }',
'it { is_expected.to have_http_status(200) }'
include_examples 'autocorrect',
'it { is_expected.to have_http_status(:not_found) }',
'it { is_expected.to have_http_status(404) }'
end
end
end