(PDOC-5) Add spec testing for pops component
Prior to this commit there was no testing around the pops component. Since most of the API in the pops component is private, there aren't very many things to test, so add just a few test cases. Additionally rename a previous spec file and make some changes to the Gemfile.
This commit is contained in:
parent
195374d2a7
commit
766fd57ebe
6
Gemfile
6
Gemfile
|
@ -8,5 +8,9 @@ group :test do
|
|||
gem 'rspec'
|
||||
gem 'mocha'
|
||||
gem 'puppetlabs_spec_helper'
|
||||
gem 'pry'
|
||||
end
|
||||
|
||||
group :development do
|
||||
gem 'pry'
|
||||
gem 'pry-debugger'
|
||||
end
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
require 'spec_helper'
|
||||
require 'puppetx/yardoc/pops/yard_statement'
|
||||
|
||||
describe Puppetx::Yardoc::Pops do
|
||||
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}
|
||||
let(:test_statement) {Puppetx::Yardoc::Pops::YARDStatement.new(model)}
|
||||
|
||||
describe "when creating a new instance of YARDStatement" do
|
||||
it "should raise an error if the argument is not a PopsObject" do
|
||||
test_arg = 'foo bar'
|
||||
expect{Puppetx::Yardoc::Pops::YARDStatement.new(test_arg)}.to raise_error(ArgumentError)
|
||||
end
|
||||
|
||||
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) { }"}
|
||||
let(:transformer) {Puppetx::Yardoc::Pops::YARDTransformer.new}
|
||||
|
||||
describe "transform method" do
|
||||
it "should perform the correct transformation with parameter defaults" do
|
||||
model = parser.parse_string(manifest_default).current.definitions.first
|
||||
statements = transformer.transform(model)
|
||||
expect(statements.parameters[0][0].class).to be(Puppetx::Yardoc::Pops::YARDStatement)
|
||||
end
|
||||
|
||||
it "should perform the correct transofmration without parameter defaults" do
|
||||
model = parser.parse_string(manifest).current.definitions.first
|
||||
statements = transformer.transform(model)
|
||||
expect(statements.parameters[0][1].class).to be(NilClass)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue