Skip to content

Commit 9706b5a

Browse files
authored
Merge pull request #217 from fac/custom-save-path-0.14.3
Support custom save_path option
2 parents cb4d633 + 03906ed commit 9706b5a

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

lib/capybara/cuprite/driver.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ def initialize(app, options = {})
3232

3333
@screen_size = @options.delete(:screen_size)
3434
@screen_size ||= DEFAULT_MAXIMIZE_SCREEN_SIZE
35-
36-
@options[:save_path] = File.expand_path(Capybara.save_path) if Capybara.save_path
35+
@options[:save_path] ||= File.expand_path(Capybara.save_path) if Capybara.save_path
3736

3837
ENV["FERRUM_DEBUG"] = "true" if ENV["CUPRITE_DEBUG"]
3938

spec/lib/driver_spec.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# frozen_string_literal: true
2+
3+
describe Capybara::Cuprite::Driver do
4+
describe "save_path configuration" do
5+
it "defaults to the Capybara save path" do
6+
driver = with_capybara_save_path("/tmp/capybara-save-path") do
7+
described_class.new(nil)
8+
end
9+
10+
expect(driver.browser.options.to_h).to include(save_path: "/tmp/capybara-save-path")
11+
end
12+
13+
it "allows a custom path to be specified" do
14+
custom_path = Dir.mktmpdir
15+
16+
driver = with_capybara_save_path("/tmp/capybara-save-path") do
17+
described_class.new(nil, { save_path: custom_path })
18+
end
19+
20+
expect(driver.browser.options.to_h).to include(save_path: custom_path)
21+
end
22+
end
23+
24+
private
25+
26+
def with_capybara_save_path(path)
27+
original_capybara_save_path = Capybara.save_path
28+
Capybara.save_path = path
29+
yield
30+
ensure
31+
Capybara.save_path = original_capybara_save_path
32+
end
33+
end

0 commit comments

Comments
 (0)