Fix minitest deprecations

This commit is contained in:
Hakan Ensari 2020-05-02 17:08:47 +01:00
parent cb8dd05177
commit 52e57475ab
12 changed files with 105 additions and 101 deletions

View File

@ -4,5 +4,8 @@ Metrics/BlockLength:
ExcludedMethods: ['describe', 'helpers']
Metrics/MethodLength:
Max: 13
Minitest:
Include:
- '**/*_spec.rb'
Style/Documentation:
Enabled: false

View File

@ -15,32 +15,32 @@ module Bank
it 'fetches current rates' do
feed = Feed.current
feed.count.must_be :==, 1
_(feed.count).must_be :==, 1
end
it 'fetches rates for the past 90 days' do
feed = Feed.ninety_days
feed.count.must_be :>, 1
feed.count.must_be :<=, 90
_(feed.count).must_be :>, 1
_(feed.count).must_be :<=, 90
end
it 'fetches historical rates' do
feed = Feed.historical
feed.count.must_be :>, 90
_(feed.count).must_be :>, 90
end
it 'parses dates' do
feed = Feed.current
day = feed.first
day[:date].must_be_kind_of Date
_(day[:date]).must_be_kind_of Date
end
it 'parses rates' do
feed = Feed.current
day = feed.first
day[:rates].each do |iso_code, value|
iso_code.must_be_kind_of String
value.must_be_kind_of Float
_(iso_code).must_be_kind_of String
_(value).must_be_kind_of Float
end
end
end

View File

@ -22,46 +22,46 @@ describe Bank do
it 'fetches all rates' do
Bank.fetch_all!
Day.count.must_be :>, 90
_(Day.count).must_be :>, 90
end
it 'does not duplicate when fetching all rates' do
Bank.fetch_all!
count = Day.count
Bank.fetch_all!
Day.count.must_equal count
_(Day.count).must_equal count
end
it 'fetches rates for last 90 days' do
Bank.fetch_ninety_days!
Day.count.must_be :>, 1
Day.count.must_be :<, 90
_(Day.count).must_be :>, 1
_(Day.count).must_be :<, 90
end
it 'seeds rates with saved data' do
Bank.seed_with_saved_data!
Day.count.must_be :>, 90
_(Day.count).must_be :>, 90
end
it 'does not duplicate when fetching rates for last 90 days' do
Bank.fetch_ninety_days!
count = Day.count
Bank.fetch_ninety_days!
Day.count.must_equal count
_(Day.count).must_equal count
end
it 'fetches current rates' do
Bank.fetch_current!
Day.count.must_equal 1
_(Day.count).must_equal 1
end
it 'does not duplicate when fetching current rates' do
2.times { Bank.fetch_current! }
Day.count.must_equal 1
_(Day.count).must_equal 1
end
it 'replaces all rates' do
Bank.replace_all!
Day.count.must_be :>, 90
_(Day.count).must_be :>, 90
end
end

View File

@ -9,10 +9,10 @@ describe CurrencyNames do
end
it 'returns currency codes and names' do
currency_names.formatted['USD'].must_equal 'United States Dollar'
_(currency_names.formatted['USD']).must_equal 'United States Dollar'
end
it 'has a cache key' do
currency_names.cache_key.wont_be :empty?
_(currency_names.cache_key).wont_be :empty?
end
end

View File

@ -2,12 +2,13 @@
require_relative 'helper'
require 'currency'
require 'minitest/autorun'
describe Currency do
describe '.latest' do
it 'returns latest rates' do
data = Currency.latest.all
data.count.must_be :>, 1
_(data.count).must_be :>, 1
end
end
@ -18,18 +19,18 @@ describe Currency do
it 'returns everything up to a year' do
interval = day..day + 365
Currency.between(interval).map(:date).uniq.count.must_be :>, 52
_(Currency.between(interval).map(:date).uniq.count).must_be :>, 52
end
it 'samples weekly over a year' do
interval = day..day + 366
Currency.between(interval).map(:date).uniq.count.must_be :<, 54
_(Currency.between(interval).map(:date).uniq.count).must_be :<, 54
end
it 'sorts by date' do
interval = day..day + 100
dates = Currency.between(interval).map(:date)
dates.must_equal dates.sort
_(dates).must_equal dates.sort
end
end
@ -37,11 +38,11 @@ describe Currency do
it 'filters symbols' do
iso_codes = %w[CAD USD]
data = Currency.latest.only(*iso_codes).all
data.map(&:iso_code).sort.must_equal iso_codes
_(data.map(&:iso_code).sort).must_equal iso_codes
end
it 'returns nothing if no matches' do
Currency.only('FOO').all.must_be_empty
_(Currency.only('FOO').all).must_be_empty
end
end
end

