Skip to content

Commit

Permalink
Add unit tests for new config functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
luke-hill committed Jun 5, 2019
1 parent df079b3 commit af0417b
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 17 deletions.
4 changes: 1 addition & 3 deletions lib/cucumber/glue/registry_and_more.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ def load_code_file(code_file)

# This will cause self.add_step_definition, self.add_hook, and self.define_parameter_type to be called from Glue::Dsl

load_files_once = @configuration.only_load_files_once || Cucumber.only_load_files_once

if load_files_once
if Cucumber.only_load_files_once
require File.expand_path(code_file)
else
load File.expand_path(code_file)
Expand Down
96 changes: 82 additions & 14 deletions spec/cucumber/glue/registry_and_more_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,97 @@ def a_file_called(name)
end
end

it 're-loads the file when called multiple times' do
a_file_called('tmp.rb') do
'$foo = 1'
context 'by default' do
before(:each) { $foo = nil }

it 're-loads the file when called multiple times' do
a_file_called('tmp.rb') do
'$foo = 1'
end

registry.load_code_file('tmp.rb')
expect($foo).to eq 1

a_file_called('tmp.rb') do
'$foo = 2'
end

registry.load_code_file('tmp.rb')
expect($foo).to eq 2
end

registry.load_code_file('tmp.rb')
expect($foo).to eq 1
it 'only loads ruby files' do
a_file_called('docs.md') do
'$foo = 1'
end

a_file_called('tmp.rb') do
'$foo = 2'
registry.load_code_file('docs.md')
expect($foo).to be nil
end
end

registry.load_code_file('tmp.rb')
expect($foo).to eq 2
context 'With `only_load_files_once` set to false' do
before(:each) do
allow(Cucumber).to receive(:only_load_files_once).and_return(false)
$foo = nil
end

it 're-loads the file when called multiple times' do
a_file_called('tmp.rb') do
'$foo = 1'
end

registry.load_code_file('tmp.rb')
expect($foo).to eq 1

a_file_called('tmp.rb') do
'$foo = 2'
end

registry.load_code_file('tmp.rb')
expect($foo).to eq 2
end

it 'only loads ruby files' do
a_file_called('docs.md') do
'$foo = 1'
end

registry.load_code_file('docs.md')
expect($foo).to be nil
end
end

it 'only loads ruby files' do
a_file_called('docs.md') do
'$foo = 1'
context 'With `only_load_files_once` set to true' do
before(:each) do
allow(Cucumber).to receive(:only_load_files_once).and_return(true)
$foo = nil
end

it 'does not re-load the file when called multiple times' do
a_file_called('tmp.rb') do
'$foo = 1'
end

registry.load_code_file('tmp.rb')
expect($foo).to eq 1

a_file_called('tmp.rb') do
'$foo = 2'
end

registry.load_code_file('tmp.rb')
expect($foo).to eq 1
end

registry.load_code_file('docs.md')
expect($foo).to be nil
it 'only loads ruby files' do
a_file_called('docs.md') do
'$foo = 1'
end

registry.load_code_file('docs.md')
expect($foo).to be nil
end
end
# rubocop:enable Style/GlobalVars
end
Expand Down

0 comments on commit af0417b

Please sign in to comment.