1+ # frozen_string_literal: true
2+
13require 'spec_helper'
24require 'active_model'
35
@@ -13,21 +15,21 @@ class Record
1315 end
1416
1517 context '[basic]' do
16- it "should allow nil if :allow_nil is set" do
18+ it "allows nil if :allow_nil is set" do
1719 @validator = described_class . new ( attributes : %i[ field ] , allow_nil : true )
1820 @validator . validate_each ( @record , :field , nil )
1921 expect ( @record . errors ) . to be_empty
2022 end
2123
22- it "should allow \" \" if :allow_blank is set" do
24+ it "allows '' if :allow_blank is set" do
2325 @validator = described_class . new ( attributes : %i[ field ] , allow_blank : true )
2426 @validator . validate_each ( @record , :field , "" )
2527 expect ( @record . errors ) . to be_empty
2628 end
2729 end
2830
2931 context '[format]' do
30- it "should only allow HTTP URLs if :scheme is set to 'http'" do
32+ it "only allows HTTP URLs if :scheme is set to 'http'" do
3133 @validator = described_class . new ( attributes : %i[ field ] , scheme : 'http' )
3234 @validator . validate_each ( @record , :field , 'http://www.apple.com' )
3335 expect ( @record . errors ) . to be_empty
@@ -36,7 +38,7 @@ class Record
3638 expect ( @record . errors [ :field ] . first ) . to include ( 'invalid_url' )
3739 end
3840
39- it "should only allow HTTP and HTTPS URLs if :scheme is set to %w(http https)" do
41+ it "onlies allow HTTP and HTTPS URLs if :scheme is set to %w(http https)" do
4042 @validator = described_class . new ( attributes : %i[ field ] , scheme : %w[ http https ] )
4143 @validator . validate_each ( @record , :field , 'http://www.apple.com' )
4244 expect ( @record . errors ) . to be_empty
@@ -47,14 +49,14 @@ class Record
4749 expect ( @record . errors [ :field ] . first ) . to include ( 'invalid_url' )
4850 end
4951
50- it "should try a default scheme if :default_scheme is set" do
52+ it "tries a default scheme if :default_scheme is set" do
5153 @validator = described_class . new ( attributes : %i[ field ] , scheme : 'http' , default_scheme : 'http' )
5254 @validator . validate_each ( @record , :field , 'www.apple.com' )
5355 expect ( @record . errors ) . to be_empty
5456 end
5557
5658 context '[HTTP(S)]' do
57- it "should not allow garbage URLs that still somehow pass the ridiculously open-ended RFC" do
59+ it "does not allow garbage URLs that still somehow pass the ridiculously open-ended RFC" do
5860 @validator = described_class . new ( attributes : %i[ field ] )
5961
6062 %w[
@@ -70,7 +72,7 @@ class Record
7072 end
7173 end
7274
73- it "should not allow invalid scheme formats" do
75+ it "does not allow invalid scheme formats" do
7476 @validator = described_class . new ( attributes : %i[ field ] )
7577 @validator . validate_each ( @record , :field , ' https://www.apple.com' )
7678 expect ( @record . errors [ :field ] . first ) . to include ( 'invalid_url' )
@@ -80,7 +82,7 @@ class Record
8082
8183 context '[accessibility]' do
8284 context '[:check_host]' do
83- it "should only validate if the host is accessible when :check_host is set" do
85+ it "only validates if the host is accessible when :check_host is set" do
8486 @validator = described_class . new ( attributes : %i[ field ] )
8587 @validator . validate_each ( @record , :field , 'http://www.invalid.tld' )
8688 expect ( @record . errors ) . to be_empty
@@ -90,25 +92,25 @@ class Record
9092 expect ( @record . errors [ :field ] . first ) . to include ( 'url_not_accessible' )
9193 end
9294
93- it "should not perform the accessibility check if :check_host is set to 'http' and the URL scheme is not HTTP" do
95+ it "does not perform the accessibility check if :check_host is set to 'http' and the URL scheme is not HTTP" do
9496 @validator = described_class . new ( attributes : %i[ field ] , check_host : 'http' )
9597 @validator . validate_each ( @record , :field , 'https://www.invalid.tld' )
9698 expect ( @record . errors ) . to be_empty
9799 end
98100
99- it "should only validate if the host is accessible when :check_host is set to 'http' and the URL scheme is HTTP" do
101+ it "only validates if the host is accessible when :check_host is set to 'http' and the URL scheme is HTTP" do
100102 @validator = described_class . new ( attributes : %i[ field ] , check_host : 'http' )
101103 @validator . validate_each ( @record , :field , 'http://www.invalid.tld' )
102104 expect ( @record . errors [ :field ] . first ) . to include ( 'url_not_accessible' )
103105 end
104106
105- it "should not perform the accessibility check if :check_host is set to %w(http https) and the URL scheme is not HTTP(S)" do
107+ it "does not perform the accessibility check if :check_host is set to %w(http https) and the URL scheme is not HTTP(S)" do
106108 @validator = described_class . new ( attributes : %i[ field ] , check_host : %w[ http https ] , scheme : %w[ ftp http https ] )
107109 @validator . validate_each ( @record , :field , 'ftp://www.invalid.tld' )
108110 expect ( @record . errors ) . to be_empty
109111 end
110112
111- it "should only validate if the host is accessible when :check_host is set to %w(http https) and the URL scheme is HTTP(S)" do
113+ it "only validates if the host is accessible when :check_host is set to %w(http https) and the URL scheme is HTTP(S)" do
112114 @validator = described_class . new ( attributes : %i[ field ] , check_host : %w[ http https ] )
113115 @validator . validate_each ( @record , :field , 'http://www.invalid.tld' )
114116 expect ( @record . errors [ :field ] . first ) . to include ( 'url_not_accessible' )
@@ -118,15 +120,15 @@ class Record
118120 expect ( @record . errors [ :field ] . first ) . to include ( 'url_not_accessible' )
119121 end
120122
121- it "should only validate the host" do
123+ it "only validates the host" do
122124 @validator = described_class . new ( attributes : %i[ field ] , check_host : true )
123125 @validator . validate_each ( @record , :field , 'http://www.google.com/sdgsdgf' )
124126 expect ( @record . errors ) . to be_empty
125127 end
126128 end
127129
128130 context '[:check_path]' do
129- it "should not validate if the response code is equal to the Integer value of this option" do
131+ it "does not validate if the response code is equal to the Integer value of this option" do
130132 @validator = described_class . new ( attributes : %i[ field ] , check_path : 404 )
131133 @validator . validate_each ( @record , :field , 'http://www.google.com/sdgsdgf' )
132134 expect ( @record . errors [ :field ] . first ) . to include ( 'url_invalid_response' )
@@ -138,7 +140,7 @@ class Record
138140 expect ( @record . errors [ :field ] ) . to be_empty
139141 end
140142
141- it "should not validate if the response code is equal to the Symbol value of this option" do
143+ it "does not validate if the response code is equal to the Symbol value of this option" do
142144 @validator = described_class . new ( attributes : %i[ field ] , check_path : :not_found )
143145 @validator . validate_each ( @record , :field , 'http://www.google.com/sdgsdgf' )
144146 expect ( @record . errors [ :field ] . first ) . to include ( 'url_invalid_response' )
@@ -150,7 +152,7 @@ class Record
150152 expect ( @record . errors [ :field ] ) . to be_empty
151153 end
152154
153- it "should not validate if the response code is within the Range value of this option" do
155+ it "does not validate if the response code is within the Range value of this option" do
154156 @validator = described_class . new ( attributes : %i[ field ] , check_path : 400 ..499 )
155157 @validator . validate_each ( @record , :field , 'http://www.google.com/sdgsdgf' )
156158 expect ( @record . errors [ :field ] . first ) . to include ( 'url_invalid_response' )
@@ -162,7 +164,7 @@ class Record
162164 expect ( @record . errors [ :field ] ) . to be_empty
163165 end
164166
165- it "should not validate if the response code is equal to the Integer value contained in the Array value of this option" do
167+ it "does not validate if the response code is equal to the Integer value contained in the Array value of this option" do
166168 @validator = described_class . new ( attributes : %i[ field ] , check_path : [ 404 , 405 ] )
167169 @validator . validate_each ( @record , :field , 'http://www.google.com/sdgsdgf' )
168170 expect ( @record . errors [ :field ] . first ) . to include ( 'url_invalid_response' )
@@ -174,7 +176,7 @@ class Record
174176 expect ( @record . errors [ :field ] ) . to be_empty
175177 end
176178
177- it "should not validate if the response code is equal to the Symbol value contained in the Array value of this option" do
179+ it "does not validate if the response code is equal to the Symbol value contained in the Array value of this option" do
178180 @validator = described_class . new ( attributes : %i[ field ] , check_path : %i[ not_found unauthorized ] )
179181 @validator . validate_each ( @record , :field , 'http://www.google.com/sdgsdgf' )
180182 expect ( @record . errors [ :field ] . first ) . to include ( 'url_invalid_response' )
@@ -186,7 +188,7 @@ class Record
186188 expect ( @record . errors [ :field ] ) . to be_empty
187189 end
188190
189- it "should not validate if the response code is equal to the Range value contained in the Array value of this option" do
191+ it "does not validate if the response code is equal to the Range value contained in the Array value of this option" do
190192 @validator = described_class . new ( attributes : %i[ field ] , check_path : [ 400 ..499 , 500 ..599 ] )
191193 @validator . validate_each ( @record , :field , 'http://www.google.com/sdgsdgf' )
192194 expect ( @record . errors [ :field ] . first ) . to include ( 'url_invalid_response' )
@@ -198,37 +200,37 @@ class Record
198200 expect ( @record . errors [ :field ] ) . to be_empty
199201 end
200202
201- it "should skip validation by default" do
203+ it "skips validation by default" do
202204 @validator = described_class . new ( attributes : %i[ field ] , check_path : nil )
203205 @validator . validate_each ( @record , :field , 'http://www.google.com/sdgsdgf' )
204206 expect ( @record . errors [ :field ] ) . to be_empty
205207 end
206208
207- it "should not validate 4xx and 5xx response codes if the value is true" do
209+ it "does not validate 4xx and 5xx response codes if the value is true" do
208210 @validator = described_class . new ( attributes : %i[ field ] , check_path : true )
209211 @validator . validate_each ( @record , :field , 'http://www.google.com/sdgsdgf' )
210212 expect ( @record . errors [ :field ] . first ) . to include ( 'url_invalid_response' )
211213 end
212214
213- it "should skip validation for non-HTTP URLs" do
215+ it "skips validation for non-HTTP URLs" do
214216 @validator = described_class . new ( attributes : %i[ field ] , check_path : true , scheme : %w[ ftp http https ] )
215217 @validator . validate_each ( @record , :field , 'ftp://ftp.sdgasdgohaodgh.com/sdgjsdg' )
216218 expect ( @record . errors [ :field ] ) . to be_empty
217219 end
218220 end
219221
220222 context '[:httpi_adapter]' do
221- it "should use the specified HTTPI adapter" do
223+ it "uses the specified HTTPI adapter" do
222224 @validator = described_class . new ( attributes : %i[ field ] , httpi_adapter : :curl , check_host : true )
223225 expect ( HTTPI ) . to receive ( :get ) . once . with ( an_instance_of ( HTTPI ::Request ) , :curl ) . and_return ( false )
224226 @validator . validate_each ( @record , :field , 'http://www.google.com/sdgsdgf' )
225227 end
226228 end
227229
228230 context '[:request_callback]' do
229- it "should be yielded the HTTPI request" do
231+ it "is yielded the HTTPI request" do
230232 called = false
231- @validator = described_class . new ( attributes : %i[ field ] , check_host : true , request_callback : -> ( request ) { called = true ; expect ( request ) . to be_kind_of ( HTTPI ::Request ) } )
233+ @validator = described_class . new ( attributes : %i[ field ] , check_host : true , request_callback : -> ( request ) { called = true ; expect ( request ) . to be_a ( HTTPI ::Request ) } )
232234 @validator . validate_each ( @record , :field , 'http://www.google.com/sdgsdgf' )
233235 expect ( called ) . to be ( true )
234236 end
0 commit comments