View File

@ -8,11 +8,11 @@ describe Day do
it 'returns latest rates before given date' do
date = Date.parse('2010-01-01')
data = Day.latest(date)
data.first.date.must_be :<=, date
_(data.first.date).must_be :<=, date
end
it 'returns nothing if there are no rates before given date' do
Day.latest(Date.parse('1998-01-01')).must_be_empty
_(Day.latest(Date.parse('1998-01-01'))).must_be_empty
end
end
@ -21,13 +21,13 @@ describe Day do
start_date = Date.parse('2010-01-01')
end_date = Date.parse('2010-01-31')
dates = Day.between((start_date..end_date)).map(:date).sort
dates.first.must_be :>=, start_date
dates.last.must_be :<=, end_date
_(dates.first).must_be :>=, start_date
_(dates.last).must_be :<=, end_date
end
it 'returns nothing if there are no rates between given dates' do
interval = (Date.parse('1998-01-01')..Date.parse('1998-01-31'))
Day.between(interval).must_be_empty
_(Day.between(interval)).must_be_empty
end
end
end

View File

@ -15,27 +15,27 @@ describe 'the server' do
it 'handles unfound pages' do
get '/foo'
last_response.status.must_equal 404
_(last_response.status).must_equal 404
end
it 'will not process an invalid date' do
get '/2010-31-01'
last_response.must_be :unprocessable?
_(last_response).must_be :unprocessable?
end
it 'will not process a date before 2000' do
get '/1999-01-01'
last_response.must_be :not_found?
_(last_response).must_be :not_found?
end
it 'will not process an unavailable base' do
get '/latest?base=UAH'
last_response.must_be :not_found?
_(last_response).must_be :not_found?
end
it 'handles malformed queries' do
get '/latest?base=USD?callback=?'
last_response.must_be :not_found?
_(last_response).must_be :not_found?
end
it 'does not return stale dates' do
@ -44,7 +44,7 @@ describe 'the server' do
date = json['date']
Day.latest.delete
get '/latest'
json['date'].wont_equal date
_(json['date']).wont_equal date
raise Sequel::Rollback
end
end

View File

@ -5,69 +5,69 @@ require 'query'
describe Query do
it 'builds a query hash' do
Query.build(date: '2014-01-01').must_be_kind_of Hash
_(Query.build(date: '2014-01-01')).must_be_kind_of Hash
end
it 'returns given amount' do
query = Query.new(amount: '100')
query.amount.must_equal 100.0
_(query.amount).must_equal 100.0
end
it 'defaults amount to nothing' do
query = Query.new
query.amount.must_be_nil
_(query.amount).must_be_nil
end
it 'returns given base' do
query = Query.new(base: 'USD')
query.base.must_equal 'USD'
_(query.base).must_equal 'USD'
end
it 'upcases given base' do
query = Query.new(base: 'usd')
query.base.must_equal 'USD'
_(query.base).must_equal 'USD'
end
it 'defaults base to nothing' do
query = Query.new
query.base.must_be_nil
_(query.base).must_be_nil
end
it 'aliases base with from' do
query = Query.new(from: 'USD')
query.base.must_equal 'USD'
_(query.base).must_equal 'USD'
end
it 'returns given symbols' do
query = Query.new(symbols: 'USD,GBP')
query.symbols.must_equal %w[USD GBP]
_(query.symbols).must_equal %w[USD GBP]
end
it 'upcases given symbols' do
query = Query.new(symbols: 'usd,gbp')
query.symbols.must_equal %w[USD GBP]
_(query.symbols).must_equal %w[USD GBP]
end
it 'aliases symbols with to' do
query = Query.new(to: 'USD')
query.symbols.must_equal ['USD']
_(query.symbols).must_equal ['USD']
end
it 'defaults symbols to nothing' do
query = Query.new
query.symbols.must_be_nil
_(query.symbols).must_be_nil
end
it 'returns given date' do
date = '2014-01-01'
query = Query.new(date: date)
query.date.must_equal Date.parse(date)
_(query.date).must_equal Date.parse(date)
end
it 'returns given date interval' do
start_date = '2014-01-01'
end_date = '2014-12-31'
query = Query.new(start_date: start_date, end_date: end_date)
query.date.must_equal((Date.parse(start_date)..Date.parse(end_date)))
_(query.date).must_equal((Date.parse(start_date)..Date.parse(end_date)))
end
end

