Skip to content

Commit 79cfae5

Browse files
committed
closes #9
1 parent 658d2ee commit 79cfae5

3 files changed

Lines changed: 16 additions & 3 deletions

File tree

‎lib/hyper-spec.rb‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
config.mock_with :rspec
1818

19+
config.add_setting :debugger_width, default: 0
20+
1921
config.before(:each) do
2022
Hyperloop.class_eval do
2123
def self.on_server?
@@ -30,7 +32,6 @@ def self.on_server?
3032
end if defined?(HyperMesh)
3133
end
3234

33-
3435
config.before(:each, js: true) do
3536
size_window
3637
end
@@ -51,7 +52,9 @@ def self.on_server?
5152
Capybara.default_max_wait_time = 10
5253

5354
Capybara.register_driver :chrome do |app|
54-
Capybara::Selenium::Driver.new(app, browser: :chrome)
55+
options = Selenium::WebDriver::Chrome::Options.new
56+
options.add_arg('auto-open-devtools-for-tabs') unless ENV['NO_DEBUGGER']
57+
Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
5558
end
5659

5760
Capybara.register_driver :firefox do |app|

‎lib/hyper-spec/component_helpers.rb‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ def size_window(width=nil, height=nil)
344344
if portrait
345345
width, height = [height, width]
346346
end
347+
width, height = [width+RSpec.configuration.debugger_width, height+RSpec.configuration.debugger_height]
347348
if page.driver.browser.respond_to?(:manage)
348349
page.driver.browser.manage.window.resize_to(width, height)
349350
elsif page.driver.respond_to?(:resize)

‎lib/hyper-spec/component_test_helpers.rb‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,16 @@ def size_window(width = nil, height = nil)
283283

284284
width, height = [height, width] if portrait
285285

286-
Capybara.current_session.current_window.resize_to(width, height)
286+
loop do
287+
Capybara.current_session.current_window
288+
.resize_to(width + RSpec.configuration.debugger_width, height)
289+
inner_width = evaluate_script('window.innerWidth')
290+
# if we have matched the size then return
291+
return if inner_width == width
292+
# if we are bigger then desired and debugger_width is <= 0 then its as small as possible
293+
return if inner_width > width && RSpec.configuration.debugger_width <= 0
294+
RSpec.configuration.debugger_width += width - inner_width
295+
end
287296
end
288297
end
289298

0 commit comments

Comments
 (0)