Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1 +1,9 @@ | |||
require "bundler/gem_tasks" | require "bundler/gem_tasks" | ||
require "rake/testtask" | |||
|
|||
Rake::TestTask.new do |t| | |||
t.libs.push 'test' | |||
t.pattern = 'test/**/*_test.rb' | |||
end | |||
|
|||
task default: :test |
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,7 +1,8 @@ | |||
require "forecastr/version" | require "forecastr/version" | ||
require 'forecastr/radar' | require "forecastr/radar" | ||
require 'forecastr/forecast' | require "forecastr/forecast" | ||
require 'forecastr/wind' | require "forecastr/wind" | ||
require 'forecastr/temperature' | require "forecastr/temperature" | ||
require 'forecastr/data_container' | require "forecastr/data_container" | ||
require 'forecastr/client' | require "forecastr/client" | ||
require "forecastr/temperature_converter" |
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,13 @@ | |||
module Forecastr | |||
class TemperatureConverter | |||
class << self | |||
def to_celsius kelvins | |||
(kelvins - 273.15).round(2) | |||
end | |||
|
|||
def to_farenheit kelvins | |||
(1.8 * (kelvins - 273.15) + 32).round(2) | |||
end | |||
end | |||
end | |||
end |
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
{"coord":{"lon":-0.13,"lat":51.51},"sys":{"message":0.0846,"country":"GB","sunrise":1395640357,"sunset":1395685239},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04n"}],"base":"cmc stations","main":{"temp":279.64,"humidity":55,"pressure":1003,"temp_min":278.71,"temp_max":280.37},"wind":{"speed":2.06,"gust":3.6,"deg":350},"clouds":{"all":92},"dt":1395699452,"id":2643743,"name":"London","cod":200} |
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
{"coord":{"lon":-0.13,"lat":51.51},"sys":{"message":0.047,"country":"GB","sunrise":1395381569,"sunset":1395425736},"weather":[{"id":520,"main":"Rain","description":"light intensity shower rain","icon":"09n"}],"base":"cmc stations","main":{"temp":280.79,"pressure":1001,"humidity":70,"temp_min":279.26,"temp_max":282.15},"wind":{"speed":5.1,"deg":180,"var_beg":150,"var_end":210},"rain":{"1h":5.08},"clouds":{"all":92},"dt":1395441145,"id":2643743,"name":"London","cod":200} |
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
{"coord":{"lon":21.43,"lat":42},"sys":{"message":0.0427,"country":"MK","sunrise":1395376499,"sunset":1395420461},"weather":[{"id":800,"main":"Clear","description":"Sky is Clear","icon":"01n"}],"base":"cmc stations","main":{"temp":283.85,"pressure":1021,"humidity":70,"temp_min":280.15,"temp_max":285.93},"wind":{"speed":1.16,"deg":128.501},"clouds":{"all":0},"dt":1395441000,"id":863860,"name":"Opština Karpoš","cod":200} |
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,18 @@ | |||
require 'test_helper' | |||
|
|||
class Forecastr::ClientTest < Minitest::Test | |||
def test_fetching_city_data_from_api | |||
stub_get("http://api.openweathermap.org/data/2.5/weather?q=London,UK").to_return(:body => fixture('london.json'), :headers => {:content_type => 'application/json; charset=utf-8'}) | |||
results = Forecastr::Client.search_by_city('London,UK') | |||
|
|||
assert_equal results.city, "London" | |||
end | |||
|
|||
def test_fetching_coordinates_data_from_api | |||
stub_get("http://api.openweathermap.org/data/2.5/weather?lat=42.0&lon=21.4333").to_return(:body => fixture('skopje.json'), :headers => {:content_type => 'application/json; charset=utf-8'}) | |||
results = Forecastr::Client.search_by_coordinates(42.0, 21.4333) | |||
This comment has been minimized.
Sorry, something went wrong.
zenspider
|
|||
|
|||
assert_equal results.city, "Opština Karpoš" | |||
end | |||
|
|||
end |
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,25 @@ | |||
require 'test_helper' | |||
|
|||
class Forecastr::DataContainerTest < Minitest::Test | |||
|
|||
def setup | |||
json = JSON.parse(fixture('skopje.json').read) | |||
@container = Forecastr::DataContainer.new(json) | |||
end | |||
|
|||
def test_mapping_from_json | |||
assert_equal @container.city, "Opština Karpoš" | |||
assert_equal @container.longitude, 21.43 | |||
assert_equal @container.latitude, 42 | |||
assert_equal @container.temperature, 283.85 | |||
assert_equal @container.pressure, 1021 | |||
assert_equal @container.humidity, 70 | |||
assert_equal @container.min_temperature, 280.15 | |||
assert_equal @container.max_temperature, 285.93 | |||
assert_equal @container.clouds, 0 | |||
assert_equal @container.wind_speed, 1.16 | |||
assert_equal @container.wind_angle, 128.501 | |||
assert_equal @container.sunrise, '1395376499' | |||
assert_equal @container.sunset, '1395420461' | |||
end | |||
end |
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,58 @@ | |||
require 'test_helper' | |||
|
|||
class Forecastr::ForecastTest < Minitest::Test | |||
def setup | |||
json = JSON.parse(fixture('london.json').read) | |||
@data = Forecastr::DataContainer.new(json) | |||
@forecast = Forecastr::Forecast.new(@data) | |||
end | |||
|
|||
def test_it_has_a_city | |||
assert_equal @forecast.city, @data.city | |||
end | |||
|
|||
def test_it_has_time_of_sunrise | |||
assert_equal @forecast.sunrise, DateTime.strptime(@data.sunrise, '%s') | |||
end | |||
|
|||
def test_time_of_sunset | |||
assert_equal @forecast.sunset, DateTime.strptime(@data.sunset, '%s') | |||
This comment has been minimized.
Sorry, something went wrong. |
|||
end | |||
|
|||
def test_longitude | |||
assert_equal @forecast.longitude, @data.longitude | |||
end | |||
|
|||
def test_latitude | |||
assert_equal @forecast.latitude, @data.latitude | |||
end | |||
|
|||
def test_current_temperature | |||
assert_equal @forecast.temperature.to_celsius, Forecastr::TemperatureConverter.to_celsius(@data.temperature) | |||
end | |||
|
|||
def test_minimal_temperature | |||
assert_equal @forecast.min_temperature.to_celsius, Forecastr::TemperatureConverter.to_celsius(@data.min_temperature) | |||
end | |||
|
|||
def test_maximal_temperature | |||
assert_equal @forecast.max_temperature.to_celsius, Forecastr::TemperatureConverter.to_celsius(@data.max_temperature) | |||
end | |||
|
|||
def test_pressure | |||
assert_equal @forecast.pressure, 1001 | |||
This comment has been minimized.
Sorry, something went wrong. |
|||
end | |||
|
|||
def test_humidity | |||
assert_equal @forecast.humidity, 70 | |||
end | |||
|
|||
def test_cloud_coverage | |||
assert_equal @forecast.clouds, 92 | |||
end | |||
|
|||
def test_wind | |||
assert_respond_to @forecast, :wind | |||
assert_kind_of Forecastr::Wind, @forecast.wind | |||
end | |||
end |
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,31 @@ | |||
require 'test_helper' | |||
|
|||
class Forecastr::RadarTest < Minitest::Test | |||
|
|||
def setup | |||
@radar = Forecastr::Radar.new | |||
end | |||
|
|||
def test_find_forecast_for_city | |||
stub_get("http://api.openweathermap.org/data/2.5/weather?q=London,UK").to_return(:body => fixture('london.json'), :headers => {:content_type => 'application/json; charset=utf-8'}) | |||
|
|||
forecast = @radar.find_by_city("London,UK") | |||
|
|||
assert_equal forecast.city, "London" | |||
assert_equal forecast.temperature.to_celsius, 7.64 | |||
assert_equal forecast.humidity, 70 | |||
assert_equal forecast.pressure, 1001 | |||
end | |||
|
|||
|
|||
def test_find_forecast_by_coordinates | |||
stub_get("http://api.openweathermap.org/data/2.5/weather?lat=42.0&lon=21.4333").to_return(:body => fixture('skopje.json'), :headers => {:content_type => 'application/json; charset=utf-8'}) | |||
|
|||
forecast = @radar.find_by_coordinates(42.000, 21.4333) | |||
|
|||
assert_equal forecast.city, "Opština Karpoš" | |||
assert_equal forecast.temperature.to_celsius, 10.7 | |||
assert_equal forecast.humidity, 70 | |||
assert_equal forecast.pressure, 1021 | |||
end | |||
end |
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,12 @@ | |||
require 'test_helper' | |||
|
|||
class Forecastr::TemperatureConverterTest < Minitest::Test | |||
|
|||
def test_celsius_conversion | |||
assert_equal Forecastr::TemperatureConverter.to_celsius(273.15), 0 | |||
end | |||
|
|||
def test_farenheit_conversion | |||
assert_equal Forecastr::TemperatureConverter.to_farenheit(278), 40.73 | |||
end | |||
end |
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,16 @@ | |||
require 'test_helper' | |||
|
|||
class Forecastr::TemperatureTest < Minitest::Test | |||
|
|||
def setup | |||
@temperature = Forecastr::Temperature.new(306.11) | |||
end | |||
|
|||
def test_to_celsius | |||
assert_equal @temperature.to_celsius, 32.96 | |||
This comment has been minimized.
Sorry, something went wrong.
zenspider
|
|||
end | |||
|
|||
def test_to_farenheit | |||
assert_equal @temperature.to_farenheit, 91.33 | |||
end | |||
end |
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,16 @@ | |||
require 'test_helper' | |||
|
|||
class Forecastr::WindTest < Minitest::Test | |||
|
|||
def setup | |||
@wind = Forecastr::Wind.new(2.5, -37) | |||
end | |||
|
|||
def test_speed_in_ms | |||
assert_equal @wind.speed, "2.5 m/s" | |||
end | |||
|
|||
def test_direction | |||
assert_equal @wind.direction, "NNW" | |||
end | |||
end |
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,22 @@ | |||
require 'forecastr' | |||
require 'minitest/autorun' | |||
require 'minitest/unit' | |||
require "minitest/reporters" | |||
require 'webmock' | |||
|
|||
include WebMock::API | |||
|
|||
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new | |||
|
|||
def fixture_path | |||
File.expand_path('../fixtures', __FILE__) | |||
This comment has been minimized.
Sorry, something went wrong.
zenspider
|
|||
end | |||
|
|||
def fixture(file) | |||
File.new(fixture_path + '/' + file) | |||
This comment has been minimized.
Sorry, something went wrong. |
|||
end | |||
|
|||
def stub_get(path) | |||
stub_request(:get, path) | |||
end | |||
|
3 comments
on commit 39264e4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I blogged about this migration @ https://ieftimov.com/migrate-rspec-to-minitest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple simple mistakes, but looks good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zenspider thanks so much! :-)
This comment has been minimized.
Sorry, something went wrong.
zenspiderJul 14, 2015