Sha256: 5b9008efbad3e5413af2165a3d85cc4326ac29a7299d62267369a53ecb514f7b

Contents?: true

Size: 1.36 KB

Versions: 1

Compression:

Stored size: 1.36 KB

Contents

require 'spec_helper'

require 'observed/builtin_plugins/stdout'

describe Observed::BuiltinPlugins::Stdout do

  subject {
    reporter = Observed::BuiltinPlugins::Stdout.new
    reporter.configure config
    reporter
  }

  let(:config) {
    { tag_pattern: /foo\..+/, format: formatter }
  }

  context 'with a specific formatter' do

    let(:formatter) {
      -> tag, time, data, fetcher { "foo #{time.to_i} #{data[:foo]} #{fetcher['bar.baz']}" }
    }

    it 'reports the formatted data to the stdout' do
      time = Time.now
      STDOUT.expects(:puts).with("foo #{time.to_i} 1 2")
      expect { subject.report('foo', time, {foo: 1, bar: {baz: 2}}) }.to_not raise_error
    end

  end

  context 'without a specific formatter' do

    let(:formatter) {
      nil
    }

    it 'reports the data formatted by the default formatter to the stdout' do
      time = Time.now
      STDOUT.expects(:puts).with("#{time.to_s} foo {:foo=>1}")
      expect { subject.report('foo', time, {foo: 1}) }.to_not raise_error
    end

  end

  context 'with the formatter whose number of parameters is not 3 nor 4' do

    let(:formatter) {
      -> a, b {}
    }

    it 'fails while reporting' do
      pattern = /Number of parameters for the function for the key :format must be 3 or 4, but was 2/
      expect { subject.report('foo', Time.now, {}) }.to raise_error(pattern)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
observed-0.1.1 spec/builtin_plugins/stdout_spec.rb