Sha256: c24f6a58165ac7cd59c1bdb4693bd0773fd671a98e42a6f8595fb0889d3682bb

Contents?: true

Size: 1.53 KB

Versions: 8

Compression:

Stored size: 1.53 KB

Contents

require_relative '../spec_helper'

describe Barometer::Query::Format do
  def clear_formats
    @formats_cache = Barometer::Query::Format.formats
    Barometer::Query::Format.formats = []
  end

  def reset_formats
    Barometer::Query::Format.formats = @formats_cache
  end

  describe ".register" do
    before { clear_formats }
    after { reset_formats }

    it "adds the query format to the list of available formats" do
      expect {
        Barometer::Query::Format.register(:test_format, double(:format))
      }.to change { Barometer::Query::Format.formats.count }.by(1)
    end

    it "raises an error if no format class given" do
      expect {
        Barometer::Query::Format.register(:test_format)
      }.to raise_error(ArgumentError)
    end

    it "only registers a key once" do
      format = double(:format)
      Barometer::Query::Format.register(:test_format, format)
      expect {
        Barometer::Query::Format.register(:test_format, format)
      }.not_to change { Barometer::Query::Format.formats.count }
    end
  end

  describe ".find" do
    before { clear_formats }
    after { reset_formats }

    it "returns a registered format" do
      test_format = double(:test_format)
      Barometer::Query::Format.register(:test_format, test_format)

      Barometer::Query::Format.find(:test_format).should == test_format
    end

    it "raises an error if the format does not exist" do
      expect {
        Barometer::Query::Format.find(:test_format)
      }.to raise_error(Barometer::Query::Format::NotFound)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
barometer-0.9.7 spec/query/formats_spec.rb
barometer-0.9.6 spec/query/formats_spec.rb
barometer-0.9.5 spec/query/formats_spec.rb
barometer-0.9.4 spec/query/formats_spec.rb
barometer-0.9.3 spec/query/formats_spec.rb
barometer-0.9.2 spec/query/formats_spec.rb
barometer-0.9.1 spec/query/formats_spec.rb
barometer-0.9.0 spec/query/formats_spec.rb