Sha256: e6873f154d635b423189344e908b7cb179ed7303432cdd28c3a49553aaee4874

Contents?: true

Size: 1.51 KB

Versions: 6

Compression:

Stored size: 1.51 KB

Contents

require 'spec_helper'

RSpec.describe JsonSchemaRails::Loaders::Directory do
  let(:loader) { JsonSchemaRails::Loaders::Directory.new(TEST_SCHEMAS_DIR) }

  describe "#load_schema" do
    subject { loader.load_schema(schema_name) }

    context "with .yml file" do
      let(:schema_name) { "posts/create" }
      it { should be_a JsonSchema::Schema }
    end

    context "with .yaml file" do
      let(:schema_name) { "posts/update" }
      it { should be_a JsonSchema::Schema }
    end

    context "with .json file" do
      let(:schema_name) { "posts/search" }
      it { should be_a JsonSchema::Schema }
    end

    context "with nonexist file" do
      let(:schema_name) { "posts/unknown" }
      it { should be_nil }
    end

    context "when extname specified" do
      before { loader.extnames = ".json" }

      context "with specified extname file" do
        let(:schema_name) { "posts/search" }
        it { should be_a JsonSchema::Schema }
      end

      context "with not specified extname file" do
        let(:schema_name) { "posts/create" }
        it { should be_nil }
      end
    end
  end

  describe "#load_schema!" do
    subject { -> { loader.load_schema!(schema_name) } }

    context "with exist file" do
      let(:schema_name) { "posts/create" }
      it "returns schema" do
        expect(subject.call).to be_a JsonSchema::Schema
      end
    end

    context "with nonexist file" do
      let(:schema_name) { "posts/unknown" }
      it { should raise_error JsonSchemaRails::SchemaNotFound }
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
json_schema_rails-0.2.1 spec/lib/json_schema_rails/loaders/directory_spec.rb
json_schema_rails-0.2.0 spec/lib/json_schema_rails/loaders/directory_spec.rb
json_schema_rails-0.1.0 spec/lib/json_schema_rails/loaders/directory_spec.rb
json_schema_rails-0.0.3 spec/lib/json_schema_rails/loaders/directory_spec.rb
json_schema_rails-0.0.2 spec/lib/json_schema_rails/loaders/directory_spec.rb
json_schema_rails-0.0.1 spec/lib/json_schema_rails/loaders/directory_spec.rb