Sha256: 0583cbc48446ffb956aaf1707f92d5d0bc83851c18ec6a056ed1dac026523706

Contents?: true

Size: 1.41 KB

Versions: 3

Compression:

Stored size: 1.41 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, output: output }
  }

  let(:output) {
    mock('output')
  }

  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
      output.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
      output.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

3 entries across 3 versions & 1 rubygems

Version Path
observed-0.2.0 spec/builtin_plugins/stdout_spec.rb
observed-0.2.0.rc2 spec/builtin_plugins/stdout_spec.rb
observed-0.2.0.rc1 spec/builtin_plugins/stdout_spec.rb