capybara-screenshot 1.0.16 → 1.0.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/capybara-screenshot/saver.rb +27 -5
- data/lib/capybara-screenshot/version.rb +1 -1
- data/spec/unit/saver_spec.rb +74 -12
- 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: 0ab9945e12e4f0aecbd988f805e0823c97506dda
|
4
|
+
data.tar.gz: 3114b7782691089bf0226c05473be33b14f148c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7fa7efb0ec06499bd65217077de23ecd8f63a89c7562f08187d2525ae3b9e5b873d8c769b181232aa433bf2749dd109a1421b045bed8cfd5fda6b44204ead894
|
7
|
+
data.tar.gz: 2fdd28b3be83176029cdb4461c2891412571469bbde6634a0ab1f6b3cff8bee767e2053a7b595b7769a2cff3df36a618f12f4100ca5adfc35ac7ce3b3311cb3d
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
17 July 2017 - 1.0.16 -> 1.0.17
|
2
|
+
|
3
|
+
* [Better handling of `page.current_path` exceptions for Spinach](https://github.com/mattheworiordan/capybara-screenshot/pull/208)
|
4
|
+
|
1
5
|
12 July 2017 - 1.0.15 -> 1.0.16
|
2
6
|
|
3
7
|
* [Support s3 key name prefixes](https://github.com/mattheworiordan/capybara-screenshot/pull/202)
|
@@ -26,11 +26,23 @@ module Capybara
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def save
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
29
|
+
current_path do |path|
|
30
|
+
if !path.empty?
|
31
|
+
begin
|
32
|
+
save_html if @html_save
|
33
|
+
rescue StandardError => e
|
34
|
+
warn "WARN: HTML source could not be saved. An exception is raised: #{e.inspect}."
|
35
|
+
end
|
36
|
+
|
37
|
+
begin
|
38
|
+
save_screenshot
|
39
|
+
rescue StandardError => e
|
40
|
+
warn "WARN: Screenshot could not be saved. An exception is raised: #{e.inspect}."
|
41
|
+
end
|
42
|
+
else
|
43
|
+
warn 'WARN: Screenshot could not be saved. `page.current_path` is empty.'
|
44
|
+
end
|
45
|
+
end
|
34
46
|
end
|
35
47
|
|
36
48
|
def save_html
|
@@ -97,6 +109,16 @@ module Capybara
|
|
97
109
|
|
98
110
|
private
|
99
111
|
|
112
|
+
def current_path
|
113
|
+
# the current_path may raise error in selenium
|
114
|
+
begin
|
115
|
+
path = page.current_path.to_s
|
116
|
+
rescue StandardError => e
|
117
|
+
warn "WARN: Screenshot could not be saved. `page.current_path` raised exception: #{e.inspect}."
|
118
|
+
end
|
119
|
+
yield path if path
|
120
|
+
end
|
121
|
+
|
100
122
|
def output(message)
|
101
123
|
puts " #{CapybaraScreenshot::Helpers.yellow(message)}"
|
102
124
|
end
|
data/spec/unit/saver_spec.rb
CHANGED
@@ -112,25 +112,87 @@ describe Capybara::Screenshot::Saver do
|
|
112
112
|
expect(saver).to_not be_html_saved
|
113
113
|
end
|
114
114
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
115
|
+
context 'the current_path is empty' do
|
116
|
+
before(:each) do
|
117
|
+
allow(page_mock).to receive(:current_path).and_return(nil)
|
118
|
+
end
|
119
119
|
|
120
|
-
|
121
|
-
|
122
|
-
|
120
|
+
it 'does not save' do
|
121
|
+
expect(capybara_mock).to_not receive(:save_page)
|
122
|
+
expect(driver_mock).to_not receive(:render)
|
123
|
+
|
124
|
+
saver.save
|
125
|
+
expect(saver).to_not be_screenshot_saved
|
126
|
+
expect(saver).to_not be_html_saved
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'prints a warning' do
|
130
|
+
expect(saver).to receive(:warn).with(
|
131
|
+
'WARN: Screenshot could not be saved. `page.current_path` is empty.',
|
132
|
+
)
|
133
|
+
saver.save
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
context 'when save_html raises' do
|
138
|
+
before(:each) do
|
139
|
+
allow(saver).to receive(:save_html).and_raise(NoMethodError.new('some error'))
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'prints warning message' do
|
143
|
+
expect(saver).to receive(:warn).with(
|
144
|
+
'WARN: HTML source could not be saved. An exception is raised: #<NoMethodError: some error>.',
|
145
|
+
)
|
146
|
+
saver.save
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'tries to save screenshot' do
|
150
|
+
expect(saver).to receive(:save_screenshot)
|
151
|
+
saver.save
|
152
|
+
end
|
123
153
|
end
|
124
154
|
|
125
|
-
context 'when
|
155
|
+
context 'when save_screenshot raises' do
|
156
|
+
before(:each) do
|
157
|
+
allow(saver).to receive(:save_screenshot).and_raise(NoMethodError.new('some error'))
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'prints warning message' do
|
161
|
+
expect(saver).to receive(:warn).with(
|
162
|
+
'WARN: Screenshot could not be saved. An exception is raised: #<NoMethodError: some error>.',
|
163
|
+
)
|
164
|
+
saver.save
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'tries to save screenshot' do
|
168
|
+
expect(saver).to receive(:save_html)
|
169
|
+
saver.save
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
context 'when current_path raises' do
|
174
|
+
before(:each) do
|
175
|
+
allow(page_mock).to receive(:current_path).and_raise(NoMethodError.new('some error'))
|
176
|
+
end
|
177
|
+
|
178
|
+
it 'prints warning message' do
|
179
|
+
expect(saver).to receive(:warn).with(
|
180
|
+
'WARN: Screenshot could not be saved. `page.current_path` raised exception: #<NoMethodError: some error>.',
|
181
|
+
)
|
182
|
+
saver.save
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'does not print extra warning message' do
|
186
|
+
expect(saver).not_to receive(:warn).with(/is empty/)
|
187
|
+
saver.save
|
188
|
+
end
|
189
|
+
|
126
190
|
it 'still restores the original value of Capybara.save_and_open_page_path' do
|
127
191
|
Capybara::Screenshot.capybara_tmp_path = 'tmp/bananas'
|
128
192
|
|
129
|
-
|
193
|
+
allow(page_mock).to receive(:current_path).and_raise
|
130
194
|
|
131
|
-
|
132
|
-
saver.save
|
133
|
-
}.to raise_error(RuntimeError)
|
195
|
+
saver.save
|
134
196
|
|
135
197
|
if Capybara.respond_to?(:save_path)
|
136
198
|
expect(Capybara.save_path).to eq('tmp/bananas')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capybara-screenshot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew O'Riordan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07-
|
11
|
+
date: 2017-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capybara
|