diff --git a/spec/helpers/cib_object.rb b/spec/helpers/cib_object.rb index 660b6d2..0d3bb50 100644 --- a/spec/helpers/cib_object.rb +++ b/spec/helpers/cib_object.rb @@ -1,6 +1,44 @@ +# Shared code used to test providers of CIB objects + require 'mixlib/shellout' -# Shared code used to test providers of CIB objects +require File.expand_path('../../libraries/pacemaker/cib_object', + File.dirname(__FILE__)) + +shared_examples "a CIB object" do + def expect_to_match_fixture(obj) + expect(obj.is_a? pacemaker_object_class).to eq(true) + fields.each do |field| + method = field.to_sym + expect(obj.send(method)).to eq(fixture.send(method)) + end + end + + it "should be instantiated via Pacemaker::CIBObject.from_name" do + Mixlib::ShellOut.any_instance.stub(:error!) + expect_any_instance_of(Mixlib::ShellOut) \ + .to receive(:stdout) \ + .and_return(fixture.definition_string) + + obj = Pacemaker::CIBObject.from_name(fixture.name) + expect_to_match_fixture(obj) + end + + it "should instantiate by parsing a definition" do + obj = Pacemaker::CIBObject.from_definition(fixture.definition_string) + expect_to_match_fixture(obj) + end + + it "should barf if the loaded definition's type is not colocation" do + Mixlib::ShellOut.any_instance.stub(:error!) + expect_any_instance_of(Mixlib::ShellOut) \ + .to receive(:stdout) \ + .and_return("clone foo blah blah") + expect { fixture.load_definition }.to \ + raise_error(Pacemaker::CIBObject::TypeMismatch, + "Expected #{object_type} type but loaded definition was type clone") + end +end shared_examples "action on non-existent resource" do |action, cmd, expected_error| it "should not attempt to #{action.to_s} a non-existent resource" do diff --git a/spec/helpers/common_object_examples.rb b/spec/helpers/common_object_examples.rb deleted file mode 100644 index e997a2b..0000000 --- a/spec/helpers/common_object_examples.rb +++ /dev/null @@ -1,38 +0,0 @@ -require 'mixlib/shellout' -require File.expand_path('../../libraries/pacemaker/cib_object', - File.dirname(__FILE__)) - -shared_examples "a CIB object" do - def expect_to_match_fixture(obj) - expect(obj.is_a? pacemaker_object_class).to eq(true) - fields.each do |field| - method = field.to_sym - expect(obj.send(method)).to eq(fixture.send(method)) - end - end - - it "should be instantiated via Pacemaker::CIBObject.from_name" do - Mixlib::ShellOut.any_instance.stub(:error!) - expect_any_instance_of(Mixlib::ShellOut) \ - .to receive(:stdout) \ - .and_return(fixture.definition_string) - - obj = Pacemaker::CIBObject.from_name(fixture.name) - expect_to_match_fixture(obj) - end - - it "should instantiate by parsing a definition" do - obj = Pacemaker::CIBObject.from_definition(fixture.definition_string) - expect_to_match_fixture(obj) - end - - it "should barf if the loaded definition's type is not colocation" do - Mixlib::ShellOut.any_instance.stub(:error!) - expect_any_instance_of(Mixlib::ShellOut) \ - .to receive(:stdout) \ - .and_return("clone foo blah blah") - expect { fixture.load_definition }.to \ - raise_error(Pacemaker::CIBObject::TypeMismatch, - "Expected #{object_type} type but loaded definition was type clone") - end -end diff --git a/spec/libraries/pacemaker/constraint/colocation_spec.rb b/spec/libraries/pacemaker/constraint/colocation_spec.rb index dc13dbf..cbf9a0b 100644 --- a/spec/libraries/pacemaker/constraint/colocation_spec.rb +++ b/spec/libraries/pacemaker/constraint/colocation_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' require File.expand_path('../../../../libraries/pacemaker/constraint/colocation', File.dirname(__FILE__)) require File.expand_path('../../../fixtures/colocation_constraint', File.dirname(__FILE__)) -require File.expand_path('../../../helpers/common_object_examples', File.dirname(__FILE__)) +require File.expand_path('../../../helpers/cib_object', File.dirname(__FILE__)) describe Pacemaker::Constraint::Colocation do let(:fixture) { Chef::RSpec::Pacemaker::Config::COLOCATION_CONSTRAINT.dup } diff --git a/spec/libraries/pacemaker/resource/primitive_spec.rb b/spec/libraries/pacemaker/resource/primitive_spec.rb index c6c2d2a..8556472 100644 --- a/spec/libraries/pacemaker/resource/primitive_spec.rb +++ b/spec/libraries/pacemaker/resource/primitive_spec.rb @@ -3,7 +3,7 @@ require File.expand_path('../../../../libraries/pacemaker/resource/primitive', File.dirname(__FILE__)) require File.expand_path('../../../fixtures/keystone_primitive', File.dirname(__FILE__)) -require File.expand_path('../../../helpers/common_object_examples', +require File.expand_path('../../../helpers/cib_object', File.dirname(__FILE__)) require File.expand_path('../../../helpers/meta_examples', File.dirname(__FILE__))