Skip to content

Commit d98d4f0

Browse files
committed
add ci_env rspec var and adjust cli unit test for ci
1 parent 486a239 commit d98d4f0

File tree

6 files changed

+14
-6
lines changed

6 files changed

+14
-6
lines changed

spec/puppet-check/cli_spec.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
it 'targets the current working directory if no paths were specified' do
77
expect { PuppetCheck::CLI.run(%w[--fail-on-warnings]) }.not_to raise_exception
88
expect(PuppetCheck.files[:clean].length).to eql(30)
9-
expect(PuppetCheck.files[:ignored].length).to eql(7)
9+
if ci_env
10+
expect(PuppetCheck.files[:ignored].length).to eql(8)
11+
else
12+
expect(PuppetCheck.files[:ignored].length).to eql(7)
13+
end
1014
end
1115
end
1216

spec/puppet-check/regression_check_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
context '.smoke' do
2121
# octocatalog-diff is returning a blank error for these tests
22-
unless ENV['CIRCLECI'] == 'true' || ENV['GITHUB_ACTIONS'] == 'true'
22+
unless ci_env
2323
it 'returns a pass for a successful catalog compilation' do
2424
expect { RegressionCheck.smoke(['good.example.com'], "#{octocatalog_diff_dir}octocatalog_diff.cfg.rb") }.not_to raise_exception
2525
end

spec/puppet-check/rspec_puppet_support_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
it 'creates missing directories, missing site.pp, missing symlinks, and a missing spec_helper' do
1717
# circle ci and gh actions
18-
if ENV['CIRCLECI'] == 'true' || ENV['GITHUB_ACTIONS'] == 'true'
18+
if ci_env
1919
expect { rspec_puppet_setup }.to output("git is not installed and cannot be used to retrieve dependency modules\nsubversion is not installed and cannot be used to retrieve dependency modules\npuppetlabs/gruntmaster has an unspecified, or specified but unsupported, download method.\n").to_stderr
2020
else
2121
expect { rspec_puppet_setup }.to output("subversion is not installed and cannot be used to retrieve dependency modules\npuppetlabs/gruntmaster has an unspecified, or specified but unsupported, download method.\n").to_stderr
@@ -29,7 +29,7 @@
2929
expect(File.file?('spec/spec_helper.rb')).to be true
3030

3131
# .dependency_setup
32-
expect(File.directory?('spec/fixtures/modules/puppetlabs-lvm')).to be true unless ENV['CIRCLECI'] == 'true' || ENV['GITHUB_ACTIONS'] == 'true'
32+
expect(File.directory?('spec/fixtures/modules/puppetlabs-lvm')).to be true unless ci_env
3333
expect(File.directory?('spec/fixtures/modules/stdlib')).to be true
3434
end
3535
end

spec/puppet-check/ruby_parser_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
RubyParser.ruby(["#{fixtures_dir}lib/style.rb"], true, [])
2424
expect(PuppetCheck.files[:errors]).to eql({})
2525
expect(PuppetCheck.files[:warnings].keys).to eql(["#{fixtures_dir}lib/style.rb"])
26-
unless ENV['CIRCLECI'] == 'true' || ENV['GITHUB_ACTIONS'] == 'true'
26+
unless ci_env
2727
expect(PuppetCheck.files[:warnings]["#{fixtures_dir}lib/style.rb"].join("\n")).to match(/Useless assignment.*\n.*Use the new.*\n.*Do not introduce.*\n.*Prefer single.*\n.*Remove unnecessary empty.*\n.*Source code comment is empty.*\n.*is a writable attribute.*\n.*Issue has no descriptive comment/)
2828
else
2929
expect(PuppetCheck.files[:warnings]["#{fixtures_dir}lib/style.rb"].join("\n")).to match(/Useless assignment.*\n.*Use the new.*\n.*Do not introduce.*\n.*Prefer single.*\n.*Remove unnecessary empty.*\n.*Source code comment is empty/)

spec/puppet_check_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787

8888
it 'correctly parses one directory and returns all of its files' do
8989
dir.each { |file| expect(File.file?(file)).to be true }
90-
if ENV['CIRCLECI'] == 'true' || ENV['GITHUB_ACTIONS'] == 'true'
90+
if ci_env
9191
expect(dir.length).to eql(37)
9292
else
9393
expect(dir.length).to eql(40)

spec/spec_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ def fixtures_dir
1111
def octocatalog_diff_dir
1212
@octocatalog_diff_dir = "#{File.dirname(__FILE__)}/octocatalog-diff/"
1313
end
14+
15+
def ci_env
16+
@ci_env = ENV['CIRCLECI'] == 'true' || ENV['GITHUB_ACTIONS'] == 'true'
17+
end
1418
end
1519

1620
RSpec.configure do |config|

0 commit comments

Comments
 (0)