Files
cookbook-pacemaker/spec/helpers/provider.rb
Adam Spiers c0e3907ba0 tidy up requires
It's really ugly to have to keep repeating File.dirname(__FILE__),
so we use a temporary variable, even in the case of a single require.
This minimises long "requires" lines and "requires" statements with
needing line-breaks, and should make search-and-replace a bit easier
if we later want to migrate to __dir__ (Ruby >= 2.0) or require_relative.

  http://stackoverflow.com/questions/4333286/ruby-require-vs-require-relative-best-practice-to-workaround-running-in-both

I've deliberately rejected the pattern:

  require File.expand_path('../relative/path', __FILE__)

because it relies on inconsistent semantics and inconsistent
documentation in File.expand_path:

  http://stackoverflow.com/questions/4333286/ruby-require-vs-require-relative-best-practice-to-workaround-running-in-both#comment34147297_4333552
2014-03-25 18:37:50 +00:00

43 lines
1.2 KiB
Ruby

# Shared code used to test providers of CIB objects
this_dir = File.dirname(__FILE__)
require File.expand_path('../helpers/cib_object', this_dir)
shared_context "a Pacemaker LWRP" do
before(:each) do
runner_opts = {
:step_into => [lwrp_name]
}
@chef_run = ::ChefSpec::Runner.new(runner_opts)
@chef_run.converge "pacemaker::default"
@node = @chef_run.node
@run_context = @chef_run.run_context
camelized_subclass_name = "Pacemaker" + lwrp_name.capitalize
@resource_class = ::Chef::Resource.const_get(camelized_subclass_name)
@provider_class = ::Chef::Provider.const_get(camelized_subclass_name)
@resource = @resource_class.new(fixture.name, @run_context)
end
let (:provider) { @provider_class.new(@resource, @run_context) }
end
shared_examples "action on non-existent resource" do |action, cmd, expected_error|
include Chef::RSpec::Pacemaker::CIBObject
it "should not attempt to #{action.to_s} a non-existent resource" do
stub_shellout("")
if expected_error
expect { provider.run_action action }.to \
raise_error(RuntimeError, expected_error)
else
provider.run_action action
end
expect(@chef_run).not_to run_execute(cmd)
expect(@resource).not_to be_updated
end
end