Sha256: 7788581e8aa4c2cd459229a291f34f9ea1af4ffba074d3393c7b13f29a74e2a3

Contents?: true

Size: 1.64 KB

Versions: 12

Compression:

Stored size: 1.64 KB

Contents

RSpec.describe Evil::Client::Resolver::Body, ".call" do
  subject { described_class.call schema, settings }

  let(:log)      { StringIO.new }
  let(:logger)   { Logger.new log }
  let(:settings) { double :my_settings, version: 77, logger: logger }

  let(:root_schema) do
    double :my_parent_schema,
           definitions: { body: proc { %W[v#{version}] } },
           parent: nil
  end

  let(:schema) do
    double :my_schema,
           definitions: { body: proc { { version: "v#{version}" } } },
           parent: root_schema
  end

  it "resolves body from a schema" do
    expect(subject).to eq version: "v77"
  end

  it "logs the result" do
    subject

    expect(log.string).to include described_class.name
    expect(log.string).to include "my_schema"
    expect(log.string).to include "my_settings"
    expect(log.string).to include "v77"
  end

  context "when logger level was set to INFO" do
    before { logger.level = Logger::INFO }

    it "skips logging" do
      expect { subject }.not_to change { log.string }
    end
  end

  context "when current schema not defines a body" do
    before { schema.definitions.delete :body }

    it "resolves body from a parent schema" do
      expect(subject).to eq %w[v77]
    end
  end

  context "when root body definitions was reloaded by nil" do
    before { schema.definitions[:body] = proc {} }

    it "resolves body to nil" do
      expect(subject).to be_nil
    end
  end

  context "when body not defined by any schema" do
    before { schema.definitions.delete :body }
    before { root_schema.definitions.delete :body }

    it "resolves body to nil" do
      expect(subject).to be_nil
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
evil-client-3.2.0 spec/unit/resolver/body_spec.rb
evil-client-3.1.0 spec/unit/resolver/body_spec.rb
evil-client-3.0.4 spec/unit/resolver/body_spec.rb
evil-client-3.0.3 spec/unit/resolver/body_spec.rb
evil-client-3.0.2 spec/unit/resolver/body_spec.rb
evil-client-3.0.1 spec/unit/resolver/body_spec.rb
evil-client-3.0.0 spec/unit/resolver/body_spec.rb
evil-client-2.1.1 spec/unit/resolver/body_spec.rb
evil-client-2.1.0 spec/unit/resolver/body_spec.rb
evil-client-2.0.0 spec/unit/resolver/body_spec.rb
evil-client-1.1.0 spec/unit/resolver/body_spec.rb
evil-client-1.0.0 spec/unit/resolver/body_spec.rb