spec/configurable.rb in mattock-0.3.4 vs spec/configurable.rb in mattock-0.4.0

- old
+ new

@@ -49,9 +49,116 @@ expect do subject.check_required end.to_not raise_error end + describe "with DirectoryStructure" do + class DirectoryThing + include Mattock::Configurable + include DirectoryStructure + + dir(:ephemeral_mountpoint, + dir(:bundle_workdir, "bundle_workdir", + path(:bundle_manifest), + path(:credentials_archive, "aws-creds.tar.gz"), + dir(:credentials_dir, "aws-creds", + path(:private_key_file, "pk.pem"), + path(:certificate_file, "cert.pem") + ) + ) + ) + end + + def subject + DirectoryThing.new.tap do |thing| + thing.setup_defaults + end + end + + it "should complain about missing fields" do + expect do + subject.check_required + end.to raise_error /Required field/ + end + + describe "with root path configured, but missing a relative path" do + def subject + DirectoryThing.new.tap do |thing| + thing.setup_defaults + thing.ephemeral_mountpoint.absolute_path = "/tmp" + thing.resolve_paths + end + end + + it "should complain about missing fields" do + expect do + subject.check_required + end.to raise_error /Required field/ + end + end + + describe "with required paths configured" do + def subject + DirectoryThing.new.tap do |thing| + thing.setup_defaults + thing.ephemeral_mountpoint.absolute_path = "/tmp" + thing.bundle_manifest.relative_path = "image.manifest.xml" + thing.resolve_paths + end + end + + it "should not complain about required fields" do + expect do + subject.check_required + end.not_to raise_error + end + + its("certificate_file.absolute_path"){ should == "/tmp/bundle_workdir/aws-creds/cert.pem" } + its("bundle_manifest.absolute_path"){ should == "/tmp/bundle_workdir/image.manifest.xml" } + its("credentials_dir.absolute_path"){ should == "/tmp/bundle_workdir/aws-creds" } + end + end + + describe "multiple instances" do + class MultiSource + include Mattock::Configurable + + setting :one, 1 + setting :nest, nested{ + setting :two, 2 + } + end + + let :first do + MultiSource.new.setup_defaults + end + + let :second do + MultiSource.new.setup_defaults + end + + before :each do + first.one = "one" + first.nest.two = "two" + second + end + + it "should not have any validation errors" do + expect do + first.check_required + second.check_required + end.not_to raise_error + end + + it "should accurately reflect settings" do + first.one.should == "one" + second.one.should == 1 + + first.nest.two.should == "two" + second.nest.two.should == 2 + end + end + describe "copying settings" do class LeftStruct include Mattock::Configurable setting(:normal, 1)