Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit ddffa6c
Author: Code Manager <code_manager@agent-694ff4-0>
Date:   Tue Oct 10 13:11:34 2023 +0000

    Fix undefined local 'path'

    Fixed failing tests after refactoring around(:all) into before/after(:all):  ``Failure/Error: FileUtils.rm_f(path)
    NameError:
      undefined local variable or method `path'...``

commit 10821c5
Author: Gavin Didrichsen <[email protected]>
Date:   Thu Oct 5 21:00:17 2023 +0100

    (CAT-1488) - Fix some rubocop warnings

    Signed-off-by: Gavin Didrichsen <[email protected]>

commit 831c41d
Author: Gavin Didrichsen <[email protected]>
Date:   Thu Oct 5 20:34:03 2023 +0100

    (CAT-1488) - Split around(:all) into before/after(:all)

    This fixes duplicate code warnings occurring during the acceptance
    tests.

    Signed-off-by: Gavin Didrichsen <[email protected]>

commit d2cec4b
Author: Gavin Didrichsen <[email protected]>
Date:   Thu Oct 5 20:32:51 2023 +0100

    (CAT-1488) - Refactor duplicated shared examples and context

    This fixes duplicate definition warnings in the acceptance tests.

    Signed-off-by: Gavin Didrichsen <[email protected]>
  • Loading branch information
gavindidrichsen committed Nov 24, 2023
1 parent 4ae0d2c commit ee96de5
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 85 deletions.
41 changes: 0 additions & 41 deletions spec/acceptance/remove_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,6 @@
describe 'pdk remove config' do
include_context 'with a fake TTY'

shared_examples 'a saved configuration file' do |new_content|
it 'saves the setting' do
# Force the command to run if not already
subject.exit_status
expect(File).to exist(ENV.fetch('PDK_ANSWER_FILE', nil))

actual_content = File.open(ENV.fetch('PDK_ANSWER_FILE', nil), 'rb:utf-8', &:read)
expect(actual_content).to eq(new_content)
end
end

shared_examples 'a saved JSON configuration file' do |new_json_content|
it 'saves the setting' do
# Force the command to run if not already
subject.exit_status
expect(File).to exist(ENV.fetch('PDK_ANSWER_FILE', nil))

actual_content_raw = File.open(ENV.fetch('PDK_ANSWER_FILE', nil), 'rb:utf-8', &:read)
actual_json_content = JSON.parse(actual_content_raw)
expect(actual_json_content).to eq(new_json_content)
end
end

RSpec.shared_context 'with a fake answer file' do |initial_content = nil|
before(:all) do
fake_answer_file = Tempfile.new('mock_answers.json')
unless initial_content.nil?
require 'json'
fake_answer_file.binmode
fake_answer_file.write(JSON.pretty_generate(initial_content))
end
fake_answer_file.close
ENV['PDK_ANSWER_FILE'] = fake_answer_file.path
end

after(:all) do
FileUtils.rm_f(ENV.fetch('PDK_ANSWER_FILE', nil)) # Need actual file calls here
ENV.delete('PDK_ANSWER_FILE')
end
end

context 'when run outside of a module' do
describe command('pdk remove config') do
its(:exit_status) { is_expected.not_to eq 0 }
Expand Down
41 changes: 0 additions & 41 deletions spec/acceptance/set_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,6 @@
describe 'pdk set config' do
include_context 'with a fake TTY'

shared_examples 'a saved configuration file' do |new_content|
it 'saves the setting' do
# Force the command to run if not already
subject.exit_status
expect(File).to exist(ENV.fetch('PDK_ANSWER_FILE', nil))

actual_content = File.open(ENV.fetch('PDK_ANSWER_FILE', nil), 'rb:utf-8', &:read)
expect(actual_content).to eq(new_content)
end
end

shared_examples 'a saved JSON configuration file' do |new_json_content|
it 'saves the setting' do
# Force the command to run if not already
subject.exit_status
expect(File).to exist(ENV.fetch('PDK_ANSWER_FILE', nil))

actual_content_raw = File.open(ENV.fetch('PDK_ANSWER_FILE', nil), 'rb:utf-8', &:read)
actual_json_content = JSON.parse(actual_content_raw)
expect(actual_json_content).to eq(new_json_content)
end
end

RSpec.shared_context 'with a fake answer file' do |initial_content = nil|
before(:all) do
fake_answer_file = Tempfile.new('mock_answers.json')
unless initial_content.nil?
require 'json'
fake_answer_file.binmode
fake_answer_file.write(JSON.pretty_generate(initial_content))
end
fake_answer_file.close
ENV['PDK_ANSWER_FILE'] = fake_answer_file.path
end

after(:all) do
FileUtils.rm_f(ENV.fetch('PDK_ANSWER_FILE', nil)) # Need actual file calls here
ENV.delete('PDK_ANSWER_FILE')
end
end

context 'when run outside of a module' do
describe command('pdk set config') do
its(:exit_status) { is_expected.not_to eq 0 }
Expand Down
10 changes: 10 additions & 0 deletions spec/acceptance/support/a_saved_configuration_file.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
RSpec.shared_examples 'a saved configuration file' do |new_content|
it 'saves the setting' do
# Force the command to run if not already
subject.exit_status
expect(File).to exist(ENV.fetch('PDK_ANSWER_FILE', nil))

actual_content = File.open(ENV.fetch('PDK_ANSWER_FILE', nil), 'rb:utf-8', &:read)
expect(actual_content).to eq(new_content)
end
end
11 changes: 11 additions & 0 deletions spec/acceptance/support/a_saved_json_configuration_file.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
RSpec.shared_examples 'a saved JSON configuration file' do |new_json_content|
it 'saves the setting' do
# Force the command to run if not already
subject.exit_status
expect(File).to exist(ENV.fetch('PDK_ANSWER_FILE', nil))

actual_content_raw = File.open(ENV.fetch('PDK_ANSWER_FILE', nil), 'rb:utf-8', &:read)
actual_json_content = JSON.parse(actual_content_raw)
expect(actual_json_content).to eq(new_json_content)
end
end
17 changes: 17 additions & 0 deletions spec/acceptance/support/with_a_fake_answer_file.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
RSpec.shared_context 'with a fake answer file' do |initial_content = nil|
before(:all) do
fake_answer_file = Tempfile.new('mock_answers.json')
unless initial_content.nil?
require 'json'
fake_answer_file.binmode
fake_answer_file.write(JSON.pretty_generate(initial_content))
end
fake_answer_file.close
ENV['PDK_ANSWER_FILE'] = fake_answer_file.path
end

after(:all) do
FileUtils.rm_f(ENV.fetch('PDK_ANSWER_FILE', nil)) # Need actual file calls here
ENV.delete('PDK_ANSWER_FILE')
end
end
8 changes: 5 additions & 3 deletions spec/acceptance/test_unit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
include_context 'with a fake TTY'

shared_context 'with spec file' do |filename, content|
around(:all) do |example|
path = File.join('spec', 'unit', filename)
path = File.join('spec', 'unit', filename)
before(:all) do
FileUtils.mkdir_p(File.dirname(path))
File.open(path, 'w') { |f| f.puts content }
example.run
end

after(:all) do
FileUtils.rm_f(path)
end
end
Expand Down

0 comments on commit ee96de5

Please sign in to comment.