Sha256: 302511ba2f7594d4374a163dfa20835a4b31822b80b7833154bfe7bac2cb298b

Contents?: true

Size: 1.36 KB

Versions: 4

Compression:

Stored size: 1.36 KB

Contents

require 'spec_helper'

describe Sumo::Formatter do
  subject { Sumo::Formatter }

  describe '.format_json' do
    context 'when the input cannot be parsed' do
      it 'raises an error' do
        expect { subject.format_json('cannot parse this') }
            .to raise_error(Sumo::Error::ParseError)
      end
    end

    context 'when the input can be parsed' do
      let(:input) {
        [
          { '_messagetime' => 2, '_raw' => 'world' },
          { '_messagetime' => 1, '_raw' => 'hello' }
        ].to_json
      }

      it 'sorts the input by the _messagetime, returning a String' do
        subject.format_json(input).should == %w(hello world)
      end
    end
  end

  describe '.extract_key' do
    context 'when at least one element of the Array cannot be parsed' do
      let(:input) { [ { :a => 1 }.to_json, 'qwerty'] }

      it 'raises an error' do
        expect { subject.extract_key('anything', input) }
            .to raise_error(Sumo::Error::ParseError)
      end
    end

    context 'when the input is an Array of parseable values' do
      let(:input) {
        [
          { 'message' => 'rats', 'time' => 2 }.to_json,
          { 'message' => 'cats', 'time' => 1 }.to_json
        ]
      }

      it 'returns an Array with the specified key extracted' do
        subject.extract_key('message', input).should == %w(rats cats)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sumo-search-0.1.1 spec/lib/sumo/formatter_spec.rb
sumo-search-0.1.0 spec/lib/sumo/formatter_spec.rb
sumo-search-0.0.2 spec/lib/sumo/formatter_spec.rb
sumo-search-0.0.1 spec/lib/sumo/formatter_spec.rb