diff --git a/Gemfile b/Gemfile index ff3e997..f897512 100644 --- a/Gemfile +++ b/Gemfile @@ -1,11 +1,12 @@ source 'https://rubygems.org' gem 'yard' +gem 'puppet', '~> 3.6.2' gem 'rgen' group :test do gem 'rspec' gem 'mocha' - gem 'puppet' gem 'puppetlabs_spec_helper' + gem 'pry' end diff --git a/lib/puppet/face/yardoc.rb b/lib/puppet/face/yardoc.rb index f5809b6..d394335 100644 --- a/lib/puppet/face/yardoc.rb +++ b/lib/puppet/face/yardoc.rb @@ -12,8 +12,8 @@ Puppet::Face.define(:yardoc, '0.0.1') do raise RuntimeError, "The 'rgen' gem must be installed in order to use this face." end - if RUBY_VERSION < '1.9' && !Puppet.features.require_relative? - raise RuntimeError, "The 'backports' gem must be installed in order to use this face under Ruby 1.8.7." + if RUBY_VERSION.match(/^1\.8/) + raise RuntimeError, "This face requires Ruby 1.9 or greater." end end diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb deleted file mode 100644 index 5d4503c..0000000 --- a/spec/classes/init_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ -require 'spec_helper' -describe 'puppet_yardoc' do - - context 'with defaults for all parameters' do - it { should contain_class('puppet_yardoc') } - end -end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5fda588..81921a0 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -4,14 +4,7 @@ $LOAD_PATH.unshift File.join(dir, 'lib') require 'mocha' require 'puppet' require 'rspec' -require 'spec/autorun' -Spec::Runner.configure do |config| +RSpec.configure do |config| config.mock_with :mocha end - -# We need this because the RAL uses 'should' as a method. This -# allows us the same behaviour but with a different method name. -class Object - alias :must :should -end diff --git a/spec/unit/face_spec.rb b/spec/unit/face_spec.rb new file mode 100644 index 0000000..b60b6ef --- /dev/null +++ b/spec/unit/face_spec.rb @@ -0,0 +1,63 @@ +require 'spec_helper' +require 'puppet/face/yardoc' + +describe Puppet::Face do + + describe "YARDoc action" do + it "should raise an error if yard is absent" do + Puppet.features.stubs(:yard?).returns(false) + expect{Puppet::Face[:yardoc, :current].yardoc}.to raise_error(RuntimeError, "The 'yard' gem must be installed in order to use this face.") + end + + it "should raise an error if rgen is absent" do + Puppet.features.stubs(:rgen?).returns(false) + expect{Puppet::Face[:yardoc, :current].yardoc}.to raise_error(RuntimeError, "The 'rgen' gem must be installed in order to use this face.") + end + + it "should raise an error if the Ruby verion is less than 1.9", :if => RUBY_VERSION.match(/^1\.8/) do + expect{Puppet::Face[:yardoc, :current].yardoc}.to raise_error(RuntimeError, "This face requires Ruby 1.9 or greater.") + end + + it "should invoke Yardoc with MODULE_SOURCEFILES if no arguments are provided" do + YARD::CLI::Yardoc.expects(:run).with('manifests/**/*.pp', 'lib/**/*.rb') + Puppet::Face[:yardoc, :current].yardoc + end + + it "should invoke Yardoc with provided arguments" do + YARD::CLI::Yardoc.expects(:run).with('--debug', 'some_file.rb') + Puppet::Face[:yardoc, :current].yardoc('--debug', 'some_file.rb') + end + end + + describe "modules action" do + it "should raise an error if yard is absent" do + Puppet.features.stubs(:yard?).returns(false) + expect{Puppet::Face[:yardoc, :current].modules}.to raise_error(RuntimeError, "The 'yard' gem must be installed in order to use this face.") + end + + it "should raise an error if rgen is absent" do + Puppet.features.stubs(:rgen?).returns(false) + expect{Puppet::Face[:yardoc, :current].modules}.to raise_error(RuntimeError, "The 'rgen' gem must be installed in order to use this face.") + end + + it "should raise an error if the Ruby version is less than 1.9", :if => RUBY_VERSION.match(/^1\.8/) do + expect{Puppet::Face[:yardoc, :current].modules}.to raise_error(RuntimeError, "This face requires Ruby 1.9 or greater.") + end + end + + describe "server action" do + it "should raise an error if yard is absent" do + Puppet.features.stubs(:yard?).returns(false) + expect{Puppet::Face[:yardoc, :current].server}.to raise_error(RuntimeError, "The 'yard' gem must be installed in order to use this face.") + end + + it "should raise an error if rgen is absent" do + Puppet.features.stubs(:rgen?).returns(false) + expect{Puppet::Face[:yardoc, :current].server}.to raise_error(RuntimeError, "The 'rgen' gem must be installed in order to use this face.") + end + + it "should raise an error if the Ruby version is less than 1.9", :if => RUBY_VERSION.match(/^1\.8/) do + expect{Puppet::Face[:yardoc, :current].server}.to raise_error(RuntimeError, "This face requires Ruby 1.9 or greater.") + end + end +end