Skip to content

Commit

Permalink
Fix capybara_lockstep_js not containing configuration (for use withou…
Browse files Browse the repository at this point in the history
…t Rails)
  • Loading branch information
triskweline committed Jan 8, 2024
1 parent 992964a commit 4c4cd01
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/capybara-lockstep/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {})
Expand All @@ -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 = ''

Expand Down
38 changes: 38 additions & 0 deletions spec/lib/capybara-lockstep/helper_spec.rb
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4c4cd01

Please sign in to comment.