spec/calendar_spec.rb in business-1.18.0 vs spec/calendar_spec.rb in business-2.0.0

- old
+ new

@@ -6,32 +6,22 @@ config.raise_errors_for_deprecations! end describe Business::Calendar do describe ".load" do + let(:dummy_calendar) { { "working_days" => ["monday"] } } + before do fixture_path = File.join(File.dirname(__FILE__), 'fixtures', 'calendars') - Business::Calendar.additional_load_paths = [fixture_path] + described_class.load_paths = [fixture_path, { "foobar" => dummy_calendar }] end - context "when given a valid calendar" do - subject { Business::Calendar.load("weekdays") } - - it "loads the yaml file" do - expect(YAML).to receive(:load_file) { |path| - expect(path).to match(/weekdays\.yml$/) - }.and_return({}) - subject - end - - it { is_expected.to be_a Business::Calendar } - end - context "when given a calendar from a custom directory" do - after { Business::Calendar.additional_load_paths = nil } - subject { Business::Calendar.load("ecb") } + subject { described_class.load("ecb") } + after { described_class.load_paths = nil } + it "loads the yaml file" do expect(YAML).to receive(:load_file) { |path| expect(path).to match(/ecb\.yml$/) }.and_return({}) subject @@ -47,10 +37,16 @@ to eq(true) end end end + context "when loading a calendar as a hash" do + subject { described_class.load("foobar") } + + it { is_expected.to be_a Business::Calendar } + end + context "when given a calendar that does not exist" do subject { Business::Calendar.load("invalid-calendar") } specify { expect { subject }.to raise_error(/No such calendar/) } end @@ -65,22 +61,9 @@ Dir.glob("#{data_path}/*").each do |filename| calendar_name = File.basename(filename, ".yml") calendar = Business::Calendar.load(calendar_name) expect(calendar.working_days.length).to be >= 1 - end - end - end - end - - describe "bundled calendars" do - calendars = Dir.glob("../lib/business/data*.yml") - .map { |f| File.basename(f, ".yml") } - - calendars.each do |calendar| - describe calendar do - it "should load without issues" do - expect { Business::Calendar.load(calendar) }.not_to raise_error end end end end