Sha256: 2b9ab6377fd24f08a3c332e3a521b1265da0d8bc28bcb5b90adf4833f030c06b

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

require 'spec_helper'

module Grape
  module DSL
    module HelpersSpec
      class Dummy
        include Grape::DSL::Helpers

        def self.settings
          @settings ||= Grape::Util::HashStack.new
        end

        def self.set(_, mod)
          @mod = mod
        end

        # rubocop:disable TrivialAccessors
        def self.mod
          @mod
        end
        # rubocop:enable TrivialAccessors
      end
    end
    describe Helpers do
      subject { Class.new(HelpersSpec::Dummy) }
      let(:proc) do
        ->(*) do
          def test
            :test
          end
        end
      end

      describe '.helpers' do
        it 'adds a module with the given block' do
          expect(subject).to receive(:set).with(:helpers, kind_of(Grape::DSL::Helpers::BaseHelper)).and_call_original
          subject.helpers(&proc)

          expect(subject.mod.instance_methods).to include(:test)
        end

        it 'uses provided modules' do
          mod = Module.new

          expect(subject).to receive(:set).with(:helpers, kind_of(Grape::DSL::Helpers::BaseHelper)).and_call_original
          subject.helpers(mod, &proc)

          expect(subject.mod).not_to eq mod
          expect(subject.mod).to include mod
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
grape-0.9.0 spec/grape/dsl/helpers_spec.rb