frankfurter/spec/api_spec.rb

42 lines
817 B
Ruby
Raw Normal View History

2012-11-21 01:10:18 +01:00
require_relative 'helper'
require 'rack/test'
2014-03-14 13:08:48 +01:00
require 'api'
2012-11-21 01:10:18 +01:00
2014-03-14 13:08:48 +01:00
describe 'the API' do
2012-11-21 01:10:18 +01:00
include Rack::Test::Methods
let(:app) { Sinatra::Application }
let(:json) { Yajl::Parser.new.parse last_response.body }
2014-06-19 13:31:35 +02:00
it 'describes itself' do
get '/'
last_response.must_be :ok?
end
2012-11-21 01:10:18 +01:00
it 'returns latest snapshot' do
get '/latest'
2012-11-21 17:11:47 +01:00
last_response.must_be :ok?
2012-11-21 01:10:18 +01:00
end
it 'sets base currency' do
get '/latest?base=USD'
json['base'].must_equal 'USD'
end
2012-11-21 15:46:15 +01:00
it 'filters symbols' do
get '/latest?symbols=USD'
json['rates'].keys.must_equal %w(USD)
end
it 'returns historical data' do
get '/2012-11-20'
json['rates'].wont_be :empty?
2014-03-17 11:15:05 +01:00
json['date'].must_equal '2012-11-20'
end
it 'works around holidays' do
get '/2010-01-01'
json['rates'].wont_be :empty?
end
2012-11-21 01:10:18 +01:00
end