Sha256: 82f20937ece4f8086a0428fa7b8cac8d0a6d3648269ad60dd57a6ead7f82ba87

Contents?: true

Size: 1.67 KB

Versions: 20

Compression:

Stored size: 1.67 KB

Contents

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
      end

    end
  end

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

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

    its([:responses, :something]) { should eq Hash.new }
    its([:responses, :nothing]) { should eq Hash.new }

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

    its([:headers, "Header2"]) { should include({required: true}) }
    context 'using the special DSL syntax for headers' do
      subject(:dsl_header) { describe[:headers]["Authorization"] }
      its([:required]){ should be(true) }
      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

20 entries across 20 versions & 1 rubygems

Version Path
praxis-2.0.pre.17 spec/praxis/trait_spec.rb
praxis-2.0.pre.16 spec/praxis/trait_spec.rb
praxis-2.0.pre.15 spec/praxis/trait_spec.rb
praxis-2.0.pre.14 spec/praxis/trait_spec.rb
praxis-2.0.pre.13 spec/praxis/trait_spec.rb
praxis-2.0.pre.12 spec/praxis/trait_spec.rb
praxis-2.0.pre.11 spec/praxis/trait_spec.rb
praxis-2.0.pre.10 spec/praxis/trait_spec.rb
praxis-2.0.pre.9 spec/praxis/trait_spec.rb
praxis-2.0.pre.8 spec/praxis/trait_spec.rb
praxis-2.0.pre.7 spec/praxis/trait_spec.rb
praxis-2.0.pre.6 spec/praxis/trait_spec.rb
praxis-2.0.pre.5 spec/praxis/trait_spec.rb
praxis-2.0.pre.4 spec/praxis/trait_spec.rb
praxis-2.0.pre.3 spec/praxis/trait_spec.rb
praxis-2.0.pre.2 spec/praxis/trait_spec.rb
praxis-2.0.pre.1 spec/praxis/trait_spec.rb
praxis-0.22.pre.2 spec/praxis/trait_spec.rb
praxis-0.22.pre.1 spec/praxis/trait_spec.rb
praxis-0.21 spec/praxis/trait_spec.rb