diff --git a/spec/helpers/common.rb b/spec/helpers/common.rb new file mode 100644 index 0000000..307b1f3 --- /dev/null +++ b/spec/helpers/common.rb @@ -0,0 +1,24 @@ +require 'mixlib/shellout' + +module Chef::RSpec + module Pacemaker + module Common + # "crm configure show" is executed by load_current_resource, and + # again later on for the :create action, to see whether to create or + # modify. + def expect_definition(definition) + Mixlib::ShellOut.any_instance.stub(:run_command) + Mixlib::ShellOut.any_instance.stub(:error!) + expect_any_instance_of(Mixlib::ShellOut) \ + .to receive(:stdout) \ + .and_return(definition) + end + + def expect_exists(exists) + expect_any_instance_of(cib_object_class) \ + .to receive(:exists?) \ + .and_return(exists) + end + end + end +end diff --git a/spec/providers/primitive_spec.rb b/spec/providers/primitive_spec.rb index 4834983..3ca6074 100644 --- a/spec/providers/primitive_spec.rb +++ b/spec/providers/primitive_spec.rb @@ -1,5 +1,6 @@ require 'chef/application' require_relative File.join(%w(.. spec_helper)) +require_relative File.join(%w(.. helpers common)) require_relative File.join(%w(.. fixtures keystone_primitive)) describe "Chef::Provider::PacemakerPrimitive" do @@ -26,27 +27,12 @@ describe "Chef::Provider::PacemakerPrimitive" do let (:provider) { Chef::Provider::PacemakerPrimitive.new(@resource, @run_context) } - # "crm configure show" is executed by load_current_resource, and - # again later on for the :create action, to see whether to create or - # modify. - def expect_definition(definition) - Mixlib::ShellOut.any_instance.stub(:run_command) - Mixlib::ShellOut.any_instance.stub(:error!) - expect_any_instance_of(Mixlib::ShellOut) \ - .to receive(:stdout) \ - .and_return(definition) - end - - def expect_exists(exists) - expect_any_instance_of(Pacemaker::Resource::Primitive) \ - .to receive(:exists?) \ - .and_return(exists) - end - def cib_object_class Pacemaker::Resource::Primitive end + include Chef::RSpec::Pacemaker::Common + def expect_running(running) expect_any_instance_of(cib_object_class) \ .to receive(:running?) \