spec/grape-apiary/blueprint_spec.rb in grape-apiary-0.0.2 vs spec/grape-apiary/blueprint_spec.rb in grape-apiary-0.0.3
- old
+ new
@@ -1,30 +1,32 @@
require 'spec_helper'
describe GrapeApiary::Blueprint do
include_context 'configuration'
- context '#generate' do
- before do
- GrapeApiary.config do |config|
- config.host = host
- config.name = name
- config.description = description
- config.resource_exclusion = [:admin]
- end
+ before do
+ GrapeApiary.config do |config|
+ config.host = host
+ config.name = name
+ config.description = description
+ config.resource_exclusion = [:admin]
+ end
- GrapeApiary.config.request_headers = [
- { 'Accept-Charset' => 'utf-8' },
- { 'Connection' => 'keep-alive' }
- ]
+ GrapeApiary.config.request_headers = [
+ { 'Accept-Charset' => 'utf-8' },
+ { 'Connection' => 'keep-alive' }
+ ]
- GrapeApiary.config.response_headers = [
- { 'Content-Length' => '21685' },
- { 'Connection' => 'keep-alive' }
- ]
- end
+ GrapeApiary.config.response_headers = [
+ { 'Content-Length' => '21685' },
+ { 'Connection' => 'keep-alive' }
+ ]
+ end
+ subject { GrapeApiary::Blueprint.new(SampleApi) }
+
+ context '#generate' do
let(:klass) { SampleApi }
subject { GrapeApiary::Blueprint.new(klass).generate }
it 'sets the format to 1A' do
@@ -43,8 +45,36 @@
expect(subject).to include(description)
end
it 'includes groups for each resource' do
expect(subject).to include('# Group Widgets')
+ end
+ end
+
+ it 'exposes configuration settings' do
+ GrapeApiary::Config::SETTINGS.each do |setting|
+ expect(subject.send(setting)).to eq(GrapeApiary.config.send(setting))
+ end
+ end
+
+ it 'exposes the raw routes of the given api' do
+ expect(subject.routes).to eq(SampleApi.routes)
+ end
+
+ context '#resources' do
+ let(:unique_routes) { subject.routes.map(&:route_name).uniq }
+
+ let(:included_routes) do
+ unique_routes.reject do |name|
+ GrapeApiary.config.resource_exclusion.include?(name.to_sym)
+ end
+ end
+
+ it 'aggregates routes into resources' do
+ expect(subject.resources.first).to be_a(GrapeApiary::Resource)
+ end
+
+ it 'excluded resources based on configuration' do
+ expect(subject.resources.map(&:key)).to eq(included_routes)
end
end
end