Sha256: a31f0216292bfdfe124c30fbe27e69cc7d5bd3cce399c309bde241d16d552b19

Contents?: true

Size: 1.74 KB

Versions: 1

Compression:

Stored size: 1.74 KB

Contents

require 'spec_helper'
require 'grape_entity'

describe GrapeEntityMatchers::DocumentMatcher do
  let(:documentation) do
    {
      type: String,
      desc: 'Some string',
      default: 'xyz',
      required: false,
      values: ['abc', 'xyz']
    }
  end
  before(:all) do
    class TestEntity < Grape::Entity
      expose :str, documentation: {
        type: String,
        desc: 'Some string',
        default: 'xyz',
        required: false,
        values: ['abc', 'xyz']
      }
      expose :no_doc
    end
  end

  subject(:entity) { TestEntity }

  context "ensure that the exposure matches the documentation" do
    it { is_expected.to document(:str).with(documentation) }
  end

  context "ensure individual keys of documentation" do
    it { is_expected.to document(:str).type(String) }
    it { is_expected.not_to document(:str).type(Fixnum) }

    it { is_expected.to document(:str).desc('Some string') }
    it { is_expected.not_to document(:str).desc('Some other string') }

    it { is_expected.to document(:str).default('xyz') }
    it { is_expected.not_to document(:str).default('abc') }

    it { is_expected.to document(:str).required(false) }
    it { is_expected.not_to document(:str).required(true) }

    it { is_expected.to document(:str).values(['abc', 'xyz']) }
    it { is_expected.not_to document(:str).values(['foo', 'bar']) }
  end

  context "ensure a combination of keys of documentation" do
    it { is_expected.to document(:str).type(String).desc('Some string') }
  end

  context "ensure that an exposure is not documented" do
    it { is_expected.to_not document(:no_doc) }
  end

  context "ensure that a specific documentation is not used" do
    it { is_expected.to_not document(:str).with(type: String, required: false) }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
grape-entity-matchers-1.2.0 spec/grape_entity_matchers/document_matcher_spec.rb