File: callbacks_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 (47 lines) | stat: -rw-r--r-- 1,198 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
# frozen_string_literal: true

require 'spec_helper'

module Grape
  module DSL
    module CallbacksSpec
      class Dummy
        include Grape::DSL::Callbacks
      end
    end

    describe Callbacks do
      subject { Class.new(CallbacksSpec::Dummy) }

      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_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' do
        it 'adds a block to "after"' do
          expect(subject).to receive(:namespace_stackable).with(:afters, proc)
          subject.after(&proc)
        end
      end
    end
  end
end