From 766fd57ebe447b5dd52e62a092ab1d7381ff1f2e Mon Sep 17 00:00:00 2001 From: Hailee Kenney Date: Thu, 21 Aug 2014 15:38:35 -0700 Subject: [PATCH] (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. --- Gemfile | 6 +++- spec/unit/{ => puppet}/face_spec.rb | 0 spec/unit/puppetx/yardoc/pops_spec.rb | 43 +++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) rename spec/unit/{ => puppet}/face_spec.rb (100%) create mode 100644 spec/unit/puppetx/yardoc/pops_spec.rb diff --git a/Gemfile b/Gemfile index f897512..392ea17 100644 --- a/Gemfile +++ b/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 diff --git a/spec/unit/face_spec.rb b/spec/unit/puppet/face_spec.rb similarity index 100% rename from spec/unit/face_spec.rb rename to spec/unit/puppet/face_spec.rb diff --git a/spec/unit/puppetx/yardoc/pops_spec.rb b/spec/unit/puppetx/yardoc/pops_spec.rb new file mode 100644 index 0000000..0407d99 --- /dev/null +++ b/spec/unit/puppetx/yardoc/pops_spec.rb @@ -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