Sha256: 48ed6362e8a45479494b7e0e0571eb70c9cd0ca27d682b8bde0677d31c80fd46

Contents?: true

Size: 1.32 KB

Versions: 9

Compression:

Stored size: 1.32 KB

Contents

require "spec_helper"

describe MetricFu::Formatter do
  describe "formatter class loading" do
    context "given a built-in formatter (string)" do
      subject { MetricFu::Formatter.class_for("html") }

      it "returns the formatter class" do
        expect(subject).to eq(MetricFu::Formatter::HTML)
      end
    end

    context "given a built-in formatter (symbol)" do
      subject { MetricFu::Formatter.class_for(:yaml) }

      it "returns the formatter class" do
        expect(subject).to eq(MetricFu::Formatter::YAML)
      end
    end

    context "given an unknown built-in formatter" do
      subject { MetricFu::Formatter.class_for(:unknown) }

      it "raises an error" do
        expect { subject }.to raise_error(NameError)
      end
    end

    context "given a custom formatter that exists" do
      subject { MetricFu::Formatter.class_for("MyCustomFormatter") }

      before do
        stub_const("MyCustomFormatter", Class.new { def initialize(*); end })
      end

      it "returns the formatter class" do
        expect(subject).to eq(MyCustomFormatter)
      end
    end

    context "given a custom formatter that doesnt exist" do
      subject { MetricFu::Formatter.class_for("MyNonExistentCustomFormatter") }

      it "raises an error" do
        expect { subject }.to raise_error(NameError)
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 3 rubygems

Version Path
metric_fu-4.13.0 spec/metric_fu/formatter_spec.rb
fastruby-metric_fu-5.0.0 spec/metric_fu/formatter_spec.rb
code_metric_fu-4.14.4 spec/metric_fu/formatter_spec.rb
code_metric_fu-4.14.3 spec/metric_fu/formatter_spec.rb
code_metric_fu-4.14.2 spec/metric_fu/formatter_spec.rb
code_metric_fu-4.14.1 spec/metric_fu/formatter_spec.rb
code_metric_fu-4.14.0 spec/metric_fu/formatter_spec.rb
metric_fu-4.12.0 spec/metric_fu/formatter_spec.rb
metric_fu-4.11.4 spec/metric_fu/formatter_spec.rb