File: headers_spec.rb

package info (click to toggle)
ruby-grape 1.6.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,156 kB
  • sloc: ruby: 25,265; makefile: 7
file content (64 lines) | stat: -rw-r--r-- 1,729 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# frozen_string_literal: true

require 'spec_helper'

module Grape
  module DSL
    module HeadersSpec
      class Dummy
        include Grape::DSL::Headers
      end
    end
    describe Headers do
      subject { HeadersSpec::Dummy.new }

      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

          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
        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
  end
end