Sha256: dd9e8d68d7f7e6532cddb634148ec6fa7c09820f210e5e01960556fe771d812a

Contents?: true

Size: 1.01 KB

Versions: 3

Compression:

Stored size: 1.01 KB

Contents

Given(/^a packet data file "(.*?)"$/) do |name|
  path = File.expand_path(File.join(File.dirname(__FILE__),
                                    '..', 'packet_data', name))
  case File.extname(name)
  when '.raw'
    @raw = path
  when '.pcap'
    @pcap = path
  else
    fail "Unsupported file extension: #{name}"
  end
end

When(/^I try to parse the file with "(.*?)" class$/) do |parser|
  parser_klass = Pio.const_get(parser)
  if @raw
    @result = parser_klass.read(IO.read(@raw))
  elsif @pcap
    File.open(@pcap) do |file|
      pcap = Pio::Pcap::Frame.read(file)
      pcap.records.each { |each| parser_klass.read each.data }
    end
  else
    fail 'Packet data file is not specified.'
  end
end

Then(/^it should finish successfully$/) do
  # Noop.
end

Then(/^the parsed data have the following field and value:$/) do |table|
  table.hashes.each do |each|
    output = each['field'].split('.').inject(@result) do |memo, method|
      memo.__send__(method)
    end
    expect(output.to_s).to eq(each['value'])
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pio-0.11.2 features/step_definitions/packet_data_steps.rb
pio-0.11.1 features/step_definitions/packet_data_steps.rb
pio-0.11.0 features/step_definitions/packet_data_steps.rb