Skip to content

Commit bd9a2ca

Browse files
committed
Raise an error if mobile: true is specified along with size
Currently we automatically resize to mobile dimensions if `mobile: true` is specified. This can be misleading if the user also passes `height` and/or `width`, because those would be disregarded. Raising an error makes the behaviour more obvious.
1 parent 1560ecd commit bd9a2ca

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/ferrum/page.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ def set_viewport(width:, height:, scale_factor: 0, mobile: false)
186186
end
187187

188188
def resize(width: nil, height: nil, fullscreen: false, mobile: false)
189+
if mobile && (height != 0 || width != 0)
190+
raise "specifying `mobile: true` causes automatic resizing to mobile dimensions"
191+
end
192+
189193
if fullscreen
190194
width, height = document_size
191195
self.window_bounds = { window_state: "fullscreen" }

spec/page_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,22 @@ def is_mobile?
284284
page.reload
285285
end.to change { body_size }.to(width: 980, height: 2120)
286286
end
287+
288+
context "when a height is passed" do
289+
it "raises an error" do
290+
expect do
291+
page.resize(width: 0, height: 100, mobile: true)
292+
end.to raise_error("specifying `mobile: true` causes automatic resizing to mobile dimensions")
293+
end
294+
end
295+
296+
context "when a width is passed" do
297+
it "raises an error" do
298+
expect do
299+
page.resize(width: 100, height: 0, mobile: true)
300+
end.to raise_error("specifying `mobile: true` causes automatic resizing to mobile dimensions")
301+
end
302+
end
287303
end
288304
end
289305
end

0 commit comments

Comments
 (0)