spec/rubyc_spec.rb in rubyc-0.0.16 vs spec/rubyc_spec.rb in rubyc-0.0.17

- old
+ new

@@ -1,111 +1 @@ -ROOT_PATH = File.expand_path('../..', __FILE__) -require File.expand_path('../spec_helper', __FILE__) -require File.expand_path(File.dirname(__FILE__) + '/spec_helper') -require 'rubyc/cli' - -include SpecHelper -# require 'colorize' -# -# module ColorizeIO -# def puts(str = "") -# red = "\\e[31m" -# blank = "\\e[0m" -# green = "\\e[32m" -# blue = "\\e[34m" -# magenta = "\\e[35m" -# # -# url_regex = %r{(\\S*.rb):(\\d+)(.*)} -# str.each_line do |line| -# if line =~ url_regex -# file_name = $1 -# line_number = $2 -# complement = $3 -# if File.exist? file_name -# full_path = File.expand_path(file_name) -# app_trace = full_path.match(ROOT_PATH) && full_path !~ /vendor/ -# new_line = "#{blue}txmt://open?url=file://#{File.dirname(full_path)}/#{red if app_trace }#{File.basename(full_path)}#{blank}&line=#{line_number -# }#{complement}" -# else -# new_line = line -# end -# else -# new_line = line -# end -# super(new_line + "\\n") -# end -# end -# end -# -# MiniTest::Unit.output.extend ColorizeIO - -describe "A rubyc cli" do - before do - @cli = Rubyc::CLI.new - end - - it "should map stdin to stdout" do - out_str = local_io("first\nsecond") do - @cli.map('l.upcase') - end - out_str.must_equal "FIRST\nSECOND\n" - end - - it "should select line from stdin and send it to stdout" do - out_str = local_io("first\nsecond\nthird") do - @cli.select('l =~ /third/') - end - out_str.must_equal "third\n" - end - - it "should sum line from stdin and send it to stdout" do - out_str = local_io("1\n2\nthird\n4") do - @cli.sum('l.to_i * 2') - end - out_str.must_equal "14.0\n" - end - - it "should sort by stdin and send the result to stdout" do - out_str = local_io("a\nbbb\ncc\ndddd") do - @cli.sort_by('l.length') - end - out_str.must_equal "a\ncc\nbbb\ndddd\n" - end - - it "should grep stdin and send the result to stdout" do - out_str = local_io("bbbb\nbbb\ncc\ndddd") do - @cli.grep('/^b/', 'l.upcase') - end - out_str.must_equal "BBBB\nBBB\n" - end - - it "should count_by an algorithm and output to stdout" do - out_str = local_io("bbbb\nbbb\ncc\ndddd") do - @cli.count_by('l =~ /^(..)/;$1') - end - expected = {"bb" => 2, "cc" => 1, "dd" => 1} - - YAML.load(out_str).must_equal expected - end - - it "should remove empty lines from stdin and output to stdout" do - out_str = local_io("bbbb\n\ncc\n") do - @cli.compact - end - out_str.must_equal "bbbb\ncc\n" - end - - it "should keep unique lines from stdin and output them to stdout" do - out_str = local_io("1\n2\n2\n3") do - @cli.uniq - end - out_str.must_equal "1\n2\n3\n" - end - - it "should merge lines in group of n output them to stdout" do - out_str = local_io("1\n2\n3\n4\n5\n6\n7\n8") do - @cli.merge(3, ",") - end - out_str.must_equal "1,2,3\n4,5,6\n7,8\n" - end -end - \ No newline at end of file