forked from excid3/ferrum_pdf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathferrum_pdf_test.rb
More file actions
67 lines (51 loc) · 1.8 KB
/
ferrum_pdf_test.rb
File metadata and controls
67 lines (51 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
require "test_helper"
class FerrumPdfTest < ActiveSupport::TestCase
def teardown
# Reset browser state after each test to avoid flaky behavior
FerrumPdf.browser = nil
end
test "it has a version number" do
assert FerrumPdf::VERSION
end
test "setting new browser replaces previous browser" do
first_browser = Ferrum::Browser.new
first_pid = first_browser.process.pid
FerrumPdf.browser = first_browser
second_browser = Ferrum::Browser.new
second_pid = second_browser.process.pid
FerrumPdf.browser = second_browser
# First browser should be shut down
assert_nil first_browser.process
# Second browser should have a different Process ID
assert_not_equal first_pid, second_pid
FerrumPdf.with_browser do |yielded_browser|
assert_same second_browser, yielded_browser
end
end
test "auto-creates browser when none is set" do
FerrumPdf.browser = nil
FerrumPdf.with_browser do |browser|
assert_instance_of Ferrum::Browser, browser
assert browser.client.present?
end
end
test "auto-created browser uses config settings" do
original_config = FerrumPdf.config.dup
FerrumPdf.config.window_size = [ 800, 600 ]
FerrumPdf.browser = nil
FerrumPdf.with_browser do |browser|
assert_instance_of Ferrum::Browser, browser
assert_equal [ 800, 600 ], browser.options.window_size
end
ensure
FerrumPdf.config.replace(original_config)
end
test "reuses same browser instance across multiple with_browser calls" do
FerrumPdf.browser = nil
first_call_browser = nil
second_call_browser = nil
FerrumPdf.with_browser { |browser| first_call_browser = browser }
FerrumPdf.with_browser { |browser| second_call_browser = browser }
assert_same first_call_browser, second_call_browser
end
end