Skip to content

Commit

Permalink
spec default reduce behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
grosser committed Apr 18, 2011
1 parent 3fad41d commit 5700c80
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
20 changes: 10 additions & 10 deletions spec/pru_spec.rb
@@ -1,10 +1,6 @@
require File.expand_path('spec/spec_helper')

describe Pru do
before :all do
@default = `ls -l | wc -l`
end

it "has a VERSION" do
Pru::VERSION.should =~ /^\d+\.\d+\.\d+$/
end
Expand All @@ -18,30 +14,34 @@
end

it "can selects via i" do
`ls -l | ./bin/pru 'i'`.split("\n")[0...3].should == ["1","2","3"]
`cat spec/test.txt | ./bin/pru 'i'`.split("\n")[0...3].should == ["1","2","3"]
end

it "maps" do
`echo abc | ./bin/pru 'gsub(/a/,"b")'`.should == "bbc\n"
end

it "selects and reduces" do
`ls -l | ./bin/pru 'include?("G")' 'size'`.should == "2\n"
`cat spec/test.txt | ./bin/pru 'include?("abc")' 'size'`.should == "2\n"
end

it "selects with empty string and reduces" do
`ls -l | ./bin/pru '' 'size'`.should == @default
`cat spec/test.txt | ./bin/pru '' 'size'`.should == "5\n"
end

it "reduces" do
`ls -l | ./bin/pru -r 'size'`.should == @default
`cat spec/test.txt | ./bin/pru -r 'size'`.should == "5\n"
end

it "prints arrays as newlines" do
`cat spec/test.txt | ./bin/pru -r 'self'`.should == File.read('spec/test.txt')
end

it "can sum" do
`echo 5 | ./bin/pru -r 'sum(&:to_i)'`.should == "5\n"
`cat spec/test.txt | ./bin/pru -r 'sum(&:to_i)'`.should == "1212\n"
end

it "can mean" do
`echo 5 | ./bin/pru -r 'mean(&:to_i)'`.should == "5.0\n"
`cat spec/test.txt | ./bin/pru -r 'mean(&:to_i)'`.should == "242.4\n"
end
end
5 changes: 5 additions & 0 deletions spec/test.txt
@@ -0,0 +1,5 @@
abc
def
abcdef
12
1200

0 comments on commit 5700c80

Please sign in to comment.