Sha256: c6ac098c991c8b2c39494e175f16629c6c28aabb2a1e589c47e4009e780538de

Contents?: true

Size: 1.42 KB

Versions: 2

Compression:

Stored size: 1.42 KB

Contents

require 'spec_helper'

describe 'misc examples' do
  include FixturesHelper
  include ProcessHelper

  # http://stackoverflow.com/questions/450799/shell-command-to-sum-integers-one-per-line
  context "summing integers" do
    it "sums" do
      lines = (1..10).to_a.map(&:to_s)
      out = run('map(:to_i).sum', lines)
      out.should == '55'
    end
  end

  # http://stackoverflow.com/questions/6022384/bash-tool-to-get-nth-line-from-a-file
  context "printing the nth line" do
    it "prints" do
      lines = (1..10).to_a.map(&:to_s)
      out = run('[4]', lines)
      out.should == '5'
    end
  end

  # https://coderwall.com/p/ueazhw
  context "sorting an Apache access log by response time" do
    it "sorts" do
      file = fixture_path('files', 'access.log')
      out = run(['map { |line| [line[/(\d+)( ".+"){2}$/, 1].to_i, line] }.sort.reverse.map(:join, " ")', file])
      out.should == <<-EOF.strip
584912 66.249.64.14 - - [18/Sep/2004:11:07:48 +1000] "GET /file.txt HTTP/1.0" 200 584912 "-" "Googlebot/2.1"
6433 66.249.64.14 - - [18/Sep/2004:11:07:48 +1000] "GET / HTTP/1.0" 200 6433 "-" "Googlebot/2.1"
6433 66.249.64.13 - - [18/Sep/2004:11:07:48 +1000] "GET / HTTP/1.0" 200 6433 "-" "Googlebot/2.1"
468 66.249.64.14 - - [18/Sep/2004:11:07:48 +1000] "GET /robots.txt HTTP/1.0" 200 468 "-" "Googlebot/2.1"
468 66.249.64.13 - - [18/Sep/2004:11:07:48 +1000] "GET /robots.txt HTTP/1.0" 200 468 "-" "Googlebot/2.1"
EOF
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ru-0.1.1 spec/examples/misc_examples_spec.rb
ru-0.1.0 spec/examples/misc_examples_spec.rb