spec/flydata/helper/config_parser_spec.rb in flydata-0.5.21 vs spec/flydata/helper/config_parser_spec.rb in flydata-0.6.0

- old
+ new

@@ -103,8 +103,65 @@ } }) end end end + describe ".parse_file" do + subject { described_class.parse_file(path) } + + let(:expected_result) { double("expected_parse_result") } + + shared_examples "opening a conf file and parse the contents" do + let(:conf_contents) { double("conf_contents") } + let(:conf_file) { double("conf_file") } + + before do + expect(File).to receive(:open).with(expected_path). + and_return(conf_file) + expect(conf_file).to receive(:read).and_return(conf_contents) + expect(described_class).to receive(:parse).with(conf_contents). + and_return(expected_result) + end + end + + context "when path is given" do + let(:path) { "/path/to/my/helper.conf" } + let(:expected_path) { path } + + before do + expect(File).to_not receive(:exists?) + end + include_examples "opening a conf file and parse the contents" + it { is_expected.to eq(expected_result) } + end + context "when no path is given" do + let(:path) { nil } + let(:expected_path) { File.join(Flydata::FLYDATA_HELPER_HOME, "helper.conf") } + + context "and default conf file exists" do + before do + expect(File).to receive(:exists?).with(expected_path). + and_return true + end + include_examples "opening a conf file and parse the contents" + it { is_expected.to eq(expected_result) } + end + context "and default conf file does not exist" do + before do + expect(File).to receive(:exists?).with(expected_path). + and_return false + end + let(:expected_result) { { + helper: { + scheduled_actions: { + check_remote_actions: { check_interval: "30s"}, + check_abnormal_shutdown: {:check_interval=>"60s"} + } + } + } } + it { is_expected.to eq(expected_result) } + end + end + end end end end