Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 28 lines (24 sloc) 0.661 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
require 'rubygems'
require 'grok-pure'
require 'rspec'

RSpec::Matchers.define :have_logstash_field do |field|
  chain :with_value do |value|
    @value= value
  end

  match do |grok_match|
    grok_captures = grok_match.captures()
    grok_field = grok_captures.keys.grep(/.*:#{field}$/)
    if @value
      grok_captures[grok_field.first].first.should == @value
    else
      grok_field.size.should equal 1
    end
  end

  failure_message_for_should do |grok_match|
    if @value
      "\"#{field}\" isn't set to \"#{@value}\" in #{grok_match.captures()}"
    else
      "\"#{field}\" suffix not present in #{grok_match.captures().keys}"
    end
  end
end
Something went wrong with that request. Please try again.