Files
cookbook-pacemaker/spec/libraries/pacemaker/constraint/location_spec.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

69 lines
1.7 KiB
Ruby

require 'spec_helper'
this_dir = File.dirname(__FILE__)
require File.expand_path('../../../../libraries/pacemaker/constraint/location',
this_dir)
require File.expand_path('../../../fixtures/location_constraint', this_dir)
require File.expand_path('../../../helpers/cib_object', this_dir)
describe Pacemaker::Constraint::Location do
let(:fixture) { Chef::RSpec::Pacemaker::Config::LOCATION_CONSTRAINT.dup }
let(:fixture_definition) {
Chef::RSpec::Pacemaker::Config::LOCATION_CONSTRAINT_DEFINITION
}
before(:each) do
Mixlib::ShellOut.any_instance.stub(:run_command)
end
def object_type
'location'
end
def pacemaker_object_class
Pacemaker::Constraint::Location
end
def fields
%w(name rsc score node)
end
it_should_behave_like "a CIB object"
describe "#definition_string" do
it "should return the definition string" do
expect(fixture.definition_string).to eq(fixture_definition)
end
it "should return a short definition string" do
location = pacemaker_object_class.new('foo')
location.definition = \
%!location location1 primitive1 -inf: node1!
location.parse_definition
expect(location.definition_string).to eq(<<'EOF'.chomp)
location location1 primitive1 -inf: node1
EOF
end
end
describe "#parse_definition" do
before(:each) do
@parsed = pacemaker_object_class.new(fixture.name)
@parsed.definition = fixture_definition
@parsed.parse_definition
end
it "should parse the rsc" do
expect(@parsed.rsc).to eq(fixture.rsc)
end
it "should parse the score" do
expect(@parsed.score).to eq(fixture.score)
end
it "should parse the node" do
expect(@parsed.node).to eq(fixture.node)
end
end
end