require 'rails_helper'

RSpec.describe 'Bank holidays' do
  describe 'bundled database' do
    subject do
      JSON.parse(File.read('config/bank-holidays.json'))['england-and-wales']['events']
    end

    it 'contains at least one bank holiday after today' do
      expect(subject.map do |entry|
        Date.parse(entry['date'])
      end.find do |date|
        date > Date.today
      end).not_to be_nil
    end
  end

  describe 'remote data source' do
    subject do
      JSON.parse(Curl::Easy.perform('https://www.gov.uk/bank-holidays.json').body_str)
    end

    it 'contains a list of holidays' do
      first_entry = subject['england-and-wales']['events'].first
      first_entry.keys.to_set > Set['bunting', 'date', 'notes', 'title']
    end
  end
end

require 'rails_helper'

RSpec.describe 'Bank holidays' do
  describe 'bundled database' do
    subject do
      JSON.parse(File.read('config/bank-holidays.json'))['england-and-wales']['events']
    end

    it 'contains at least one bank holiday after today' do
      expect(subject.map do |entry|
        Date.parse(entry['date'])
      end.find do |date|
        date > Date.today
      end).not_to be_nil
    end

    describe 'a bank holiday object' do
      expected_keys = %w( bunting date notes title )

      it "contains the keys: #{expected_keys.to_sentence}" do
        subject.each do |hash|
          expect(hash.keys).to include *expected_keys
        end
      end
    end
  end
end

Remove unnecessary foreign data source check
Remove unnecessary foreign data source check

It seems unnecessary to make a call out to get the bank
holiday data every time the suite of specs is run. Besides
this the actual test makes no assertion! & the attempt at
an assertion incorrectly uses sets `proper_superset?`
method which is inappropriate for comparing sets that
contain exactly the same items.

Imagine the following:

   Set A = [ 1, 2, 3]
   Set B = [ 1, 2, 3, 4]

In the example above Set B is a 'proper superset' of
Set A as it contains at least one more element that is not
in Set A.

Moving on..

Whenever the data is updated via the rake task we would
spot inconsistencies in the data when the specs run.

A test has been added to assert the data contains the
expected keys.
