File tree Expand file tree Collapse file tree 3 files changed +20
-1
lines changed Expand file tree Collapse file tree 3 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -183,6 +183,7 @@ Ferrum::Browser.new(options)
183
183
than this will cause a ` Ferrum::DeadBrowserError ` .
184
184
* ` :proxy ` (Hash) - Specify proxy settings, [ read more] ( https://github.com/rubycdp/ferrum#proxy )
185
185
* ` :save_path ` (String) - Path to save attachments with [ Content-Disposition] ( https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition ) header.
186
+ * ` :env ` (Hash) - Environment variables you'd like to pass through to the process
186
187
187
188
188
189
## Navigation
Original file line number Diff line number Diff line change @@ -73,6 +73,7 @@ def initialize(options)
73
73
74
74
@logger = options [ :logger ]
75
75
@process_timeout = options . fetch ( :process_timeout , PROCESS_TIMEOUT )
76
+ @env = Hash ( options [ :env ] )
76
77
77
78
tmpdir = Dir . mktmpdir ( "ferrum_user_data_dir_" )
78
79
ObjectSpace . define_finalizer ( self , self . class . directory_remover ( tmpdir ) )
@@ -95,7 +96,8 @@ def start
95
96
ObjectSpace . define_finalizer ( self , self . class . process_killer ( @xvfb . pid ) )
96
97
end
97
98
98
- @pid = ::Process . spawn ( Hash ( @xvfb &.to_env ) , *@command . to_a , process_options )
99
+ env = Hash ( @xvfb &.to_env ) . merge ( @env )
100
+ @pid = ::Process . spawn ( env , *@command . to_a , process_options )
99
101
ObjectSpace . define_finalizer ( self , self . class . process_killer ( @pid ) )
100
102
101
103
parse_ws_url ( read_io , @process_timeout )
Original file line number Diff line number Diff line change @@ -21,6 +21,22 @@ class Browser
21
21
subject . quit
22
22
end
23
23
end
24
+
25
+ context "env variables" do
26
+ subject { Browser . new ( env : { "LD_PRELOAD" => "some.so" } ) }
27
+
28
+ it "passes through env" do
29
+ allow ( ::Process ) . to receive ( :wait ) . and_return ( nil )
30
+ allow ( Client ) . to receive ( :new ) . and_return ( double . as_null_object )
31
+
32
+ allow ( ::Process ) . to receive ( :spawn ) . with ( { "LD_PRELOAD" => "some.so" } , any_args )
33
+
34
+ allow_any_instance_of ( Process ) . to receive ( :parse_ws_url )
35
+
36
+ subject . send ( :start )
37
+ subject . quit
38
+ end
39
+ end
24
40
end
25
41
end
26
42
end
You can’t perform that action at this time.
0 commit comments