
The previous use of require caused File.join on several occasions to calculate different paths to the same library, depending on which __FILE__ the library was being calculated as relative to; e.g. /some/path/prefix/spec/one/bar.rb would do the equivalent of: require '/some/path/prefix/spec/one/../../libraries/foo/mylib.rb' and /some/path/prefix/spec/two/baz.rb would do the equivalent of: require '/some/path/prefix/spec/two/../../libraries/foo/mylib.rb' This would result in mylib.rb being loaded multiple times, causing warnings from constants being redefined, and worse, multiple objects representing the same class hierarchy (@@foo) variables. The latter actually broke the @@subclasses registration mechanism in Pacemaker::CIBObject. By switching to File.expand_path, we ensure we always refer to each library using a single absolute path, which means Ruby's require mechanism works as it should, only loading the code the first time round.
29 lines
860 B
Ruby
29 lines
860 B
Ruby
require 'spec_helper'
|
|
require File.expand_path('../../../libraries/pacemaker/resource',
|
|
File.dirname(__FILE__))
|
|
|
|
describe Pacemaker::Resource do
|
|
describe "#running?" do
|
|
let(:rsc) { Pacemaker::Resource.new('keystone') }
|
|
|
|
before(:each) do
|
|
@cmd = double(Mixlib::ShellOut)
|
|
expect(rsc).to receive(:shell_out!) \
|
|
.with(*%w(crm resource status keystone)) \
|
|
.and_return(@cmd)
|
|
end
|
|
|
|
it "should return true" do
|
|
expect(@cmd).to receive(:stdout).at_least(:once) \
|
|
.and_return("resource #{rsc.name} is running on: d52-54-00-e5-6b-a0")
|
|
expect(rsc.running?).to be(true)
|
|
end
|
|
|
|
it "should return false" do
|
|
expect(@cmd).to receive(:stdout).at_least(:once) \
|
|
.and_return("resource #{rsc.name} is NOT running")
|
|
expect(rsc.running?).to be(false)
|
|
end
|
|
end
|
|
end
|