Skip to content

Commit

Permalink
coverage for show sunlight hours
Browse files Browse the repository at this point in the history
  • Loading branch information
one-m1nd committed Mar 5, 2024
1 parent 5b08589 commit e269970
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions spec/lib/show_sunlight_hours_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e269970

Please sign in to comment.