(PDOC-5) Add spec testing for face component

Add spec tests for Puppet face component, mainly around error checking.
Due to the use of `puppet module list`, the behavior of the `modules`
and `server` actions are not very feasible to test via spec testing.

Additionally, make a few minor changes to the gem file, and make a
small change in `check_required_features` to reflect the fact that
this module will no longer support anything earlier than Ruby 1.9.
This commit is contained in:
Hailee Kenney 2014-08-19 10:44:40 -07:00
parent 686e60c791
commit 195374d2a7
5 changed files with 68 additions and 18 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

63
spec/unit/face_spec.rb Normal file
View File

@ -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