spec/unit/berkshelf/api/endpoint/v1_spec.rb in berkshelf-api-1.1.1 vs spec/unit/berkshelf/api/endpoint/v1_spec.rb in berkshelf-api-1.2.0.rc1
- old
+ new
@@ -4,26 +4,47 @@
include Rack::Test::Methods
include Berkshelf::API::Mixin::Services
let(:app) { described_class.new }
let(:cache_warm) { false }
+ let(:rack_env) { Hash.new }
before do
Berkshelf::API::CacheManager.start
cache_manager.set_warmed if cache_warm
end
subject { last_response }
describe "GET /universe" do
- before { get '/universe' }
+ before { get '/universe', {}, rack_env }
let(:app_cache) { cache_manager.cache }
context "the cache has been warmed" do
let(:cache_warm) { true }
+ context "the default format is json" do
+ subject { last_response }
+ let(:app_cache) { cache_manager.cache }
- its(:status) { should be(200) }
- its(:body) { should eq(app_cache.to_json) }
+ its(:status) { should be(200) }
+ its(:body) { should eq(app_cache.to_json) }
+ end
+ context "the user requests json" do
+ subject { last_response }
+ let(:app_cache) { cache_manager.cache }
+ let(:rack_env) { { 'HTTP_ACCEPT' => 'application/json' } }
+
+ its(:status) { should be(200) }
+ its(:body) { should eq(app_cache.to_json) }
+ end
+ context "the user requests msgpack" do
+ subject { last_response }
+ let(:app_cache) { cache_manager.cache }
+ let(:rack_env) { { 'HTTP_ACCEPT' => 'application/x-msgpack' } }
+
+ its(:status) { should be(200) }
+ its(:body) { should eq(app_cache.to_msgpack) }
+ end
end
context "the cache is still warming" do
its(:status) { should be(503) }
its(:headers) { should have_key("Retry-After") }