spec/pru_spec.rb in pru-0.1.5 vs spec/pru_spec.rb in pru-0.1.6

- old
+ new

@@ -3,10 +3,14 @@ describe Pru do it "has a VERSION" do Pru::VERSION.should =~ /^\d+\.\d+\.\d+$/ end + it "shows help when no arguments are given" do + `./bin/pru`.should include('Usage:') + end + describe 'map' do it "selects" do `ls -l | ./bin/pru 'include?("G")'`.split("\n").size.should == 2 end @@ -80,8 +84,36 @@ `echo 1 | ./bin/pru --require rake --reduce 'Rake.to_s'`.should == "Rake\n" end it "requires these libs comma-separated" do `echo 1 | ./bin/pru --require jeweler,rake --reduce 'Rake.to_s + Jeweler.to_s'`.should == "RakeJeweler\n" + end + end + + describe '--inplace-edit FILE' do + after do + `rm -f xxx` + end + + it "modifies the file" do + File.open('xxx','w'){|f| f.write "abc\nab\na" } + `./bin/pru --inplace-edit xxx size`.should == '' + File.read('xxx').should == "3\n2\n1" + end + + it "fails with empty file" do + `./bin/pru --inplace-edit xxx size 2>&1`.should include('No such file or directory - xxx') + end + + it "keeps line separators when modifying" do + File.open('xxx','w'){|f| f.write "abc\r\nab\r\na" } + `./bin/pru --inplace-edit xxx size`.should == '' + File.read('xxx').should == "3\r\n2\r\n1" + end + + it "modifies the file with reduce" do + File.open('xxx','w'){|f| f.write "abc\nab\na" } + `./bin/pru --inplace-edit xxx size inspect`.should == '' + File.read('xxx').should == "[3, 2, 1]" end end end