Sha256: 7de81db624b69f31cce65d1431d4ec67045cf8ab7bd4d826e549c1ecd53a51b6

Contents?: true

Size: 1.63 KB

Versions: 22

Compression:

Stored size: 1.63 KB

Contents

require 'spec_helper'

module Grape
  module Presenters
    module PresenterSpec
      class Dummy
        include Grape::DSL::InsideRoute

        attr_reader :env, :request, :new_settings

        def initialize
          @env = {}
          @header = {}
          @new_settings = { namespace_inheritable: {}, namespace_stackable: {} }
        end
      end
    end

    describe Presenter do
      describe 'represent' do
        let(:object_mock) do
          Object.new
        end

        it 'represent object' do
          expect(Presenter.represent(object_mock)).to eq object_mock
        end
      end

      subject { PresenterSpec::Dummy.new }

      describe 'present' do
        let(:hash_mock) do
          { key: :value }
        end

        describe 'instance' do
          before do
            subject.present hash_mock, with: Grape::Presenters::Presenter
          end
          it 'presents dummy hash' do
            expect(subject.body).to eq hash_mock
          end
        end

        describe 'multiple presenter' do
          let(:hash_mock1) do
            { key1: :value1 }
          end

          let(:hash_mock2) do
            { key2: :value2 }
          end

          describe 'instance' do
            before do
              subject.present hash_mock1, with: Grape::Presenters::Presenter
              subject.present hash_mock2, with: Grape::Presenters::Presenter
            end

            it 'presents both dummy presenter' do
              expect(subject.body[:key1]).to eq hash_mock1[:key1]
              expect(subject.body[:key2]).to eq hash_mock2[:key2]
            end
          end
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 2 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/grape-1.2.5/spec/grape/presenters/presenter_spec.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/grape-1.2.5/spec/grape/presenters/presenter_spec.rb
grape-1.2.5 spec/grape/presenters/presenter_spec.rb
grape-1.2.4 spec/grape/presenters/presenter_spec.rb
grape-1.2.3 spec/grape/presenters/presenter_spec.rb
grape-1.2.2 spec/grape/presenters/presenter_spec.rb
grape-1.2.1 spec/grape/presenters/presenter_spec.rb
grape-1.2.0 spec/grape/presenters/presenter_spec.rb
grape-1.1.0 spec/grape/presenters/presenter_spec.rb
grape-1.0.3 spec/grape/presenters/presenter_spec.rb
grape-1.0.2 spec/grape/presenters/presenter_spec.rb
grape-1.0.1 spec/grape/presenters/presenter_spec.rb
grape-1.0.0 spec/grape/presenters/presenter_spec.rb
grape-0.19.2 spec/grape/presenters/presenter_spec.rb
grape-0.19.1 spec/grape/presenters/presenter_spec.rb
grape-0.19.0 spec/grape/presenters/presenter_spec.rb
grape-0.18.0 spec/grape/presenters/presenter_spec.rb
grape-0.17.0 spec/grape/presenters/presenter_spec.rb
grape-0.16.2 spec/grape/presenters/presenter_spec.rb
grape-0.16.1 spec/grape/presenters/presenter_spec.rb