grell 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/grell/page.rb +16 -0
- data/lib/grell/rawpage.rb +14 -0
- data/lib/grell/version.rb +1 -1
- data/spec/lib/page_spec.rb +39 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61bf72903f19172767e0702e86b81539d5da4b7d
|
4
|
+
data.tar.gz: 5fcc616f9002fc46dbecc3070b63f4ba58acae49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c74181c32f2aab10655dff0023a271e47671b11aa2b81095a384ff2fb75425621ef17e3b0eb92d16d45a2575b55f1a676983c09584e6f557de2cae2a2e3f534b
|
7
|
+
data.tar.gz: cf699863fd4ddf88e83db631d2346ef83c6cb56d4d717eefe2852da8a7b16933b1e07884caf928e6ede6e6db097ef40c68e403edf540c44f414687c8d55ab40a
|
data/CHANGELOG.md
CHANGED
data/lib/grell/page.rb
CHANGED
@@ -48,10 +48,26 @@ module Grell
|
|
48
48
|
unavailable_page(404, e)
|
49
49
|
end
|
50
50
|
|
51
|
+
# Number of times we have retried the current page
|
51
52
|
def retries
|
52
53
|
[@times_visited -1, 0].max
|
53
54
|
end
|
54
55
|
|
56
|
+
# The current URL, this may be different from the URL we asked for if there was some redirect
|
57
|
+
def current_url
|
58
|
+
@rawpage.current_url
|
59
|
+
end
|
60
|
+
|
61
|
+
# True if we followed a redirect to get the current contents
|
62
|
+
def followed_redirects?
|
63
|
+
current_url != @url
|
64
|
+
end
|
65
|
+
|
66
|
+
# True if there page responded with an error
|
67
|
+
def error?
|
68
|
+
!!(status.to_s =~ /[4|5]\d\d/)
|
69
|
+
end
|
70
|
+
|
55
71
|
private
|
56
72
|
def unavailable_page(status, exception)
|
57
73
|
Grell.logger.warn "The page with the URL #{@url} was not available. Exception #{exception}"
|
data/lib/grell/rawpage.rb
CHANGED
@@ -5,6 +5,7 @@ module Grell
|
|
5
5
|
|
6
6
|
def navigate(url)
|
7
7
|
visit(url)
|
8
|
+
follow_redirects!
|
8
9
|
end
|
9
10
|
|
10
11
|
def headers
|
@@ -33,5 +34,18 @@ module Grell
|
|
33
34
|
def has_selector?(selector)
|
34
35
|
page.has_selector?(selector)
|
35
36
|
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def follow_redirects!
|
41
|
+
# Phantom is very weird, it will follow a redirect to provide the correct body but will not fill the
|
42
|
+
# status and the headers, if we are in that situation, revisit the page with the correct url this time.
|
43
|
+
# Note that we will still fail if we have more than 5 redirects on a row
|
44
|
+
redirects = 0
|
45
|
+
while(page.status_code == nil && redirects < 5)
|
46
|
+
visit( CGI.unescape(page.current_url))
|
47
|
+
redirects = redirects + 1
|
48
|
+
end
|
49
|
+
end
|
36
50
|
end
|
37
51
|
end
|
data/lib/grell/version.rb
CHANGED
data/spec/lib/page_spec.rb
CHANGED
@@ -86,7 +86,7 @@ RSpec.describe Grell::Page do
|
|
86
86
|
end
|
87
87
|
|
88
88
|
shared_examples_for 'an errored grell page' do
|
89
|
-
it 'returns empty status 404 page after navigating' do
|
89
|
+
it 'returns empty status 404 page after navigating' do
|
90
90
|
expect(page.status).to eq(404)
|
91
91
|
expect(page.links).to eq([])
|
92
92
|
expect(page.headers).to eq(headers)
|
@@ -94,7 +94,7 @@ RSpec.describe Grell::Page do
|
|
94
94
|
expect(page.has_selector?('html')).to eq(false)
|
95
95
|
expect(page).to be_visited
|
96
96
|
expect(page.timestamp).to eq(now)
|
97
|
-
|
97
|
+
expect(page.error?).to eq(true)
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
@@ -153,6 +153,30 @@ RSpec.describe Grell::Page do
|
|
153
153
|
|
154
154
|
end
|
155
155
|
|
156
|
+
context 'navigating to an URL with redirects, follows them transparently' do
|
157
|
+
let(:visited) {true}
|
158
|
+
let(:status) { 200}
|
159
|
+
let(:body) {'<html><head></head><body>nothing cool</body></html>'}
|
160
|
+
let(:links) {[]}
|
161
|
+
let(:expected_headers) {returned_headers}
|
162
|
+
let(:real_url) {'http://example.com/other'}
|
163
|
+
before do
|
164
|
+
proxy.stub(url).and_return(:redirect_to => real_url)
|
165
|
+
proxy.stub(real_url).and_return(body: body, code: status, headers: returned_headers.dup)
|
166
|
+
page.navigate
|
167
|
+
end
|
168
|
+
it_behaves_like 'a grell page'
|
169
|
+
|
170
|
+
it 'followed_redirects? is true' do
|
171
|
+
expect(page.followed_redirects?).to eq(true)
|
172
|
+
end
|
173
|
+
|
174
|
+
it 'current_url match the url we were redirected to' do
|
175
|
+
expect(page.current_url).to eq(real_url)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
#Here also add examples that may happen for almost all pages (no errors, no redirects)
|
156
180
|
context 'navigating to the URL we get page with no links' do
|
157
181
|
let(:visited) {true}
|
158
182
|
let(:status) { 200}
|
@@ -166,6 +190,18 @@ RSpec.describe Grell::Page do
|
|
166
190
|
end
|
167
191
|
|
168
192
|
it_behaves_like 'a grell page'
|
193
|
+
|
194
|
+
it 'followed_redirects is false' do
|
195
|
+
expect(page.followed_redirects?).to eq(false)
|
196
|
+
end
|
197
|
+
|
198
|
+
it 'current_url is url' do
|
199
|
+
expect(page.current_url).to eq(url)
|
200
|
+
end
|
201
|
+
|
202
|
+
it 'does not have errors' do
|
203
|
+
expect(page.error?).to eq(false)
|
204
|
+
end
|
169
205
|
end
|
170
206
|
|
171
207
|
context 'navigating to the URL we get page with links using a elements' do
|
@@ -238,7 +274,7 @@ RSpec.describe Grell::Page do
|
|
238
274
|
</body></html>"
|
239
275
|
end
|
240
276
|
let(:links) do
|
241
|
-
["http://www.example.com/trusmis.html", "http://www.example.com/help.html",
|
277
|
+
["http://www.example.com/trusmis.html", "http://www.example.com/help.html",
|
242
278
|
'http://www.example.com/more_help.html', 'http://www.example.com/help_me.html'
|
243
279
|
]
|
244
280
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grell
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jordi Polo Carres
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capybara
|