# # Author:: Adam Leff ( "read_uuid" }) expect(TestMessage.read_node_uuid).to eq("read_uuid") end end describe "metadata" do let(:metadata_filename) { "fake_metadata_file.json" } before do allow(TestMessage).to receive(:metadata_filename).and_return(metadata_filename) end context "when the metadata file exists" do it "returns the contents of the metadata file" do expect(Chef::FileCache).to receive(:load).with(metadata_filename).and_return('{"foo":"bar"}') expect(TestMessage.metadata["foo"]).to eq("bar") end end context "when the metadata file does not exist" do it "returns an empty hash" do expect(Chef::FileCache).to receive(:load).with(metadata_filename).and_raise(Chef::Exceptions::FileNotFound) expect(TestMessage.metadata).to eq({}) end end end describe "#update_metadata" do it "updates the file" do allow(TestMessage).to receive(:metadata_filename).and_return("fake_metadata_file.json") allow(TestMessage).to receive(:metadata).and_return({ "key" => "current_value" }) expect(Chef::FileCache).to receive(:store).with( "fake_metadata_file.json", '{"key":"updated_value"}', 0644 ) TestMessage.update_metadata("key", "updated_value") end end end