Sha256: 92f92c89868fb0c43caccaed7bcde430aff8570e79952117ecaa80a2cf19c618

Contents?: true

Size: 1.75 KB

Versions: 23

Compression:

Stored size: 1.75 KB

Contents

# frozen_string_literal: true

require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")

describe Praxis::Trait do
  subject(:trait) do
    Praxis::Trait.new do
      description 'my awesome trait'

      routing do
        prefix '/:app_name'
      end

      response :something
      response :nothing

      # Double params to test "additive behavior"
      params do
        attribute :app_name, String
      end
      params do
        attribute :order, String,
                  description: 'Field to sort by.'
      end

      headers do
        header 'Authorization'
        key 'Header2', String, required: true, null: false
      end
    end
  end

  context 'describe' do
    subject(:describe) { trait.describe }

    its([:description]) { should eq('my awesome trait') }

    its(%i[responses something]) { should eq({}) }
    its(%i[responses nothing]) { should eq({}) }

    its(%i[params app_name type name]) { should eq 'String' }
    its(%i[params order type name]) { should eq 'String' }
    its(%i[routing prefix]) { should eq '/:app_name' }

    its([:headers, 'Header2']) { should include({ required: true, null: false }) }
    context 'using the special DSL syntax for headers' do
      subject(:dsl_header) { describe[:headers]['Authorization'] }
      its([:required]) { should be(true) }
      its([:null]) { should be_nil }
      its([:type]) { should eq({ id: 'Attributor-String', name: 'String', family: 'string' }) }
    end
  end

  context 'apply!' do
    let(:target) { double('Target') }
    it 'does' do
      expect(target).to receive(:routing).once
      expect(target).to receive(:response).twice
      expect(target).to receive(:params).twice
      expect(target).to receive(:headers).once
      subject.apply!(target)
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
praxis-2.0.0 spec/praxis/trait_spec.rb
praxis-2.0.pre.40 spec/praxis/trait_spec.rb
praxis-2.0.pre.39 spec/praxis/trait_spec.rb
praxis-2.0.pre.38 spec/praxis/trait_spec.rb
praxis-2.0.pre.37 spec/praxis/trait_spec.rb
praxis-2.0.pre.36 spec/praxis/trait_spec.rb
praxis-2.0.pre.35 spec/praxis/trait_spec.rb
praxis-2.0.pre.34 spec/praxis/trait_spec.rb
praxis-2.0.pre.33 spec/praxis/trait_spec.rb
praxis-2.0.pre.32 spec/praxis/trait_spec.rb
praxis-2.0.pre.31 spec/praxis/trait_spec.rb
praxis-2.0.pre.30 spec/praxis/trait_spec.rb
praxis-2.0.pre.29 spec/praxis/trait_spec.rb
praxis-2.0.pre.28 spec/praxis/trait_spec.rb
praxis-2.0.pre.27 spec/praxis/trait_spec.rb
praxis-2.0.pre.26 spec/praxis/trait_spec.rb
praxis-2.0.pre.25 spec/praxis/trait_spec.rb
praxis-2.0.pre.24 spec/praxis/trait_spec.rb
praxis-2.0.pre.23 spec/praxis/trait_spec.rb
praxis-2.0.pre.22 spec/praxis/trait_spec.rb