From e2699706e1bf37e874e412a0e54a12f5bff6952f Mon Sep 17 00:00:00 2001 From: Xero Date: Mon, 4 Mar 2024 22:14:33 -0500 Subject: [PATCH] coverage for show sunlight hours --- spec/lib/show_sunlight_hours_spec.rb | 29 ++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 spec/lib/show_sunlight_hours_spec.rb diff --git a/spec/lib/show_sunlight_hours_spec.rb b/spec/lib/show_sunlight_hours_spec.rb new file mode 100644 index 0000000..e767f3d --- /dev/null +++ b/spec/lib/show_sunlight_hours_spec.rb @@ -0,0 +1,29 @@ +RSpec.describe ShowSunlightHours do + describe '.show' do + let(:body) do + <<~BODY +{"results":{"sunrise":"2024-03-05T11:10:30+00:00","sunset":"2024-03-05T22:40:57+00:00","solar_noon":"2024-03-05T16:55:44+00:00","day_length":41427,"civil_twilight_begin":"2024-03-05T10:43:54+00:00","civil_twilight_end":"2024-03-05T23:07:33+00:00","nautical_twilight_begin":"2024-03-05T10:11:24+00:00","nautical_twilight_end":"2024-03-05T23:40:03+00:00","astronomical_twilight_begin":"2024-03-05T09:38:43+00:00","astronomical_twilight_end":"2024-03-06T00:12:44+00:00"},"status":"OK","tzid":"UTC"} + BODY + end + + before(:each) do + stub_request(:get, "https://api.sunrise-sunset.org/json") + .with(query: { formatted: 0, lat: 42.3723008, lng: -71.10656 }) + .to_return(status: 200, body: body, headers: {'Content-Type' => 'application/json'}) + + end + + subject { ShowSunlightHours.show } + + it do + expect(subject).to be_instance_of(Hash) + expect(subject[:hours]).to be_kind_of(Numeric) + expect(subject[:sunset]).to be_instance_of(Time) + expect(subject[:sunrise]).to be_instance_of(Time) + expect( + a_request(:get, "https://api.sunrise-sunset.org/json") + .with(query: { formatted: 0, lat: 42.3723008, lng: -71.10656 }) + ).to have_been_made + end + end +end \ No newline at end of file