@@ -8,12 +8,16 @@ module Ferrum
8
8
let ( :content ) { JSON . parse ( File . read ( file_path ) ) }
9
9
let ( :trace_config ) { JSON . parse ( content [ "metadata" ] [ "trace-config" ] ) }
10
10
11
+ after do
12
+ FileUtils . rm_f ( file_path )
13
+ FileUtils . rm_f ( file_path2 )
14
+ FileUtils . rm_f ( file_path3 )
15
+ end
16
+
11
17
it "outputs a trace" do
12
18
page . tracing . record ( path : file_path ) { page . go_to }
13
19
14
20
expect ( File . exist? ( file_path ) ) . to be ( true )
15
- ensure
16
- FileUtils . rm_f ( file_path )
17
21
end
18
22
19
23
it "runs with custom options" do
@@ -29,8 +33,6 @@ module Ferrum
29
33
expect ( trace_config [ "excluded_categories" ] ) . to eq ( [ "*" ] )
30
34
expect ( trace_config [ "included_categories" ] ) . to eq ( [ "disabled-by-default-devtools.timeline" ] )
31
35
expect ( content [ "traceEvents" ] . any? { |o | o [ "cat" ] == "toplevel" } ) . to eq ( false )
32
- ensure
33
- FileUtils . rm_f ( file_path )
34
36
end
35
37
36
38
it "runs with default categories" do
@@ -44,11 +46,9 @@ module Ferrum
44
46
blink.user_timing latencyInfo disabled-by-default-devtools.timeline.stack
45
47
disabled-by-default-v8.cpu_profiler disabled-by-default-v8.cpu_profiler.hires ] )
46
48
expect ( content [ "traceEvents" ] . any? { |o | o [ "cat" ] == "toplevel" } ) . to eq ( true )
47
- ensure
48
- FileUtils . rm_f ( file_path )
49
49
end
50
50
51
- it "throws an exception if tracing is on two pages" do
51
+ it "raises an error when tracing is on two pages" do
52
52
page . tracing . record ( path : file_path ) do
53
53
page . go_to
54
54
@@ -62,6 +62,15 @@ module Ferrum
62
62
expect ( File . exist? ( file_path ) ) . to be ( true )
63
63
end
64
64
65
+ it "raises an error when cannot handle stream" do
66
+ allow ( page . tracing ) . to receive ( :stream_handle ) . and_raise ( "boom" )
67
+ expect do
68
+ page . tracing . record ( path : file_path ) { page . go_to }
69
+ end . to raise_error ( RuntimeError , "boom" )
70
+
71
+ expect ( File . exist? ( file_path ) ) . to be ( false )
72
+ end
73
+
65
74
it "handles tracing complete event once" do
66
75
expect ( page . tracing ) . to receive ( :stream_handle ) . exactly ( 3 ) . times . and_call_original
67
76
@@ -73,10 +82,6 @@ module Ferrum
73
82
74
83
page . tracing . record ( path : file_path3 ) { page . go_to }
75
84
expect ( File . exist? ( file_path3 ) ) . to be ( true )
76
- ensure
77
- FileUtils . rm_f ( file_path )
78
- FileUtils . rm_f ( file_path2 )
79
- FileUtils . rm_f ( file_path3 )
80
85
end
81
86
82
87
it "returns base64 encoded string" do
@@ -101,8 +106,6 @@ module Ferrum
101
106
expect ( File . exist? ( file_path ) ) . to be ( true )
102
107
expect ( trace_config [ "included_categories" ] ) . to include ( "disabled-by-default-devtools.screenshot" )
103
108
expect ( content [ "traceEvents" ] . any? { |o | o [ "name" ] == "Screenshot" } ) . to eq ( true )
104
- ensure
105
- FileUtils . rm_f ( file_path )
106
109
end
107
110
108
111
it "returns a buffer with screenshot data" do
0 commit comments