From 4c4cd01539c3f65de401e7905720b9ffee9933c4 Mon Sep 17 00:00:00 2001 From: Henning Koch Date: Mon, 8 Jan 2024 20:56:00 +0100 Subject: [PATCH] Fix capybara_lockstep_js not containing configuration (for use without Rails) --- lib/capybara-lockstep/helper.rb | 11 ++++--- spec/lib/capybara-lockstep/helper_spec.rb | 38 +++++++++++++++++++++++ spec/spec_helper.rb | 1 + 3 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 spec/lib/capybara-lockstep/helper_spec.rb diff --git a/lib/capybara-lockstep/helper.rb b/lib/capybara-lockstep/helper.rb index 53a4c6d..db7fa19 100644 --- a/lib/capybara-lockstep/helper.rb +++ b/lib/capybara-lockstep/helper.rb @@ -3,10 +3,10 @@ module Lockstep module Helper JS_PATH = File.expand_path('../helper.js', __FILE__) - JS = IO.read(JS_PATH) + HELPER_JS = IO.read(JS_PATH) - def capybara_lockstep_js - JS + def capybara_lockstep_js(options = {}) + HELPER_JS + capybara_lockstep_config_js(options) end def capybara_lockstep(options = {}) @@ -17,10 +17,11 @@ def capybara_lockstep(options = {}) tag_options[:nonce] = options.fetch(:nonce, true) end - js = capybara_lockstep_js + capybara_lockstep_config_js(options) - javascript_tag(js, tag_options) + javascript_tag(capybara_lockstep_js(options), tag_options) end + private + def capybara_lockstep_config_js(options = {}) js = '' diff --git a/spec/lib/capybara-lockstep/helper_spec.rb b/spec/lib/capybara-lockstep/helper_spec.rb new file mode 100644 index 0000000..6750597 --- /dev/null +++ b/spec/lib/capybara-lockstep/helper_spec.rb @@ -0,0 +1,38 @@ +module Capybara + module Lockstep + describe Helper do + + subject do + object = Object.new + object.extend(Helper) + object + end + + describe '#capybara_lockstep_js' do + + it 'returns the CapybaraLockstep helper' do + expect(subject.capybara_lockstep_js).to include('window.CapybaraLockstep =') + end + + it 'configures a custom #wait_tasks setting' do + expect(subject.capybara_lockstep_js).to_not include('CapybaraLockstep.waitTasks') + + Lockstep.wait_tasks = 99 + + expect(subject.capybara_lockstep_js).to include('CapybaraLockstep.waitTasks = 99') + end + + it 'configures a custom #debug setting' do + expect(subject.capybara_lockstep_js).to_not include('CapybaraLockstep.debug') + + Lockstep.debug = true + + expect(subject.capybara_lockstep_js).to include('CapybaraLockstep.debug = true') + + end + + end + + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2050f40..a6e4318 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -40,6 +40,7 @@ RSpec.configure do |config| config.before(:each) do + Capybara::Lockstep.wait_tasks = nil Capybara::Lockstep.timeout = 5 Capybara::Lockstep.debug = false Capybara::Lockstep.mode = :auto