capybara-screenshot 1.0.16 → 1.0.17

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9afdd9d33462cf19d2cd005844e6790171b23073
4
- data.tar.gz: ac0e7b147e924204f72657cbdfd92b96e2b912cf
3
+ metadata.gz: 0ab9945e12e4f0aecbd988f805e0823c97506dda
4
+ data.tar.gz: 3114b7782691089bf0226c05473be33b14f148c6
5
5
  SHA512:
6
- metadata.gz: 8966719fe9c36701a98e20c72f92d00be96df39374e871ceb18de0aaf91284c40a9c1bedf714186e0c6967da75df8e477f247bfd0201229c1fd32ce4f57489c4
7
- data.tar.gz: 936a36d7efd3fb8e50a203e3130e0575eb0ce5b99c24ae85e56eede5f19faf5b32cb01a42aa997151ebf00971fe85bed1b78734fed5d27116748e1ca9ab7dc10
6
+ metadata.gz: 7fa7efb0ec06499bd65217077de23ecd8f63a89c7562f08187d2525ae3b9e5b873d8c769b181232aa433bf2749dd109a1421b045bed8cfd5fda6b44204ead894
7
+ data.tar.gz: 2fdd28b3be83176029cdb4461c2891412571469bbde6634a0ab1f6b3cff8bee767e2053a7b595b7769a2cff3df36a618f12f4100ca5adfc35ac7ce3b3311cb3d
@@ -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
- # if current_path empty then nothing to screen shot as browser has not loaded any URL
30
- return if page.current_path.to_s.empty?
31
-
32
- save_html if @html_save
33
- save_screenshot
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
@@ -1,5 +1,5 @@
1
1
  module Capybara
2
2
  module Screenshot
3
- VERSION = '1.0.16'
3
+ VERSION = '1.0.17'
4
4
  end
5
5
  end
@@ -112,25 +112,87 @@ describe Capybara::Screenshot::Saver do
112
112
  expect(saver).to_not be_html_saved
113
113
  end
114
114
 
115
- it 'does not save if current_path is empty' do
116
- allow(page_mock).to receive(:current_path).and_return(nil)
117
- expect(capybara_mock).to_not receive(:save_page)
118
- expect(driver_mock).to_not receive(:render)
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
- saver.save
121
- expect(saver).to_not be_screenshot_saved
122
- expect(saver).to_not be_html_saved
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 saving a screenshot fails' do
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
- expect(capybara_mock).to receive(:save_page).and_raise
193
+ allow(page_mock).to receive(:current_path).and_raise
130
194
 
131
- expect {
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.16
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-12 00:00:00.000000000 Z
11
+ date: 2017-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capybara