repo stringlengths 5 92 | file_url stringlengths 80 287 | file_path stringlengths 5 197 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 15:37:27 2026-01-04 17:58:21 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/path_spec.rb | spec/grape/path_spec.rb | # frozen_string_literal: true
describe Grape::Path do
describe '#origin' do
context 'mount_path' do
it 'is not included when it is nil' do
path = described_class.new(nil, nil, mount_path: '/foo/bar')
expect(path.origin).to eql '/foo/bar'
end
it 'is included when it is not nil' ... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/api_remount_spec.rb | spec/grape/api_remount_spec.rb | # frozen_string_literal: true
require 'shared/versioning_examples'
describe Grape::API do
subject(:a_remounted_api) { Class.new(described_class) }
let(:root_api) { Class.new(described_class) }
let(:app) { root_api }
describe 'remounting an API' do
context 'with a defined route' do
before do
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/content_types_spec.rb | spec/grape/content_types_spec.rb | # frozen_string_literal: true
describe Grape::ContentTypes do
describe 'DEFAULTS' do
subject { described_class::DEFAULTS }
let(:expected_value) do
{
xml: 'application/xml',
serializable_hash: 'application/json',
json: 'application/json',
binary: 'application/octet-strea... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/named_api_spec.rb | spec/grape/named_api_spec.rb | # frozen_string_literal: true
describe Grape::API do
subject(:api_name) { NamedAPI.endpoints.last.options[:for].to_s }
let(:api) do
Class.new(Grape::API) do
get 'test' do
'response'
end
end
end
let(:name) { 'NamedAPI' }
before { stub_const(name, api) }
it 'can access the nam... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/request_spec.rb | spec/grape/request_spec.rb | # frozen_string_literal: true
describe Grape::Request do
let(:default_method) { Rack::GET }
let(:default_params) { {} }
let(:default_options) do
{
method: method,
params: params
}
end
let(:default_env) do
Rack::MockRequest.env_for('/', options)
end
let(:method) { default_method }
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/api_spec.rb | spec/grape/api_spec.rb | # frozen_string_literal: true
require 'shared/versioning_examples'
describe Grape::API do
subject { Class.new(described_class) }
let(:app) { subject }
describe '.prefix' do
it 'routes root through with the prefix' do
subject.prefix 'awesome/sauce'
subject.get do
'Hello there.'
en... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | true |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/validations_spec.rb | spec/grape/validations_spec.rb | # frozen_string_literal: true
describe Grape::Validations do
subject { Class.new(Grape::API) }
let(:app) { subject }
describe 'params' do
context 'optional' do
before do
subject.params do
optional :a_number, regexp: /^[0-9]+$/
optional :attachment, type: File
end
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | true |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/router_spec.rb | spec/grape/router_spec.rb | # frozen_string_literal: true
describe Grape::Router do
describe '.normalize_path' do
subject { described_class.normalize_path(path) }
context 'when no leading slash' do
let(:path) { 'foo%20bar%20baz' }
it { is_expected.to eq '/foo%20bar%20baz' }
end
context 'when path ends with slash'... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/loading_spec.rb | spec/grape/loading_spec.rb | # frozen_string_literal: true
describe Grape::API do
subject do
context = self
Class.new(Grape::API) do
format :json
mount context.combined_api => '/'
end
end
let(:jobs_api) do
Class.new(Grape::API) do
namespace :one do
namespace :two do
namespace :three do
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/parser_spec.rb | spec/grape/parser_spec.rb | # frozen_string_literal: true
describe Grape::Parser do
subject { described_class }
describe '.parser_for' do
let(:options) { {} }
it 'returns parser correctly' do
expect(subject.parser_for(:json)).to eq(Grape::Parser::Json)
end
context 'when parser is available' do
let(:parsers) do
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/util/media_type_spec.rb | spec/grape/util/media_type_spec.rb | # frozen_string_literal: true
RSpec.describe Grape::Util::MediaType do
shared_examples 'MediaType' do
it { is_expected.to eq(described_class.new(type: type, subtype: subtype)) }
end
describe '.parse' do
subject(:media_type) { described_class.parse(header) }
context 'when header blank?' do
let... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/util/inheritable_setting_spec.rb | spec/grape/util/inheritable_setting_spec.rb | # frozen_string_literal: true
describe Grape::Util::InheritableSetting do
before do
described_class.reset_global!
subject.inherit_from parent
end
let(:parent) do
described_class.new.tap do |settings|
settings.global[:global_thing] = :global_foo_bar
settings.namespace[:namespace_thing] = ... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/util/stackable_values_spec.rb | spec/grape/util/stackable_values_spec.rb | # frozen_string_literal: true
describe Grape::Util::StackableValues do
subject { described_class.new(parent) }
let(:parent) { described_class.new }
describe '#keys' do
it 'returns all keys' do
subject[:some_thing] = :foo_bar
subject[:some_thing_else] = :foo_bar
expect(subject.keys).to eq ... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/util/reverse_stackable_values_spec.rb | spec/grape/util/reverse_stackable_values_spec.rb | # frozen_string_literal: true
describe Grape::Util::ReverseStackableValues do
subject { described_class.new(parent) }
let(:parent) { described_class.new }
describe '#keys' do
it 'returns all keys' do
subject[:some_thing] = :foo_bar
subject[:some_thing_else] = :foo_bar
expect(subject.keys)... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/util/inheritable_values_spec.rb | spec/grape/util/inheritable_values_spec.rb | # frozen_string_literal: true
describe Grape::Util::InheritableValues do
subject { described_class.new(parent) }
let(:parent) { described_class.new }
describe '#delete' do
it 'deletes a key' do
subject[:some_thing] = :new_foo_bar
subject.delete :some_thing
expect(subject[:some_thing]).to ... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/util/registry_spec.rb | spec/grape/util/registry_spec.rb | # frozen_string_literal: true
describe Grape::Util::Registry do
# Create a test class that includes the Registry module
subject { test_registry_class.new }
let(:test_registry_class) do
Class.new do
include Grape::Util::Registry
# Public methods to expose private functionality for testing
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/params_builder/hash_spec.rb | spec/grape/params_builder/hash_spec.rb | # frozen_string_literal: true
describe Grape::ParamsBuilder::Hash do
subject { app }
let(:app) do
Class.new(Grape::API)
end
describe 'in an endpoint' do
describe '#params' do
before do
subject.params do
build_with :hash
end
subject.get do
params.clas... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/params_builder/hash_with_indifferent_access_spec.rb | spec/grape/params_builder/hash_with_indifferent_access_spec.rb | # frozen_string_literal: true
describe Grape::ParamsBuilder::HashWithIndifferentAccess do
subject { app }
let(:app) do
Class.new(Grape::API)
end
describe 'in an endpoint' do
describe '#params' do
before do
subject.params do
build_with :hash_with_indifferent_access
end
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/integration/rack_spec.rb | spec/grape/integration/rack_spec.rb | # frozen_string_literal: true
describe Rack do
describe 'from a Tempfile' do
subject { last_response.body }
let(:app) do
Class.new(Grape::API) do
format :json
params do
requires :file, type: File
end
post do
params[:file].then do |file|
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/integration/global_namespace_function_spec.rb | spec/grape/integration/global_namespace_function_spec.rb | # frozen_string_literal: true
# see https://github.com/ruby-grape/grape/issues/1348
def namespace
raise
end
describe Grape::API do
subject do
Class.new(Grape::API) do
format :json
get do
{ ok: true }
end
end
end
def app
subject
end
context 'with a global namespace ... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/integration/rack_sendfile_spec.rb | spec/grape/integration/rack_sendfile_spec.rb | # frozen_string_literal: true
describe Rack::Sendfile do
subject do
content_object = file_object
app = Class.new(Grape::API) do
use Rack::Sendfile, 'X-Accel-Redirect'
format :json
get do
if content_object.is_a?(String)
sendfile content_object
else
stream ... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/presenters/presenter_spec.rb | spec/grape/presenters/presenter_spec.rb | # frozen_string_literal: true
describe Grape::Presenters::Presenter do
subject { dummy_class.new }
let(:dummy_class) do
Class.new do
include Grape::DSL::InsideRoute
attr_reader :env, :request, :new_settings
def initialize
@env = {}
@header = {}
@new_settings = { nam... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/exceptions/missing_group_type_spec.rb | spec/grape/exceptions/missing_group_type_spec.rb | # frozen_string_literal: true
RSpec.describe Grape::Exceptions::MissingGroupType do
describe '#message' do
subject { described_class.new.message }
it { is_expected.to include 'group type is required' }
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/exceptions/invalid_formatter_spec.rb | spec/grape/exceptions/invalid_formatter_spec.rb | # frozen_string_literal: true
describe Grape::Exceptions::InvalidFormatter do
describe '#message' do
let(:error) do
described_class.new(String, 'xml')
end
it 'contains the problem in the message' do
expect(error.message).to include(
'cannot convert String to xml'
)
end
en... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/exceptions/invalid_accept_header_spec.rb | spec/grape/exceptions/invalid_accept_header_spec.rb | # frozen_string_literal: true
describe Grape::Exceptions::InvalidAcceptHeader do
shared_examples_for 'a valid request' do
it 'does return with status 200' do
expect(last_response.status).to eq 200
end
it 'does return the expected result' do
expect(last_response.body).to eq('beer received')
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/exceptions/unsupported_group_type_spec.rb | spec/grape/exceptions/unsupported_group_type_spec.rb | # frozen_string_literal: true
RSpec.describe Grape::Exceptions::UnsupportedGroupType do
subject { described_class.new }
describe '#message' do
subject { described_class.new.message }
it { is_expected.to include 'group type must be Array, Hash, JSON or Array[JSON]' }
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/exceptions/missing_mime_type_spec.rb | spec/grape/exceptions/missing_mime_type_spec.rb | # frozen_string_literal: true
describe Grape::Exceptions::MissingMimeType do
describe '#message' do
let(:error) do
described_class.new('new_json')
end
it 'contains the problem in the message' do
expect(error.message).to include 'missing mime type for new_json'
end
it 'contains the r... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/exceptions/invalid_versioner_option_spec.rb | spec/grape/exceptions/invalid_versioner_option_spec.rb | # frozen_string_literal: true
describe Grape::Exceptions::InvalidVersionerOption do
describe '#message' do
let(:error) do
described_class.new('headers')
end
it 'contains the problem in the message' do
expect(error.message).to include(
'unknown :using for versioner: headers'
)
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/exceptions/unknown_validator_spec.rb | spec/grape/exceptions/unknown_validator_spec.rb | # frozen_string_literal: true
describe Grape::Exceptions::UnknownValidator do
describe '#message' do
let(:error) do
described_class.new('gt_10')
end
it 'contains the problem in the message' do
expect(error.message).to include(
'unknown validator: gt_10'
)
end
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/exceptions/body_parse_errors_spec.rb | spec/grape/exceptions/body_parse_errors_spec.rb | # frozen_string_literal: true
describe Grape::Exceptions::ValidationErrors do
context 'api with rescue_from :all handler' do
subject { Class.new(Grape::API) }
before do
subject.rescue_from :all do |_e|
error! 'message was processed', 400
end
subject.params do
requires :beer... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/exceptions/base_spec.rb | spec/grape/exceptions/base_spec.rb | # frozen_string_literal: true
describe Grape::Exceptions::Base do
describe '#to_s' do
subject { described_class.new(message: message).to_s }
let(:message) { 'a_message' }
it { is_expected.to eq(message) }
end
describe '#message' do
subject { described_class.new(message: message).message }
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/exceptions/validation_errors_spec.rb | spec/grape/exceptions/validation_errors_spec.rb | # frozen_string_literal: true
describe Grape::Exceptions::ValidationErrors do
let(:validation_message) { 'FooBar is invalid' }
let(:validation_error) { instance_double Grape::Exceptions::Validation, params: [validation_message], message: '' }
context 'initialize' do
subject do
described_class.new(erro... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/exceptions/invalid_response_spec.rb | spec/grape/exceptions/invalid_response_spec.rb | # frozen_string_literal: true
describe Grape::Exceptions::InvalidResponse do
describe '#message' do
let(:error) { described_class.new }
it 'contains the problem in the message' do
expect(error.message).to include('Invalid response')
end
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/exceptions/validation_spec.rb | spec/grape/exceptions/validation_spec.rb | # frozen_string_literal: true
describe Grape::Exceptions::Validation do
it 'fails when params are missing' do
expect { described_class.new(message: 'presence') }.to raise_error(ArgumentError, /missing keyword:.+?params/)
end
context 'when message is a symbol' do
it 'stores message_key' do
expect(d... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/middleware/exception_spec.rb | spec/grape/middleware/exception_spec.rb | # frozen_string_literal: true
describe Grape::Middleware::Error do
let(:exception_app) do
Class.new do
class << self
def call(_env)
raise 'rain!'
end
end
end
end
let(:other_exception_app) do
Class.new do
class << self
def call(_env)
raise... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/middleware/formatter_spec.rb | spec/grape/middleware/formatter_spec.rb | # frozen_string_literal: true
describe Grape::Middleware::Formatter do
subject { described_class.new(app) }
before { allow(subject).to receive(:dup).and_return(subject) }
let(:body) { { 'foo' => 'bar' } }
let(:app) { ->(_env) { [200, {}, [body]] } }
context 'serialization' do
let(:body) { { 'abc' => '... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/middleware/versioner_spec.rb | spec/grape/middleware/versioner_spec.rb | # frozen_string_literal: true
describe Grape::Middleware::Versioner do
subject { described_class.using(strategy) }
context 'when :path' do
let(:strategy) { :path }
it { is_expected.to eq(Grape::Middleware::Versioner::Path) }
end
context 'when :header' do
let(:strategy) { :header }
it { is_e... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/middleware/base_spec.rb | spec/grape/middleware/base_spec.rb | # frozen_string_literal: true
describe Grape::Middleware::Base do
subject { described_class.new(blank_app) }
let(:blank_app) { ->(_) { [200, {}, 'Hi there.'] } }
before do
# Keep it one object for testing.
allow(subject).to receive(:dup).and_return(subject)
end
it 'has the app as an accessor' do
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/middleware/stack_spec.rb | spec/grape/middleware/stack_spec.rb | # frozen_string_literal: true
describe Grape::Middleware::Stack do
subject { described_class.new }
let(:foo_middleware) { Class.new }
let(:bar_middleware) { Class.new }
let(:block_middleware) do
Class.new do
attr_reader :block
def initialize(&block)
@block = block
end
end
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/middleware/error_spec.rb | spec/grape/middleware/error_spec.rb | # frozen_string_literal: true
describe Grape::Middleware::Error do
let(:error_entity) do
Class.new(Grape::Entity) do
expose :code
expose :static
def static
'static text'
end
end
end
let(:err_app) do
Class.new do
class << self
attr_accessor :error, :forma... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/middleware/globals_spec.rb | spec/grape/middleware/globals_spec.rb | # frozen_string_literal: true
describe Grape::Middleware::Globals do
subject { described_class.new(blank_app) }
before { allow(subject).to receive(:dup).and_return(subject) }
let(:blank_app) { ->(_env) { [200, {}, 'Hi there.'] } }
it 'calls through to the app' do
expect(subject.call({})).to eq([200, {},... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/middleware/auth/dsl_spec.rb | spec/grape/middleware/auth/dsl_spec.rb | # frozen_string_literal: true
describe Grape::Middleware::Auth::DSL do
subject { Class.new(Grape::API) }
let(:block) { -> {} }
let(:settings) do
{
opaque: 'secret',
proc: block,
realm: 'API Authorization',
type: :http_digest
}
end
describe '.auth' do
it 'sets auth parame... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/middleware/auth/strategies_spec.rb | spec/grape/middleware/auth/strategies_spec.rb | # frozen_string_literal: true
describe Grape::Middleware::Auth::Strategies do
describe 'Basic Auth' do
let(:app) do
proc = ->(u, p) { u && p && u == p }
Rack::Builder.app do
use Grape::Middleware::Error
use(Grape::Middleware::Auth::Base, type: :http_basic, proc: proc)
run ->(_... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/middleware/auth/base_spec.rb | spec/grape/middleware/auth/base_spec.rb | # frozen_string_literal: true
describe Grape::Middleware::Auth::Base do
subject do
Class.new(Grape::API) do
http_basic realm: 'my_realm' do |user, password|
user && password && user == password
end
get '/authorized' do
'DONE'
end
end
end
let(:app) { subject }
i... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/middleware/versioner/path_spec.rb | spec/grape/middleware/versioner/path_spec.rb | # frozen_string_literal: true
describe Grape::Middleware::Versioner::Path do
subject { described_class.new(app, **options) }
let(:app) { ->(env) { [200, env, env[Grape::Env::API_VERSION]] } }
let(:options) { {} }
it 'sets the API version based on the first path' do
expect(subject.call(Rack::PATH_INFO => ... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/middleware/versioner/header_spec.rb | spec/grape/middleware/versioner/header_spec.rb | # frozen_string_literal: true
describe Grape::Middleware::Versioner::Header do
subject { described_class.new(app, **@options) }
let(:app) { ->(env) { [200, env, env] } }
before do
@options = {
version_options: {
using: :header,
vendor: 'vendor'
}
}
end
context 'api.type... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/middleware/versioner/param_spec.rb | spec/grape/middleware/versioner/param_spec.rb | # frozen_string_literal: true
describe Grape::Middleware::Versioner::Param do
subject { described_class.new(app, **options) }
let(:app) { ->(env) { [200, env, env[Grape::Env::API_VERSION]] } }
let(:options) { {} }
it 'sets the API version based on the default param (apiver)' do
env = Rack::MockRequest.en... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/middleware/versioner/accept_version_header_spec.rb | spec/grape/middleware/versioner/accept_version_header_spec.rb | # frozen_string_literal: true
describe Grape::Middleware::Versioner::AcceptVersionHeader do
subject { described_class.new(app, **@options) }
let(:app) { ->(env) { [200, env, env] } }
before do
@options = {
version_options: {
using: :accept_version_header
}
}
end
describe '#bad ... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/dsl/routing_spec.rb | spec/grape/dsl/routing_spec.rb | # frozen_string_literal: true
describe Grape::DSL::Routing do
subject { dummy_class }
let(:dummy_class) do
Class.new do
extend Grape::DSL::Routing
extend Grape::DSL::Settings
extend Grape::DSL::Validations
class << self
attr_reader :instance, :base
attr_accessor :confi... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/dsl/desc_spec.rb | spec/grape/dsl/desc_spec.rb | # frozen_string_literal: true
describe Grape::DSL::Desc do
subject { dummy_class }
let(:dummy_class) do
Class.new do
extend Grape::DSL::Desc
extend Grape::DSL::Settings
end
end
describe '.desc' do
it 'sets a description' do
desc_text = 'The description'
options = { message... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/dsl/callbacks_spec.rb | spec/grape/dsl/callbacks_spec.rb | # frozen_string_literal: true
describe Grape::DSL::Callbacks do
subject { dummy_class }
let(:dummy_class) do
Class.new do
extend Grape::DSL::Settings
extend Grape::DSL::Callbacks
end
end
let(:proc) { -> {} }
describe '.before' do
it 'adds a block to "before"' do
subject.befor... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/dsl/parameters_spec.rb | spec/grape/dsl/parameters_spec.rb | # frozen_string_literal: true
describe Grape::DSL::Parameters do
subject { dummy_class.new }
let(:dummy_class) do
Class.new do
include Grape::DSL::Parameters
attr_accessor :api, :element, :parent
def initialize
@validate_attributes = []
end
def validate_attributes(*arg... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/dsl/request_response_spec.rb | spec/grape/dsl/request_response_spec.rb | # frozen_string_literal: true
describe Grape::DSL::RequestResponse do
subject { dummy_class }
let(:dummy_class) do
Class.new do
extend Grape::DSL::RequestResponse
extend Grape::DSL::Settings
end
end
let(:c_type) { 'application/json' }
let(:format) { 'txt' }
describe '.default_format'... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/dsl/middleware_spec.rb | spec/grape/dsl/middleware_spec.rb | # frozen_string_literal: true
describe Grape::DSL::Middleware do
subject { dummy_class }
let(:dummy_class) do
Class.new do
extend Grape::DSL::Middleware
extend Grape::DSL::Settings
end
end
let(:proc) { -> {} }
let(:foo_middleware) { Class.new }
let(:bar_middleware) { Class.new }
de... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/dsl/validations_spec.rb | spec/grape/dsl/validations_spec.rb | # frozen_string_literal: true
describe Grape::DSL::Validations do
subject { dummy_class }
let(:dummy_class) do
Class.new do
extend Grape::DSL::Settings
extend Grape::DSL::Validations
end
end
describe '.params' do
subject { dummy_class.params { :my_block } }
it 'creates a proper G... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/dsl/settings_spec.rb | spec/grape/dsl/settings_spec.rb | # frozen_string_literal: true
describe Grape::DSL::Settings do
subject { dummy_class.new }
let(:dummy_class) do
Class.new do
include Grape::DSL::Settings
def with_namespace(&block)
within_namespace(&block)
end
def reset_validations!; end
end
end
describe '#global_set... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/dsl/headers_spec.rb | spec/grape/dsl/headers_spec.rb | # frozen_string_literal: true
describe Grape::DSL::Headers do
subject { dummy_class.new }
let(:dummy_class) do
Class.new do
include Grape::DSL::Headers
end
end
let(:header_data) do
{ 'first key' => 'First Value',
'second key' => 'Second Value' }
end
context 'when headers are set'... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/dsl/logger_spec.rb | spec/grape/dsl/logger_spec.rb | # frozen_string_literal: true
describe Grape::DSL::Logger do
let(:dummy_logger) do
Class.new do
extend Grape::DSL::Logger
extend Grape::DSL::Settings
end
end
describe '.logger' do
context 'when setting a logger' do
subject { dummy_logger.logger :my_logger }
it { is_expected.... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/dsl/inside_route_spec.rb | spec/grape/dsl/inside_route_spec.rb | # frozen_string_literal: true
describe Grape::DSL::InsideRoute do
subject { dummy_class.new }
let(:dummy_class) do
Class.new do
include Grape::DSL::InsideRoute
include Grape::DSL::Settings
attr_reader :env, :request, :new_settings
def initialize
@env = {}
@header = {}... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/dsl/helpers_spec.rb | spec/grape/dsl/helpers_spec.rb | # frozen_string_literal: true
describe Grape::DSL::Helpers do
subject { dummy_class }
let(:dummy_class) do
Class.new do
extend Grape::DSL::Helpers
extend Grape::DSL::Settings
def self.mods
inheritable_setting.namespace_stackable[:helpers]
end
def self.first_mod
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/api/mount_and_helpers_order_spec.rb | spec/grape/api/mount_and_helpers_order_spec.rb | # frozen_string_literal: true
describe Grape::API do
describe 'rescue_from' do
context 'when the API is mounted AFTER defining the class rescue_from handler' do
let(:api_rescue_from) do
Class.new(Grape::API) do
rescue_from :all do
error!({ type: 'all' }, 404)
end
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/api/shared_helpers_exactly_one_of_spec.rb | spec/grape/api/shared_helpers_exactly_one_of_spec.rb | # frozen_string_literal: true
describe Grape::API::Helpers do
let(:app) do
Class.new(Grape::API) do
helpers Module.new do
extend Grape::API::Helpers
params :drink do
optional :beer
optional :wine
exactly_one_of :beer, :wine
end
end
format :... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/api/inherited_helpers_spec.rb | spec/grape/api/inherited_helpers_spec.rb | # frozen_string_literal: true
describe Grape::API::Helpers do
let(:user) { 'Miguel Caneo' }
let(:id) { '42' }
let(:api_super_class) do
Class.new(Grape::API) do
helpers do
params(:superclass_params) { requires :id, type: String }
def current_user
params[:user]
end
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/api/required_parameters_with_invalid_method_spec.rb | spec/grape/api/required_parameters_with_invalid_method_spec.rb | # frozen_string_literal: true
describe Grape::Endpoint do
subject { Class.new(Grape::API) }
def app
subject
end
before do
subject.namespace do
params do
requires :id, desc: 'Identifier.'
end
get ':id' do
end
end
end
context 'post' do
it '405' do
post... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/api/namespace_parameters_in_route_spec.rb | spec/grape/api/namespace_parameters_in_route_spec.rb | # frozen_string_literal: true
describe Grape::Endpoint do
subject { Class.new(Grape::API) }
def app
subject
end
before do
subject.namespace :me do
namespace :pending do
get '/' do
'banana'
end
end
put ':id' do
params[:id]
end
end
end
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/api/mount_and_rescue_from_spec.rb | spec/grape/api/mount_and_rescue_from_spec.rb | # frozen_string_literal: true
describe Grape::API do
context 'when multiple classes defines the same rescue_from' do
let(:an_api) do
Class.new(Grape::API) do
rescue_from ZeroDivisionError do
error!({ type: 'an-api-zero' }, 404)
end
get '/an-api' do
{ count: 1 / ... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/api/parameters_modification_spec.rb | spec/grape/api/parameters_modification_spec.rb | # frozen_string_literal: true
describe Grape::Endpoint do
subject { Class.new(Grape::API) }
def app
subject
end
before do
subject.namespace :test do
params do
optional :foo, default: +'-abcdef'
end
get do
params[:foo].slice!(0)
params[:foo]
end
end
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/api/patch_method_helpers_spec.rb | spec/grape/api/patch_method_helpers_spec.rb | # frozen_string_literal: true
describe Grape::API::Helpers do
let(:patch_public) do
Class.new(Grape::API) do
format :json
version 'public-v1', using: :header, vendor: 'grape'
get do
{ ok: 'public' }
end
end
end
let(:auth_methods) do
Module.new do
def authenticat... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/api/documentation_spec.rb | spec/grape/api/documentation_spec.rb | # frozen_string_literal: true
describe Grape::API do
subject { Class.new(described_class) }
let(:app) { subject }
context 'an endpoint with documentation' do
it 'documents parameters' do
subject.params do
requires 'price', type: Float, desc: 'Sales price'
end
subject.get '/'
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/api/optional_parameters_in_route_spec.rb | spec/grape/api/optional_parameters_in_route_spec.rb | # frozen_string_literal: true
describe Grape::Endpoint do
subject { Class.new(Grape::API) }
def app
subject
end
before do
subject.namespace :api do
get ':id(/:ext)' do
[params[:id], params[:ext]].compact.join('/')
end
put ':id' do
params[:id]
end
end
end... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/api/nested_helpers_spec.rb | spec/grape/api/nested_helpers_spec.rb | # frozen_string_literal: true
describe Grape::API::Helpers do
let(:helper_methods) do
Module.new do
extend Grape::API::Helpers
def current_user
@current_user ||= params[:current_user]
end
end
end
let(:nested) do
context = self
Class.new(Grape::API) do
resource :l... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/api/recognize_path_spec.rb | spec/grape/api/recognize_path_spec.rb | # frozen_string_literal: true
describe Grape::API do
describe '.recognize_path' do
subject { Class.new(described_class) }
it 'fetches endpoint by given path' do
subject.get('/foo/:id') {}
subject.get('/bar/:id') {}
subject.get('/baz/:id') {}
actual = subject.recognize_path('/bar/123... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/api/required_parameters_in_route_spec.rb | spec/grape/api/required_parameters_in_route_spec.rb | # frozen_string_literal: true
describe Grape::Endpoint do
subject { Class.new(Grape::API) }
def app
subject
end
before do
subject.namespace :api do
get ':id' do
[params[:id], params[:ext]].compact.join('/')
end
put ':something_id' do
params[:something_id]
end
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/api/mounted_helpers_inheritance_spec.rb | spec/grape/api/mounted_helpers_inheritance_spec.rb | # frozen_string_literal: true
describe Grape::API do
context 'when mounting a child API that inherits helpers from parent API' do
let(:child_api) do
Class.new(Grape::API) do
get '/test' do
parent_helper
end
end
end
let(:parent_api) do
context = self
Clas... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/api/instance_spec.rb | spec/grape/api/instance_spec.rb | # frozen_string_literal: true
require 'shared/versioning_examples'
describe Grape::API::Instance do
subject(:an_instance) do
Class.new(Grape::API::Instance) do
namespace :some_namespace do
get 'some_endpoint' do
'success'
end
end
end
end
let(:root_api) do
to_mo... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/api/custom_validations_spec.rb | spec/grape/api/custom_validations_spec.rb | # frozen_string_literal: true
describe Grape::Validations do
describe 'using a custom length validator' do
subject do
Class.new(Grape::API) do
params do
requires :text, default_length: 140
end
get do
'bacon'
end
end
end
let(:default_length_... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/api/routes_with_requirements_spec.rb | spec/grape/api/routes_with_requirements_spec.rb | # frozen_string_literal: true
describe Grape::Endpoint do
subject { Class.new(Grape::API) }
def app
subject
end
context 'get' do
it 'routes to a namespace param with dots' do
subject.namespace ':ns_with_dots', requirements: { ns_with_dots: %r{[^/]+} } do
get '/' do
params[:ns_... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/api/deeply_included_options_spec.rb | spec/grape/api/deeply_included_options_spec.rb | # frozen_string_literal: true
describe Grape::API do
let(:app) do
main_api = api
Class.new(Grape::API) do
mount main_api
end
end
let(:api) do
deeply_included_options = options
Class.new(Grape::API) do
include deeply_included_options
resource :users do
get do
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/api/defines_boolean_in_params_spec.rb | spec/grape/api/defines_boolean_in_params_spec.rb | # frozen_string_literal: true
describe Grape::API::Instance do
describe 'boolean constant' do
let(:app) do
Class.new(Grape::API) do
params do
requires :message, type: Grape::API::Boolean
end
post :echo do
{ class: params[:message].class.name, value: params[:messa... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/api/shared_helpers_spec.rb | spec/grape/api/shared_helpers_spec.rb | # frozen_string_literal: true
describe Grape::API::Helpers do
subject do
shared_params = Module.new do
extend Grape::API::Helpers
params :pagination do
optional :page, type: Integer
optional :size, type: Integer
end
end
Class.new(Grape::API) do
helpers shared_par... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/api/invalid_format_spec.rb | spec/grape/api/invalid_format_spec.rb | # frozen_string_literal: true
describe Grape::Endpoint do
subject { Class.new(Grape::API) }
def app
subject
end
before do
subject.namespace do
format :json
content_type :json, 'application/json'
params do
requires :id, desc: 'Identifier.'
end
get ':id' do
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/validations/types_spec.rb | spec/grape/validations/types_spec.rb | # frozen_string_literal: true
describe Grape::Validations::Types do
let(:foo_type) do
Class.new do
def self.parse(_); end
end
end
let(:bar_type) do
Class.new do
def self.parse; end
end
end
describe '::primitive?' do
[
Integer, Float, Numeric, BigDecimal,
Grape::AP... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/validations/multiple_attributes_iterator_spec.rb | spec/grape/validations/multiple_attributes_iterator_spec.rb | # frozen_string_literal: true
describe Grape::Validations::MultipleAttributesIterator do
describe '#each' do
subject(:iterator) { described_class.new(validator, scope, params) }
let(:scope) { Grape::Validations::ParamsScope.new(api: Class.new(Grape::API)) }
let(:validator) { double(attrs: %i[first secon... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/validations/params_scope_spec.rb | spec/grape/validations/params_scope_spec.rb | # frozen_string_literal: true
describe Grape::Validations::ParamsScope do
subject do
Class.new(Grape::API)
end
def app
subject
end
context 'when using custom types' do
let(:custom_type) do
Class.new do
attr_reader :value
def self.parse(value)
raise if value == '... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | true |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/validations/single_attribute_iterator_spec.rb | spec/grape/validations/single_attribute_iterator_spec.rb | # frozen_string_literal: true
describe Grape::Validations::SingleAttributeIterator do
describe '#each' do
subject(:iterator) { described_class.new(validator, scope, params) }
let(:scope) { Grape::Validations::ParamsScope.new(api: Class.new(Grape::API)) }
let(:validator) { double(attrs: %i[first second])... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/validations/params_documentation_spec.rb | spec/grape/validations/params_documentation_spec.rb | # frozen_string_literal: true
describe Grape::Validations::ParamsDocumentation do
subject { klass.new(api_double) }
let(:api_double) do
Class.new do
include Grape::DSL::Settings
end.new
end
let(:klass) do
Class.new do
include Grape::Validations::ParamsDocumentation
attr_accesso... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/validations/validators/regexp_validator_spec.rb | spec/grape/validations/validators/regexp_validator_spec.rb | # frozen_string_literal: true
describe Grape::Validations::Validators::RegexpValidator do
let_it_be(:app) do
Class.new(Grape::API) do
default_format :json
resources :custom_message do
params do
requires :name, regexp: { value: /^[a-z]+$/, message: 'format is invalid' }
end
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/validations/validators/contract_scope_validator_spec.rb | spec/grape/validations/validators/contract_scope_validator_spec.rb | # frozen_string_literal: true
describe Grape::Validations::Validators::ContractScopeValidator do
describe '.inherits' do
subject { described_class }
it { is_expected.to be < Grape::Validations::Validators::Base }
end
end
| ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/validations/validators/coerce_validator_spec.rb | spec/grape/validations/validators/coerce_validator_spec.rb | # frozen_string_literal: true
describe Grape::Validations::Validators::CoerceValidator do
subject { Class.new(Grape::API) }
let(:app) { subject }
describe 'coerce' do
let(:secure_uri_only) do
Class.new do
def self.parse(value)
URI.parse(value)
end
def self.parsed?(v... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | true |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/validations/validators/length_validator_spec.rb | spec/grape/validations/validators/length_validator_spec.rb | # frozen_string_literal: true
describe Grape::Validations::Validators::LengthValidator do
let_it_be(:app) do
Class.new(Grape::API) do
params do
requires :list, length: { min: 2, max: 3 }
end
post 'with_min_max' do
end
params do
requires :list, type: [Integer], lengt... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/validations/validators/mutually_exclusive_spec.rb | spec/grape/validations/validators/mutually_exclusive_spec.rb | # frozen_string_literal: true
describe Grape::Validations::Validators::MutuallyExclusiveValidator do
let_it_be(:app) do
Class.new(Grape::API) do
rescue_from Grape::Exceptions::ValidationErrors do |e|
error!(e.errors.transform_keys! { |key| key.join(',') }, 400)
end
params do
op... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/validations/validators/values_validator_spec.rb | spec/grape/validations/validators/values_validator_spec.rb | # frozen_string_literal: true
describe Grape::Validations::Validators::ValuesValidator do
let(:values_model) do
Class.new do
class << self
def values
@values ||= []
[default_values + @values].flatten.uniq
end
def add_value(value)
@values ||= []
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/validations/validators/at_least_one_of_validator_spec.rb | spec/grape/validations/validators/at_least_one_of_validator_spec.rb | # frozen_string_literal: true
describe Grape::Validations::Validators::AtLeastOneOfValidator do
let_it_be(:app) do
Class.new(Grape::API) do
rescue_from Grape::Exceptions::ValidationErrors do |e|
error!(e.errors.transform_keys! { |key| key.join(',') }, 400)
end
params do
optiona... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/validations/validators/presence_validator_spec.rb | spec/grape/validations/validators/presence_validator_spec.rb | # frozen_string_literal: true
describe Grape::Validations::Validators::PresenceValidator do
subject do
Class.new(Grape::API) do
format :json
end
end
def app
subject
end
context 'without validation' do
before do
subject.resource :bacons do
get do
'All the bacon'... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/validations/validators/same_as_validator_spec.rb | spec/grape/validations/validators/same_as_validator_spec.rb | # frozen_string_literal: true
describe Grape::Validations::Validators::SameAsValidator do
let_it_be(:app) do
Class.new(Grape::API) do
params do
requires :password
requires :password_confirmation, same_as: :password
end
post do
end
params do
requires :passwor... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/validations/validators/exactly_one_of_validator_spec.rb | spec/grape/validations/validators/exactly_one_of_validator_spec.rb | # frozen_string_literal: true
describe Grape::Validations::Validators::ExactlyOneOfValidator do
let_it_be(:app) do
Class.new(Grape::API) do
rescue_from Grape::Exceptions::ValidationErrors do |e|
error!(e.errors.transform_keys! { |key| key.join(',') }, 400)
end
params do
optiona... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/validations/validators/all_or_none_validator_spec.rb | spec/grape/validations/validators/all_or_none_validator_spec.rb | # frozen_string_literal: true
describe Grape::Validations::Validators::AllOrNoneOfValidator do
let_it_be(:app) do
Class.new(Grape::API) do
rescue_from Grape::Exceptions::ValidationErrors do |e|
error!(e.errors.transform_keys! { |key| key.join(',') }, 400)
end
params do
optional... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/validations/validators/except_values_validator_spec.rb | spec/grape/validations/validators/except_values_validator_spec.rb | # frozen_string_literal: true
describe Grape::Validations::Validators::ExceptValuesValidator do
describe 'IncompatibleOptionValues' do
subject { api }
context 'when a default value is set' do
let(:api) do
ev = except_values
dv = default_value
Class.new(Grape::API) do
... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/validations/validators/allow_blank_validator_spec.rb | spec/grape/validations/validators/allow_blank_validator_spec.rb | # frozen_string_literal: true
describe Grape::Validations::Validators::AllowBlankValidator do
let_it_be(:app) do
Class.new(Grape::API) do
default_format :json
params do
requires :name, allow_blank: false
end
get '/disallow_blank'
params do
optional :name, type: Str... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
ruby-grape/grape | https://github.com/ruby-grape/grape/blob/17fb0cf64296e9c9c968ea7b62f7614538070be4/spec/grape/validations/validators/default_validator_spec.rb | spec/grape/validations/validators/default_validator_spec.rb | # frozen_string_literal: true
describe Grape::Validations::Validators::DefaultValidator do
let_it_be(:app) do
Class.new(Grape::API) do
default_format :json
params do
optional :id
optional :type, default: 'default-type'
end
get '/' do
{ id: params[:id], type: param... | ruby | MIT | 17fb0cf64296e9c9c968ea7b62f7614538070be4 | 2026-01-04T15:38:22.454413Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.