-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Replace modules/classes declaration by anonymous modules/classes. * Rename validator spec with suffix validator_spec. Rubocop autocorrect * Fix RSpec/DescribeClass * Fix rubocop * Add CHANGELOG.md
- Loading branch information
1 parent
5b0066c
commit 277fe3e
Showing
34 changed files
with
1,951 additions
and
2,018 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,41 @@ | ||
# frozen_string_literal: true | ||
|
||
module Grape | ||
module DSL | ||
module CallbacksSpec | ||
class Dummy | ||
include Grape::DSL::Callbacks | ||
end | ||
end | ||
describe Grape::DSL::Callbacks do | ||
subject { dummy_class } | ||
|
||
describe Callbacks do | ||
subject { Class.new(CallbacksSpec::Dummy) } | ||
let(:dummy_class) do | ||
Class.new do | ||
include Grape::DSL::Callbacks | ||
end | ||
end | ||
|
||
let(:proc) { -> {} } | ||
let(:proc) { -> {} } | ||
|
||
describe '.before' do | ||
it 'adds a block to "before"' do | ||
expect(subject).to receive(:namespace_stackable).with(:befores, proc) | ||
subject.before(&proc) | ||
end | ||
end | ||
describe '.before' do | ||
it 'adds a block to "before"' do | ||
expect(subject).to receive(:namespace_stackable).with(:befores, proc) | ||
subject.before(&proc) | ||
end | ||
end | ||
|
||
describe '.before_validation' do | ||
it 'adds a block to "before_validation"' do | ||
expect(subject).to receive(:namespace_stackable).with(:before_validations, proc) | ||
subject.before_validation(&proc) | ||
end | ||
end | ||
describe '.before_validation' do | ||
it 'adds a block to "before_validation"' do | ||
expect(subject).to receive(:namespace_stackable).with(:before_validations, proc) | ||
subject.before_validation(&proc) | ||
end | ||
end | ||
|
||
describe '.after_validation' do | ||
it 'adds a block to "after_validation"' do | ||
expect(subject).to receive(:namespace_stackable).with(:after_validations, proc) | ||
subject.after_validation(&proc) | ||
end | ||
end | ||
describe '.after_validation' do | ||
it 'adds a block to "after_validation"' do | ||
expect(subject).to receive(:namespace_stackable).with(:after_validations, proc) | ||
subject.after_validation(&proc) | ||
end | ||
end | ||
|
||
describe '.after' do | ||
it 'adds a block to "after"' do | ||
expect(subject).to receive(:namespace_stackable).with(:afters, proc) | ||
subject.after(&proc) | ||
end | ||
end | ||
describe '.after' do | ||
it 'adds a block to "after"' do | ||
expect(subject).to receive(:namespace_stackable).with(:afters, proc) | ||
subject.after(&proc) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,59 @@ | ||
# frozen_string_literal: true | ||
|
||
module Grape | ||
module DSL | ||
module HeadersSpec | ||
class Dummy | ||
include Grape::DSL::Headers | ||
end | ||
describe Grape::DSL::Headers do | ||
subject { dummy_class.new } | ||
|
||
let(:dummy_class) do | ||
Class.new do | ||
include Grape::DSL::Headers | ||
end | ||
describe Headers do | ||
subject { HeadersSpec::Dummy.new } | ||
end | ||
|
||
let(:header_data) do | ||
{ 'first key' => 'First Value', | ||
'second key' => 'Second Value' } | ||
end | ||
|
||
context 'when headers are set' do | ||
describe '#header' do | ||
before do | ||
header_data.each { |k, v| subject.header(k, v) } | ||
end | ||
|
||
let(:header_data) do | ||
{ 'first key' => 'First Value', | ||
'second key' => 'Second Value' } | ||
describe 'get' do | ||
it 'returns a specifc value' do | ||
expect(subject.header['first key']).to eq 'First Value' | ||
expect(subject.header['second key']).to eq 'Second Value' | ||
end | ||
|
||
it 'returns all set headers' do | ||
expect(subject.header).to eq header_data | ||
expect(subject.headers).to eq header_data | ||
end | ||
end | ||
|
||
context 'when headers are set' do | ||
describe '#header' do | ||
before do | ||
header_data.each { |k, v| subject.header(k, v) } | ||
end | ||
|
||
describe 'get' do | ||
it 'returns a specifc value' do | ||
expect(subject.header['first key']).to eq 'First Value' | ||
expect(subject.header['second key']).to eq 'Second Value' | ||
end | ||
|
||
it 'returns all set headers' do | ||
expect(subject.header).to eq header_data | ||
expect(subject.headers).to eq header_data | ||
end | ||
end | ||
|
||
describe 'set' do | ||
it 'returns value' do | ||
expect(subject.header('third key', 'Third Value')) | ||
expect(subject.header['third key']).to eq 'Third Value' | ||
end | ||
end | ||
|
||
describe 'delete' do | ||
it 'deletes a header key-value pair' do | ||
expect(subject.header('first key')).to eq header_data['first key'] | ||
expect(subject.header).not_to have_key('first key') | ||
end | ||
end | ||
describe 'set' do | ||
it 'returns value' do | ||
expect(subject.header('third key', 'Third Value')) | ||
expect(subject.header['third key']).to eq 'Third Value' | ||
end | ||
end | ||
|
||
context 'when no headers are set' do | ||
describe '#header' do | ||
it 'returns nil' do | ||
expect(subject.header['first key']).to be_nil | ||
expect(subject.header('first key')).to be_nil | ||
end | ||
describe 'delete' do | ||
it 'deletes a header key-value pair' do | ||
expect(subject.header('first key')).to eq header_data['first key'] | ||
expect(subject.header).not_to have_key('first key') | ||
end | ||
end | ||
end | ||
end | ||
|
||
context 'when no headers are set' do | ||
describe '#header' do | ||
it 'returns nil' do | ||
expect(subject.header['first key']).to be_nil | ||
expect(subject.header('first key')).to be_nil | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.