2014-08-21 22:38:35 +00:00
|
|
|
require 'spec_helper'
|
2015-02-03 23:06:30 +00:00
|
|
|
require 'puppet_x/puppetlabs/strings/pops/yard_statement'
|
2014-08-21 22:38:35 +00:00
|
|
|
|
2015-02-03 23:06:30 +00:00
|
|
|
describe PuppetX::PuppetLabs::Strings::Pops do
|
2014-08-21 22:38:35 +00:00
|
|
|
let(:parser) {Puppet::Pops::Parser::Parser.new()}
|
|
|
|
|
|
|
|
describe "YARDstatement class" do
|
|
|
|
let(:manifest) {"#hello world\nclass foo { }"}
|
|
|
|
let(:model) {parser.parse_string(manifest).current.definitions.first}
|
2015-02-03 23:06:30 +00:00
|
|
|
let(:test_statement) {PuppetX::PuppetLabs::Strings::Pops::YARDStatement.new(model)}
|
2014-08-21 22:38:35 +00:00
|
|
|
|
|
|
|
describe "when creating a new instance of YARDStatement" do
|
|
|
|
it "should extract comments from the source code" do
|
|
|
|
expect(test_statement.comments).to match(/^#hello world/)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "YARDTransfomer class" do
|
|
|
|
let(:manifest) {"#hello world\nclass foo($bar) { }"}
|
|
|
|
let(:manifest_default) {"#hello world\nclass foo($bar = 3) { }"}
|
2015-02-03 23:06:30 +00:00
|
|
|
let(:transformer) {PuppetX::PuppetLabs::Strings::Pops::YARDTransformer.new}
|
2014-08-21 22:38:35 +00:00
|
|
|
|
2015-02-13 18:55:12 +00:00
|
|
|
describe "transform method" do
|
|
|
|
it "should perform the correct transformation with parameter defaults" do
|
2014-08-21 22:38:35 +00:00
|
|
|
model = parser.parse_string(manifest_default).current.definitions.first
|
|
|
|
statements = transformer.transform(model)
|
2015-02-03 23:06:30 +00:00
|
|
|
expect(statements.parameters[0][0].class).to be(PuppetX::PuppetLabs::Strings::Pops::YARDStatement)
|
2015-02-13 18:55:12 +00:00
|
|
|
end
|
2014-08-21 22:38:35 +00:00
|
|
|
|
2015-02-13 18:55:12 +00:00
|
|
|
it "should perform the correct transofmration without parameter defaults" do
|
2014-08-21 22:38:35 +00:00
|
|
|
model = parser.parse_string(manifest).current.definitions.first
|
|
|
|
statements = transformer.transform(model)
|
|
|
|
expect(statements.parameters[0][1].class).to be(NilClass)
|
2015-02-13 18:55:12 +00:00
|
|
|
end
|
2014-08-21 22:38:35 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|