View File

@ -14,23 +14,23 @@ module Quote
end
it 'requires data' do
-> { quote.perform }.must_raise NotImplementedError
_ { quote.perform }.must_raise NotImplementedError
end
it 'does not know how to format result' do
-> { quote.formatted }.must_raise NotImplementedError
_ { quote.formatted }.must_raise NotImplementedError
end
it 'does not know how to generate a cache key' do
-> { quote.cache_key }.must_raise NotImplementedError
_ { quote.cache_key }.must_raise NotImplementedError
end
it 'defaults base to Euro' do
quote.base.must_equal 'EUR'
_(quote.base).must_equal 'EUR'
end
it 'defaults amount to 1' do
quote.amount.must_equal 1
_(quote.amount).must_equal 1
end
describe 'when given data' do
@ -67,7 +67,7 @@ module Quote
it 'finds nothing' do
quote.perform
quote.not_found?.must_equal true
_(quote.not_found?).must_equal true
end
end
@ -88,7 +88,7 @@ module Quote
it 'finds nothing' do
quote.perform
quote.not_found?.must_equal true
_(quote.not_found?).must_equal true
end
end
end

View File

@ -18,24 +18,24 @@ module Quote
end
it 'returns rates' do
quote.formatted[:rates].wont_be :empty?
_(quote.formatted[:rates]).wont_be :empty?
end
it 'quotes given date' do
Date.parse(quote.formatted[:date]).must_be :<=, date
_(Date.parse(quote.formatted[:date])).must_be :<=, date
end
it 'quotes against the Euro' do
quote.formatted[:rates].keys.wont_include 'EUR'
_(quote.formatted[:rates].keys).wont_include 'EUR'
end
it 'sorts rates' do
rates = quote.formatted[:rates]
rates.keys.must_equal rates.keys.sort
_(rates.keys).must_equal rates.keys.sort
end
it 'has a cache key' do
quote.cache_key.wont_be :empty?
_(quote.cache_key).wont_be :empty?
end
describe 'given a new base' do
@ -44,12 +44,12 @@ module Quote
end
it 'quotes against that base' do
quote.formatted[:rates].keys.wont_include 'USD'
_(quote.formatted[:rates].keys).wont_include 'USD'
end
it 'sorts rates' do
rates = quote.formatted[:rates]
rates.keys.must_equal rates.keys.sort
_(rates.keys).must_equal rates.keys.sort
end
end
@ -60,13 +60,13 @@ module Quote
it 'quotes only for those symbols' do
rates = quote.formatted[:rates]
rates.keys.must_include 'USD'
rates.keys.wont_include 'CAD'
_(rates.keys).must_include 'USD'
_(rates.keys).wont_include 'CAD'
end
it 'sorts rates' do
rates = quote.formatted[:rates]
rates.keys.must_equal rates.keys.sort
_(rates.keys).must_equal rates.keys.sort
end
end
@ -76,7 +76,7 @@ module Quote
end
it 'calculates quotes for that amount' do
quote.formatted[:rates]['USD'].must_be :>, 10
_(quote.formatted[:rates]['USD']).must_be :>, 10
end
end
end

View File

