diff options
author | Adam Jahn <ajjahn@gmail.com> | 2016-07-08 15:05:48 -0400 |
---|---|---|
committer | Adam Jahn <ajjahn@gmail.com> | 2016-07-08 15:05:48 -0400 |
commit | f0095397fd8a61367d39ae76bf63fb1c48885bbc (patch) | |
tree | a4dbb58817c4711c7590de86a34bbc6ee3bf10fa /spec/support | |
parent | 98e7b92963b8288de0a700b1acd7bc7abdd717f2 (diff) | |
download | puppet-samba-f0095397fd8a61367d39ae76bf63fb1c48885bbc.tar.gz puppet-samba-f0095397fd8a61367d39ae76bf63fb1c48885bbc.tar.bz2 |
implement helpers and reduce test duplication
Diffstat (limited to 'spec/support')
-rw-r--r-- | spec/support/augeas.rb | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/spec/support/augeas.rb b/spec/support/augeas.rb new file mode 100644 index 0000000..4912e1a --- /dev/null +++ b/spec/support/augeas.rb @@ -0,0 +1,67 @@ +require "delegate" + +module Augeas + class Change + attr_reader :target, :name, :delimiter + + def initialize(target, name, value = nil, delimiter = "\"") + @target = target + @name = name + @value = value + @delimiter = delimiter + end + + def to_s + "#{action} #{delimiter}target[. = '#{target}']/#{name}#{delimiter}#{value}" + end + + def hash + [target, name, Change].hash + end + + def eql?(other) + other.is_a?(self.class) && [other.target, other.name] == [target, name] + end + + private + + def action + return "set" unless @value.nil? + "rm " + end + + def value + " #{@value}" if @value + end + end + + class ChangeSet + def initialize + @set = {} + end + + def <<(change) + @set[change] = change + end + + def to_a + changes + end + + def changes + @set.values.map(&:to_s) + end + end + + class TargetedChangeSet < DelegateClass(ChangeSet) + def initialize(target) + @target = target + super(ChangeSet.new) + end + + def with(*args) + self << Change.new(@target, *args) + self + end + end +end |