Sha256: c15cf06927742b5ed064e56f4b1d0cb5561f323ccf5647cec5348392d7d6d2c4

Contents?: true

Size: 1.32 KB

Versions: 10

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
        subject.should 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
        subject.should 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
        lambda{ subject }.should 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
        subject.should eq(MyCustomFormatter)
      end
    end

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

      it 'raises an error' do
        lambda{ subject }.should raise_error(NameError)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
metric_fu-4.6.0 spec/metric_fu/formatter_spec.rb
metric_fu-4.5.2 spec/metric_fu/formatter_spec.rb
metric_fu-4.5.1 spec/metric_fu/formatter_spec.rb
metric_fu-4.4.4 spec/metric_fu/formatter_spec.rb
metric_fu-4.4.3 spec/metric_fu/formatter_spec.rb
metric_fu-4.4.2 spec/metric_fu/formatter_spec.rb
metric_fu-4.4.1 spec/metric_fu/formatter_spec.rb
metric_fu-4.4.0 spec/metric_fu/formatter_spec.rb
metric_fu-4.3.1 spec/metric_fu/formatter_spec.rb
metric_fu-4.3.0 spec/metric_fu/formatter_spec.rb