@ -5,12 +5,12 @@ require 'quote/interval'
module Quote
describe Interval do
let(:date_interval) do
let(:dates) do
(Date.parse('2010-01-01')..Date.parse('2010-12-31'))
end
let(:quote) do
Interval.new(date: date_interval)
Interval.new(date: dates)
end
before do
@ -18,75 +18,75 @@ module Quote
end
it 'returns rates' do
quote.formatted[:rates].wont_be :empty?
_(quote.formatted[:rates]).wont_be :empty?
end
it 'quotes given date interval' do
Date.parse(quote.formatted[:start_date]).must_be :>=, date_interval.first
Date.parse(quote.formatted[:end_date]).must_be :<=, date_interval.last
_(Date.parse(quote.formatted[:start_date])).must_be :>=, dates.first
_(Date.parse(quote.formatted[:end_date])).must_be :<=, dates.last
end
it 'quotes against the Euro' do
quote.formatted[:rates].each_value do |rates|
rates.keys.wont_include 'EUR'
_(rates.keys).wont_include 'EUR'
end
end
it 'sorts rates' do
quote.formatted[:rates].each_value do |rates|
rates.keys.must_equal rates.keys.sort
_(rates.keys).must_equal rates.keys.sort
end
end
it 'has a cache key' do
quote.cache_key.wont_be :empty?
_(quote.cache_key).wont_be :empty?
end
describe 'given a new base' do
let(:quote) do
Interval.new(date: date_interval, base: 'USD')
Interval.new(date: dates, base: 'USD')
end
it 'quotes against that base' do
quote.formatted[:rates].each_value do |rates|
rates.keys.wont_include 'USD'
_(rates.keys).wont_include 'USD'
end
end
it 'sorts rates' do
quote.formatted[:rates].each_value do |rates|
rates.keys.must_equal rates.keys.sort
_(rates.keys).must_equal rates.keys.sort
end
end
end
describe 'given symbols' do
let(:quote) do
Interval.new(date: date_interval, symbols: %w[USD GBP JPY])
Interval.new(date: dates, symbols: %w[USD GBP JPY])
end
it 'quotes only for those symbols' do
quote.formatted[:rates].each_value do |rates|
rates.keys.must_include 'USD'
rates.keys.wont_include 'CAD'
_(rates.keys).must_include 'USD'
_(rates.keys).wont_include 'CAD'
end
end
it 'sorts rates' do
quote.formatted[:rates].each_value do |rates|
rates.keys.must_equal rates.keys.sort
_(rates.keys).must_equal rates.keys.sort
end
end
end
describe 'when given an amount' do
let(:quote) do
Interval.new(date: date_interval, amount: 100)
Interval.new(date: dates, amount: 100)
end
it 'calculates quotes for that amount' do
quote.formatted[:rates].each_value do |rates|
rates['USD'].must_be :>, 10
_(rates['USD']).must_be :>, 10
end
end
end

View File

@ -13,46 +13,46 @@ describe 'the server' do
it 'redirects root to documentation site' do
get '/'
last_response.must_be :redirect?
_(last_response).must_be :redirect?
end
it 'returns latest quotes' do
get '/latest'
last_response.must_be :ok?
_(last_response).must_be :ok?
end
it 'sets base currency' do
get '/latest'
res = Oj.load(last_response.body)
get '/latest?from=USD'
json.wont_equal res
_(json).wont_equal res
end
it 'sets base amount' do
get '/latest?amount=10'
json['rates']['USD'].must_be :>, 10
_(json['rates']['USD']).must_be :>, 10
end
it 'filters symbols' do
get '/latest?to=USD'
json['rates'].keys.must_equal %w[USD]
_(json['rates'].keys).must_equal %w[USD]
end
it 'returns historical quotes' do
get '/2012-11-20'
json['rates'].wont_be :empty?
json['date'].must_equal '2012-11-20'
_(json['rates']).wont_be :empty?
_(json['date']).must_equal '2012-11-20'
end
it 'works around holidays' do
get '/2010-01-01'
json['rates'].wont_be :empty?
_(json['rates']).wont_be :empty?
end
it 'returns an ETag' do
%w[/latest /2012-11-20].each do |path|
get path
headers['ETag'].wont_be_nil
_(headers['ETag']).wont_be_nil
end
end
@ -76,30 +76,30 @@ describe 'the server' do
it 'converts an amount' do
get '/latest?from=GBP&to=USD&amount=100'
json['rates']['USD'].must_be :>, 100
_(json['rates']['USD']).must_be :>, 100
end
it 'returns rates for a given period' do
get '/2010-01-01..2010-12-31'
json['start_date'].wont_be :empty?
json['end_date'].wont_be :empty?
json['rates'].wont_be :empty?
_(json['start_date']).wont_be :empty?
_(json['end_date']).wont_be :empty?
_(json['rates']).wont_be :empty?
end
it 'returns rates when given period does not include end date' do
get '/2010-01-01..'
json['start_date'].wont_be :empty?
json['end_date'].wont_be :empty?
json['rates'].wont_be :empty?
_(json['start_date']).wont_be :empty?
_(json['end_date']).wont_be :empty?
_(json['rates']).wont_be :empty?
end
it 'returns currencies' do
get '/currencies'
json['USD'].must_equal 'United States Dollar'
_(json['USD']).must_equal 'United States Dollar'
end
it 'handles JSONP' do
get '/latest?callback=foo'
last_response.body.must_be :start_with?, 'foo'
_(last_response.body).must_be :start_with?, 'foo'
end
end