spec/grape/api_remount_spec.rb in grape-1.6.0 vs spec/grape/api_remount_spec.rb in grape-1.6.1
- old
+ new
@@ -2,13 +2,14 @@
require 'spec_helper'
require 'shared/versioning_examples'
describe Grape::API do
- subject(:a_remounted_api) { Class.new(Grape::API) }
- let(:root_api) { Class.new(Grape::API) }
+ subject(:a_remounted_api) { Class.new(described_class) }
+ let(:root_api) { Class.new(described_class) }
+
def app
root_api
end
describe 'remounting an API' do
@@ -66,11 +67,11 @@
end
describe 'with dynamic configuration' do
context 'when mounting an endpoint conditional on a configuration' do
subject(:a_remounted_api) do
- Class.new(Grape::API) do
+ Class.new(described_class) do
get 'always' do
'success'
end
given configuration[:mount_sometimes] do
@@ -99,11 +100,11 @@
end
end
context 'when using an expression derived from a configuration' do
subject(:a_remounted_api) do
- Class.new(Grape::API) do
+ Class.new(described_class) do
get(mounted { "api_name_#{configuration[:api_name]}" }) do
'success'
end
end
end
@@ -124,11 +125,11 @@
expect(last_response.body).not_to eq 'success'
end
context 'when the expression lives in a namespace' do
subject(:a_remounted_api) do
- Class.new(Grape::API) do
+ Class.new(described_class) do
namespace :base do
get(mounted { "api_name_#{configuration[:api_name]}" }) do
'success'
end
end
@@ -147,11 +148,11 @@
end
end
context 'when executing a standard block within a `mounted` block with all dynamic params' do
subject(:a_remounted_api) do
- Class.new(Grape::API) do
+ Class.new(described_class) do
mounted do
desc configuration[:description] do
headers configuration[:headers]
end
get configuration[:endpoint] do
@@ -189,11 +190,11 @@
end
end
context 'when executing a custom block on mount' do
subject(:a_remounted_api) do
- Class.new(Grape::API) do
+ Class.new(described_class) do
get 'always' do
'success'
end
mounted do
@@ -213,11 +214,11 @@
end
end
context 'when the configuration is part of the arguments of a method' do
subject(:a_remounted_api) do
- Class.new(Grape::API) do
+ Class.new(described_class) do
get configuration[:endpoint_name] do
'success'
end
end
end
@@ -235,11 +236,11 @@
expect(last_response.body).to eq 'success'
end
context 'when the configuration is the value in a key-arg pair' do
subject(:a_remounted_api) do
- Class.new(Grape::API) do
+ Class.new(described_class) do
version 'v1', using: :param, parameter: configuration[:version_param]
get 'endpoint' do
'version 1'
end
@@ -265,11 +266,11 @@
end
end
context 'on the DescSCope' do
subject(:a_remounted_api) do
- Class.new(Grape::API) do
+ Class.new(described_class) do
desc 'The description of this' do
tags ['not_configurable_tag', configuration[:a_configurable_tag]]
end
get 'location' do
'success'
@@ -282,11 +283,11 @@
end
end
context 'on the ParamScope' do
subject(:a_remounted_api) do
- Class.new(Grape::API) do
+ Class.new(described_class) do
params do
requires configuration[:required_param], type: configuration[:required_type]
end
get 'location' do
@@ -312,11 +313,11 @@
expect(last_response.status).to eq 400
end
context 'on dynamic checks' do
subject(:a_remounted_api) do
- Class.new(Grape::API) do
+ Class.new(described_class) do
params do
optional :restricted_values, values: -> { [configuration[:allowed_value], 'always'] }
end
get 'location' do
@@ -361,11 +362,11 @@
end
end
context 'a very complex configuration example' do
before do
- top_level_api = Class.new(Grape::API) do
+ top_level_api = Class.new(described_class) do
remounted_api = Class.new(Grape::API) do
get configuration[:endpoint_name] do
configuration[:response]
end
end
@@ -429,11 +430,11 @@
end
end
context 'when the configuration is read in a helper' do
subject(:a_remounted_api) do
- Class.new(Grape::API) do
+ Class.new(described_class) do
helpers do
def printed_response
configuration[:some_value]
end
end
@@ -452,10 +453,10 @@
end
end
context 'when the configuration is read within the response block' do
subject(:a_remounted_api) do
- Class.new(Grape::API) do
+ Class.new(described_class) do
get 'location' do
configuration[:some_value]
end
end
end