Skip to content

(MAINT) Add CI workflow #310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
(MAINT) Rubocop - (spec) fixes for puppet-strings
  • Loading branch information
chelnak committed Sep 28, 2022
commit 5ceb042f197c85f61b51fe6463f4ead5101a28cc
16 changes: 7 additions & 9 deletions spec/unit/puppet-strings/describe_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@
require 'puppet-strings/describe'
require 'tempfile'

#TODO:
#basic describe
#params from other files (e.g. file content)
# TODO: basic describe
# params from other files (e.g. file content)
#--providers - list providers in detail
#X--list - list all providers summary
# X--list - list all providers summary
#--meta - List all metaparameters
#--short - only list params

describe PuppetStrings::Describe do
before :each do
# Populate the YARD registry with both Puppet and Ruby source


YARD::Parser::SourceParser.parse_string(<<-SOURCE, :ruby)
Puppet::Type.newtype(:database) do
desc 'An example database server resource type.'
Expand Down Expand Up @@ -98,16 +96,16 @@
end

describe 'rendering DESCRIBE to stdout' do
it 'should output the expected describe content for the list of types' do
it 'outputs the expected describe content for the list of types' do
output = <<-DATA
These are the types known to puppet:
apt_key - This type provides Puppet with the capabiliti ...
database - An example database server resource type.
file - Manages files, including their content, owner ...
DATA
expect{ PuppetStrings::Describe.render(nil, true) }.to output(output).to_stdout
expect { described_class.render(nil, true) }.to output(output).to_stdout
end
it 'should output the expected describe content for a type' do
it 'outputs the expected describe content for a type' do
output = <<-DATA

file
Expand Down Expand Up @@ -137,7 +135,7 @@
Providers
---------
DATA
expect{ PuppetStrings::Describe.render(['file']) }.to output(output).to_stdout
expect { described_class.render(['file']) }.to output(output).to_stdout
end
end
end
26 changes: 13 additions & 13 deletions spec/unit/puppet-strings/json_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,49 +226,49 @@ class klass(Integer $param1, $param2, String $param3 = hi) inherits foo::bar {
SOURCE
end

RSpec.shared_examples "correct JSON" do
it 'should include data for Puppet Classes' do
RSpec.shared_examples 'correct JSON' do
it 'includes data for Puppet Classes' do
puppet_class_json = YARD::Registry.all(:puppet_class).sort_by!(&:name).map!(&:to_hash).to_json

expect(json_output).to include_json(puppet_class_json)
end

it 'should include data for Puppet Data Types' do
it 'includes data for Puppet Data Types' do
data_types_json = YARD::Registry.all(:puppet_data_type).sort_by!(&:name).map!(&:to_hash).to_json
expect(json_output).to include_json(data_types_json)
end

it 'should include data for Puppet Defined Types' do
it 'includes data for Puppet Defined Types' do
defined_types_json = YARD::Registry.all(:puppet_defined_type).sort_by!(&:name).map!(&:to_hash).to_json

expect(json_output).to include_json(defined_types_json)
end

it 'should include data for Puppet Resource Types' do
it 'includes data for Puppet Resource Types' do
resource_types_json = YARD::Registry.all(:puppet_type).sort_by!(&:name).map!(&:to_hash).to_json

expect(json_output).to include_json(resource_types_json)
end

it 'should include data for Puppet Providers' do
it 'includes data for Puppet Providers' do
providers_json = YARD::Registry.all(:puppet_provider).sort_by!(&:name).map!(&:to_hash).to_json

expect(json_output).to include_json(providers_json)
end

it 'should include data for Puppet Functions', if: TEST_PUPPET_FUNCTIONS do
it 'includes data for Puppet Functions', if: TEST_PUPPET_FUNCTIONS do
puppet_functions_json = YARD::Registry.all(:puppet_function).sort_by!(&:name).map!(&:to_hash).to_json

expect(json_output).to include_json(puppet_functions_json)
end

it 'should include data for Puppet Tasks' do
it 'includes data for Puppet Tasks' do
puppet_tasks_json = YARD::Registry.all(:puppet_task).sort_by!(&:name).map!(&:to_hash).to_json

expect(json_output).to include_json(puppet_tasks_json)
end

it 'should include data for Puppet Plans', if: TEST_PUPPET_PLANS do
it 'includes data for Puppet Plans', if: TEST_PUPPET_PLANS do
puppet_plans_json = YARD::Registry.all(:puppet_plan).sort_by!(&:name).map!(&:to_hash).to_json

expect(json_output).to include_json(puppet_plans_json)
Expand All @@ -280,15 +280,15 @@ class klass(Integer $param1, $param2, String $param3 = hi) inherits foo::bar {
json_output = nil

Tempfile.open('json') do |file|
PuppetStrings::Json.render(file.path)
described_class.render(file.path)

json_output = File.read(file.path)
end

json_output
end

include_examples "correct JSON"
include_examples 'correct JSON'
end

describe 'rendering JSON to stdout' do
Expand All @@ -300,13 +300,13 @@ class klass(Integer $param1, $param2, String $param3 = hi) inherits foo::bar {
old_stdout = $stdout
$stdout = output

PuppetStrings::Json.render(nil)
described_class.render(nil)

$stdout = old_stdout

@json_output = output.string
end

include_examples "correct JSON"
include_examples 'correct JSON'
end
end
25 changes: 13 additions & 12 deletions spec/unit/puppet-strings/markdown/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class klass(Integer $param1, $param2, String $param3 = hi) inherits foo::bar {
end

let(:reg) { YARD::Registry.all(:puppet_class).sort_by!(&:name).map!(&:to_hash)[0] }
let(:component) { PuppetStrings::Markdown::Base.new(reg, 'class') }
let(:component) { described_class.new(reg, 'class') }

describe '#name' do
it 'returns the expected name' do
Expand All @@ -27,16 +27,15 @@ class klass(Integer $param1, $param2, String $param3 = hi) inherits foo::bar {
end

['examples',
'see',
'since',
'return_val',
'return_type',].each do |method|
'see',
'since',
'return_val',
'return_type'].each do |method|
describe "##{method}" do
it 'returns nil' do
expect(component.method(method.to_sym).call).to be_nil
end
end

end

describe '#private?' do
Expand All @@ -59,6 +58,7 @@ class klass(Integer $param1, $param2, String $param3 = hi) inherits foo::bar {

describe '#toc_info' do
let(:toc) { component.toc_info }

it 'returns a hash' do
expect(toc).to be_instance_of Hash
end
Expand Down Expand Up @@ -91,7 +91,7 @@ class klass::yeah(
end

let(:reg) { YARD::Registry.all(:puppet_class).sort_by!(&:name).map!(&:to_hash)[0] }
let(:component) { PuppetStrings::Markdown::Base.new(reg, 'class') }
let(:component) { described_class.new(reg, 'class') }

describe '#name' do
it 'returns the expected name' do
Expand All @@ -100,10 +100,10 @@ class klass::yeah(
end

['summary',
'see',
'since',
'return_val',
'return_type'].each do |method|
'see',
'since',
'return_val',
'return_type'].each do |method|
describe "##{method}" do
it 'returns nil' do
expect(component.method(method.to_sym).call).to be_nil
Expand All @@ -112,7 +112,7 @@ class klass::yeah(
end

describe '#examples' do
it 'should return one example' do
it 'returns one example' do
expect(component.examples.size).to eq 1
end
end
Expand All @@ -131,6 +131,7 @@ class klass::yeah(

describe '#toc_info' do
let(:toc) { component.toc_info }

it 'returns a hash' do
expect(toc).to be_instance_of Hash
end
Expand Down
Loading