Sha256: 6a0fc8c6fcd48f5afcda9c181ee09355049b96f0f7d78a455a0de458901cd177

Contents?: true

Size: 1.65 KB

Versions: 1

Compression:

Stored size: 1.65 KB

Contents

# frozen_string_literal: true

require "spec_helper"

RSpec.describe RSpec::Grape::Entity::Matchers::HaveRootMatcher do
  include RSpec::Grape::Entity::Matchers::HaveRootMatcher

  context "when root is not defined" do
    let(:described_class) do
      Class.new Grape::Entity
    end

    it { expect(described_class).to have_root(nil) }
    it { expect(described_class).to have_root(nil).with_singular(nil) }
    it { expect(described_class).not_to have_root("tests") }
    it { expect(described_class).not_to have_root("tests").with_singular(nil) }
    it { expect(described_class).not_to have_root("tests").with_singular("test") }
  end

  context "when collection root is only defined" do
    let(:described_class) do
      Class.new Grape::Entity do
        root "tests"
      end
    end

    it { expect(described_class).not_to have_root(nil) }
    it { expect(described_class).not_to have_root(nil).with_singular(nil) }
    it { expect(described_class).to have_root("tests") }
    it { expect(described_class).to have_root("tests").with_singular(nil) }
    it { expect(described_class).not_to have_root("tests").with_singular("test") }
  end

  context "when both root and collection_root is defined" do
    let(:described_class) do
      Class.new Grape::Entity do
        root "tests", "test"
      end
    end

    it { expect(described_class).not_to have_root(nil) }
    it { expect(described_class).not_to have_root(nil).with_singular(nil) }
    it { expect(described_class).not_to have_root("tests") }
    it { expect(described_class).not_to have_root("tests").with_singular(nil) }
    it { expect(described_class).to have_root("tests").with_singular("test") }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rspec-grape-entity-0.1.0 spec/matchers/have_root_matcher_spec.rb