rubyc 0.0.14 → 0.0.16
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.rdoc +5 -6
- data/Rakefile +9 -2
- data/bin/rubyc +3 -112
- data/features/rubyc.feature +18 -0
- data/features/step_definitions/.rubyc_steps.rb.swp +0 -0
- data/features/step_definitions/rubyc_steps.rb +104 -0
- data/features/support/env.rb +15 -0
- data/lib/rubyc/cli.rb +122 -0
- data/lib/rubyc/version.rb +1 -1
- data/rubyc.gemspec +3 -1
- data/spec/rubyc_spec.rb +111 -0
- data/spec/spec_helper.rb +17 -0
- metadata +49 -9
data/.gitignore
CHANGED
data/README.rdoc
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
= Description
|
2
|
-
Adds Ruby's
|
1
|
+
= Description {<img src="https://secure.travis-ci.org/martinos/rubyc.png" />}[http://travis-ci.org/martinos/rubyc]
|
2
|
+
Adds Ruby's power to the command line.
|
3
3
|
Supports many enumerator methods applied to STDIN. The current line is represented by the "line" variable name or it's shorter alias 'l'.
|
4
4
|
|
5
5
|
To get help:
|
6
6
|
rubyc help
|
7
7
|
|
8
|
-
==
|
8
|
+
== Examples
|
9
9
|
$ ls | rubyc map 'line.upcase'
|
10
10
|
GEMFILE
|
11
11
|
RAILS_VERSION
|
@@ -18,9 +18,8 @@ To get help:
|
|
18
18
|
Here are the currently supported methods:
|
19
19
|
compact # Remove empty lines
|
20
20
|
count_by # Count the number of lines that have the same property. The property is defined by the return value of the given the block.
|
21
|
-
grep # Enumerable#grep
|
22
|
-
|
23
|
-
map # Apply Enumerable#map on each line
|
21
|
+
grep # Enumerable#grep the first argument is the pattern matcher and the second is the block executed on each line.
|
22
|
+
map # Apply Enumerable#map on each line and outputs the results of the block by calling to_s on the returned object.
|
24
23
|
merge # Merge consecutive lines
|
25
24
|
scan # String#scan
|
26
25
|
select # Enumerable#select
|
data/Rakefile
CHANGED
@@ -3,8 +3,15 @@ Bundler::GemHelper.install_tasks
|
|
3
3
|
Bundler.require(:default, :development)
|
4
4
|
require 'rake/testtask'
|
5
5
|
|
6
|
-
|
6
|
+
require 'cucumber'
|
7
|
+
require 'cucumber/rake/task'
|
8
|
+
|
7
9
|
Rake::TestTask.new do |t|
|
8
|
-
|
10
|
+
t.pattern = "spec/*_spec.rb"
|
11
|
+
end
|
12
|
+
|
13
|
+
Cucumber::Rake::Task.new(:features) do |t|
|
14
|
+
t.fork = false
|
9
15
|
end
|
10
16
|
|
17
|
+
task :default => [:test, :features]
|
data/bin/rubyc
CHANGED
@@ -1,113 +1,4 @@
|
|
1
|
-
|
2
|
-
require 'yaml'
|
1
|
+
#!/usr/bin/env ruby
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
self.inject({}) do |memo, elem|
|
7
|
-
key = yield elem
|
8
|
-
memo[key] ||= 0
|
9
|
-
memo[key] += 1
|
10
|
-
memo
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
# This method was borrowed from ActiveSupport code
|
15
|
-
def group_by
|
16
|
-
self.inject({}) do |memo, elem|
|
17
|
-
key = yield elem
|
18
|
-
memo[key] ||= []
|
19
|
-
memo[key] << elem
|
20
|
-
memo
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
# File activesupport/lib/active_support/core_ext/enumerable.rb, line 57
|
25
|
-
def sum(identity = 0, &block)
|
26
|
-
if block_given?
|
27
|
-
map(&block).sum(identity)
|
28
|
-
else
|
29
|
-
inject { |sum, element| sum + element } || identity
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
class Rubyc < Thor
|
35
|
-
$stdout.sync = true
|
36
|
-
desc :map, "Apply Enumerable#map on each line"
|
37
|
-
def map(code)
|
38
|
-
proc = eval( "Proc.new{|line| l = line; #{code}}" )
|
39
|
-
$stdin.each do |line|
|
40
|
-
puts proc.call(line.chomp).to_s
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
desc :sum, "Calculate the sum of Numeric expressed on each line"
|
45
|
-
def sum(code = nil)
|
46
|
-
code ||= "line"
|
47
|
-
proc = eval("Proc.new{|line| l = line; #{code}}")
|
48
|
-
sum = $stdin.sum do |line|
|
49
|
-
proc.call(line.chomp).to_f
|
50
|
-
end
|
51
|
-
puts sum
|
52
|
-
end
|
53
|
-
|
54
|
-
desc :select, "Apply Enumerable#select on each line"
|
55
|
-
def select(code)
|
56
|
-
proc = eval("Proc.new{|line| l = line; #{code}}")
|
57
|
-
$stdin.each do |line|
|
58
|
-
puts line if proc.call(line.chomp)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
desc :count_by, "Count the number of lines that have the same property. The property is defined by the return value of the given the block"
|
63
|
-
def count_by(code = nil)
|
64
|
-
code ||= "line"
|
65
|
-
proc = eval("Proc.new{|line| l = line; #{code}}")
|
66
|
-
counts = $stdin.count_by do |line|
|
67
|
-
proc.call(line.chomp)
|
68
|
-
end
|
69
|
-
puts counts.to_yaml
|
70
|
-
end
|
71
|
-
|
72
|
-
desc :sort_by, "Sort by"
|
73
|
-
def sort_by(code = nil)
|
74
|
-
code ||= "line"
|
75
|
-
proc = eval("Proc.new{|line| l = line; #{code}}")
|
76
|
-
counts = $stdin.sort_by do |line|
|
77
|
-
proc.call(line.chomp)
|
78
|
-
end
|
79
|
-
puts counts
|
80
|
-
end
|
81
|
-
|
82
|
-
desc :grep, "Grep"
|
83
|
-
def grep(pattern, code = nil)
|
84
|
-
pattern = eval(pattern)
|
85
|
-
proc = code ? eval("Proc.new{|line| l = line; #{code}}") : nil
|
86
|
-
puts $stdin.grep(pattern, &proc)
|
87
|
-
end
|
88
|
-
|
89
|
-
desc :scan, "Scan"
|
90
|
-
def scan(pattern, code = nil)
|
91
|
-
pattern = eval(pattern)
|
92
|
-
proc = code ? eval("Proc.new{|*match| m = match; #{code}}") : nil
|
93
|
-
str = $stdin.read
|
94
|
-
str.scan(pattern, &proc)
|
95
|
-
end
|
96
|
-
|
97
|
-
desc :uniq, "uniq"
|
98
|
-
def uniq
|
99
|
-
puts STDIN.to_a.uniq
|
100
|
-
end
|
101
|
-
|
102
|
-
desc :compact, "Remove empty lines"
|
103
|
-
def compact
|
104
|
-
STDIN.each{|line| puts line if line.chomp! != ""}
|
105
|
-
end
|
106
|
-
|
107
|
-
desc :merge, "Merge consecutive lines"
|
108
|
-
def merge(nb_lines, sep = ",")
|
109
|
-
STDIN.each_slice(nb_lines.to_i){|chunk| puts chunk.map{|elem| elem.strip}.join(sep)}
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
Rubyc.start
|
3
|
+
require 'rubyc/cli'
|
4
|
+
Rubyc::CLI.start
|
@@ -0,0 +1,18 @@
|
|
1
|
+
Feature: My bootstrapped app kinda works
|
2
|
+
In order to get going on coding my awesome app
|
3
|
+
I want to have aruba and cucumber setup
|
4
|
+
So I don't have to do it myself
|
5
|
+
|
6
|
+
Scenario: App just runs
|
7
|
+
When I get help for "rubyc"
|
8
|
+
Then the exit status should be 0
|
9
|
+
And the following options should be documented:
|
10
|
+
|map|
|
11
|
+
|select|
|
12
|
+
|sum|
|
13
|
+
|sort_by|
|
14
|
+
|grep|
|
15
|
+
|compact|
|
16
|
+
|count_by|
|
17
|
+
|uniq|
|
18
|
+
|merge|
|
Binary file
|
@@ -0,0 +1,104 @@
|
|
1
|
+
module Methadone
|
2
|
+
# By <tt>require</tt>'ing <tt>methadone/cucumber</tt> in your Cucumber setup (e.g. in <tt>env.rb</tt>), you
|
3
|
+
# gain access to the steps defined in this file. They provide you with the following:
|
4
|
+
#
|
5
|
+
# * Run <tt>command_to_run --help</tt> using aruba
|
6
|
+
#
|
7
|
+
# When I get help for "command_to_run"
|
8
|
+
#
|
9
|
+
# * Make sure that each option shows up in the help and has *some* sort of documentation
|
10
|
+
#
|
11
|
+
# Then the following options should be documented:
|
12
|
+
# |--force|
|
13
|
+
# |-x |
|
14
|
+
#
|
15
|
+
# * Check an individual option for documentation:
|
16
|
+
#
|
17
|
+
# Then the option "--force" should be documented
|
18
|
+
#
|
19
|
+
# * Checks that the help has a proper usage banner
|
20
|
+
#
|
21
|
+
# Then the banner should be present
|
22
|
+
#
|
23
|
+
# * Checks that the banner includes the version
|
24
|
+
#
|
25
|
+
# Then the banner should include the version
|
26
|
+
#
|
27
|
+
# * Checks that the usage banner indicates it takes options via <tt>[options]</tt>
|
28
|
+
#
|
29
|
+
# Then the banner should document that this app takes options
|
30
|
+
#
|
31
|
+
# * Do the opposite; check that you don't indicate options are accepted
|
32
|
+
#
|
33
|
+
# Then the banner should document that this app takes no options
|
34
|
+
#
|
35
|
+
# * Checks that the app's usage banner documents that its arguments are <tt>args</tt>
|
36
|
+
#
|
37
|
+
# Then the banner should document that this app's arguments are
|
38
|
+
# |foo|which is optional|
|
39
|
+
# |bar|which is required|
|
40
|
+
#
|
41
|
+
# * Do the opposite; check that your app doesn't take any arguments
|
42
|
+
#
|
43
|
+
# Then the banner should document that this app takes no arguments
|
44
|
+
#
|
45
|
+
# * Check for a usage description which occurs after the banner and a blank line
|
46
|
+
#
|
47
|
+
# Then there should be a one line summary of what the app does
|
48
|
+
#
|
49
|
+
module Cucumber
|
50
|
+
end
|
51
|
+
end
|
52
|
+
When /^I get help for "([^"]*)"$/ do |app_name|
|
53
|
+
@app_name = app_name
|
54
|
+
step %(I run `#{app_name} --help`)
|
55
|
+
end
|
56
|
+
|
57
|
+
Then /^the following options should be documented:$/ do |options|
|
58
|
+
options.raw.each do |option|
|
59
|
+
step %(the option "#{option[0]}" should be documented)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
Then /^the option "([^"]*)" should be documented$/ do |option|
|
64
|
+
step %(the output should match /\\s*#{Regexp.escape(option)}[\\s\\W]+\\w\\w\\w+/)
|
65
|
+
end
|
66
|
+
|
67
|
+
Then /^the banner should be present$/ do
|
68
|
+
step %(the output should match /Usage: #{@app_name}/)
|
69
|
+
end
|
70
|
+
|
71
|
+
Then /^the banner should document that this app takes options$/ do
|
72
|
+
step %(the output should match /\[options\]/)
|
73
|
+
step %(the output should contain "Options")
|
74
|
+
end
|
75
|
+
|
76
|
+
Then /^the banner should document that this app's arguments are:$/ do |table|
|
77
|
+
expected_arguments = table.raw.map { |row|
|
78
|
+
option = row[0]
|
79
|
+
option = "[#{option}]" if row[1] == 'optional' || row[1] == 'which is optional'
|
80
|
+
option
|
81
|
+
}.join(' ')
|
82
|
+
step %(the output should contain "#{expected_arguments}")
|
83
|
+
end
|
84
|
+
|
85
|
+
Then /^the banner should document that this app takes no options$/ do
|
86
|
+
step %(the output should not contain "[options]")
|
87
|
+
step %(the output should not contain "Options")
|
88
|
+
end
|
89
|
+
|
90
|
+
Then /^the banner should document that this app takes no arguments$/ do
|
91
|
+
step %(the output should match /Usage: #{@app_name}\\s*\(\\[options\\]\)?$/)
|
92
|
+
end
|
93
|
+
|
94
|
+
Then /^the banner should include the version$/ do
|
95
|
+
step %(the output should match /v\\d+\\.\\d+\\.\\d+/)
|
96
|
+
end
|
97
|
+
|
98
|
+
Then /^there should be a one line summary of what the app does$/ do
|
99
|
+
output_lines = all_output.split(/\n/)
|
100
|
+
output_lines.should have_at_least(3).items
|
101
|
+
# [0] is our banner, which we've checked for
|
102
|
+
output_lines[1].should match(/^\s*$/)
|
103
|
+
output_lines[2].should match(/^\w+\s+\w+/)
|
104
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'aruba/cucumber'
|
2
|
+
|
3
|
+
ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
|
4
|
+
LIB_DIR = File.join(File.expand_path(File.dirname(__FILE__)),'..','..','lib')
|
5
|
+
|
6
|
+
Before do
|
7
|
+
# Using "announce" causes massive warnings on 1.9.2
|
8
|
+
@puts = true
|
9
|
+
@original_rubylib = ENV['RUBYLIB']
|
10
|
+
ENV['RUBYLIB'] = LIB_DIR + File::PATH_SEPARATOR + ENV['RUBYLIB'].to_s
|
11
|
+
end
|
12
|
+
|
13
|
+
After do
|
14
|
+
ENV['RUBYLIB'] = @original_rubylib
|
15
|
+
end
|
data/lib/rubyc/cli.rb
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'thor'
|
3
|
+
|
4
|
+
module Rubyc
|
5
|
+
module ::Enumerable
|
6
|
+
def count_by
|
7
|
+
self.inject({}) do |memo, elem|
|
8
|
+
key = yield elem
|
9
|
+
memo[key] ||= 0
|
10
|
+
memo[key] += 1
|
11
|
+
memo
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# This method was borrowed from ActiveSupport code
|
16
|
+
def group_by
|
17
|
+
self.inject({}) do |memo, elem|
|
18
|
+
key = yield elem
|
19
|
+
memo[key] ||= []
|
20
|
+
memo[key] << elem
|
21
|
+
memo
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# File activesupport/lib/active_support/core_ext/enumerable.rb, line 57
|
26
|
+
def sum(identity = 0, &block)
|
27
|
+
if block_given?
|
28
|
+
map(&block).sum(identity)
|
29
|
+
else
|
30
|
+
inject { |sum, element| sum + element } || identity
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class CLI < Thor
|
36
|
+
class_option :require, :aliases => '-r'
|
37
|
+
|
38
|
+
def initialize(*args)
|
39
|
+
super
|
40
|
+
libs = options[:require] ? options[:require].strip.split(":") : []
|
41
|
+
libs.each {|lib| require lib}
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
$stdout.sync = true
|
46
|
+
desc :map, "Apply Enumerable#map on each line"
|
47
|
+
def map(code)
|
48
|
+
proc = eval( "Proc.new{|line| l = line; #{code}}" )
|
49
|
+
$stdin.each do |line|
|
50
|
+
puts proc.call(line.chomp).to_s
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
desc :sum, "Calculate the sum of Numeric expressed on each line"
|
55
|
+
def sum(code = nil)
|
56
|
+
code ||= "line"
|
57
|
+
proc = eval("Proc.new{|line| l = line; #{code}}")
|
58
|
+
sum = $stdin.sum do |line|
|
59
|
+
proc.call(line.chomp).to_f
|
60
|
+
end
|
61
|
+
puts sum
|
62
|
+
end
|
63
|
+
|
64
|
+
desc :select, "Apply Enumerable#select on each line"
|
65
|
+
def select(code)
|
66
|
+
proc = eval("Proc.new{|line| l = line; #{code}}")
|
67
|
+
$stdin.each do |line|
|
68
|
+
puts line if proc.call(line.chomp)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
desc :count_by, "Count the number of lines that have the same property. The property is defined by the return value of the given the block"
|
73
|
+
def count_by(code = nil)
|
74
|
+
code ||= "line"
|
75
|
+
proc = eval("Proc.new{|line| l = line; #{code}}")
|
76
|
+
counts = $stdin.count_by do |line|
|
77
|
+
proc.call(line.chomp)
|
78
|
+
end
|
79
|
+
puts counts.to_yaml
|
80
|
+
end
|
81
|
+
|
82
|
+
desc :sort_by, "Sort by"
|
83
|
+
def sort_by(code = nil)
|
84
|
+
code ||= "line"
|
85
|
+
proc = eval("Proc.new{|line| l = line; #{code}}")
|
86
|
+
counts = $stdin.sort_by do |line|
|
87
|
+
proc.call(line.chomp)
|
88
|
+
end
|
89
|
+
puts counts
|
90
|
+
end
|
91
|
+
|
92
|
+
desc :grep, "Grep"
|
93
|
+
def grep(pattern, code = nil)
|
94
|
+
pattern = eval(pattern)
|
95
|
+
proc = code ? eval("Proc.new{|line| l = line; #{code}}") : nil
|
96
|
+
puts $stdin.grep(pattern, &proc)
|
97
|
+
end
|
98
|
+
|
99
|
+
desc :scan, "Scan"
|
100
|
+
def scan(pattern, code = nil)
|
101
|
+
pattern = eval(pattern)
|
102
|
+
proc = code ? eval("Proc.new{|*match| m = match; #{code}}") : nil
|
103
|
+
str = $stdin.read
|
104
|
+
str.scan(pattern, &proc)
|
105
|
+
end
|
106
|
+
|
107
|
+
desc :uniq, "uniq"
|
108
|
+
def uniq
|
109
|
+
puts $stdin.to_a.uniq
|
110
|
+
end
|
111
|
+
|
112
|
+
desc :compact, "Remove empty lines"
|
113
|
+
def compact
|
114
|
+
$stdin.each{ |line| puts line if line.chomp! != ""}
|
115
|
+
end
|
116
|
+
|
117
|
+
desc :merge, "Merge consecutive lines"
|
118
|
+
def merge(nb_lines, sep = ",")
|
119
|
+
$stdin.each_slice(nb_lines.to_i){|chunk| puts chunk.map{|elem| elem.strip}.join(sep)}
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
data/lib/rubyc/version.rb
CHANGED
data/rubyc.gemspec
CHANGED
@@ -15,7 +15,9 @@ Gem::Specification.new do |s|
|
|
15
15
|
|
16
16
|
s.add_dependency "thor"
|
17
17
|
s.add_development_dependency 'rake'
|
18
|
-
s.add_development_dependency
|
18
|
+
s.add_development_dependency "bundler", "~> 1.0"
|
19
|
+
s.add_development_dependency 'minitest'
|
20
|
+
s.add_development_dependency 'aruba'
|
19
21
|
|
20
22
|
s.files = `git ls-files`.split("\n")
|
21
23
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
data/spec/rubyc_spec.rb
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
ROOT_PATH = File.expand_path('../..', __FILE__)
|
2
|
+
require File.expand_path('../spec_helper', __FILE__)
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
4
|
+
require 'rubyc/cli'
|
5
|
+
|
6
|
+
include SpecHelper
|
7
|
+
# require 'colorize'
|
8
|
+
#
|
9
|
+
# module ColorizeIO
|
10
|
+
# def puts(str = "")
|
11
|
+
# red = "\\e[31m"
|
12
|
+
# blank = "\\e[0m"
|
13
|
+
# green = "\\e[32m"
|
14
|
+
# blue = "\\e[34m"
|
15
|
+
# magenta = "\\e[35m"
|
16
|
+
# #
|
17
|
+
# url_regex = %r{(\\S*.rb):(\\d+)(.*)}
|
18
|
+
# str.each_line do |line|
|
19
|
+
# if line =~ url_regex
|
20
|
+
# file_name = $1
|
21
|
+
# line_number = $2
|
22
|
+
# complement = $3
|
23
|
+
# if File.exist? file_name
|
24
|
+
# full_path = File.expand_path(file_name)
|
25
|
+
# app_trace = full_path.match(ROOT_PATH) && full_path !~ /vendor/
|
26
|
+
# new_line = "#{blue}txmt://open?url=file://#{File.dirname(full_path)}/#{red if app_trace }#{File.basename(full_path)}#{blank}&line=#{line_number
|
27
|
+
# }#{complement}"
|
28
|
+
# else
|
29
|
+
# new_line = line
|
30
|
+
# end
|
31
|
+
# else
|
32
|
+
# new_line = line
|
33
|
+
# end
|
34
|
+
# super(new_line + "\\n")
|
35
|
+
# end
|
36
|
+
# end
|
37
|
+
# end
|
38
|
+
#
|
39
|
+
# MiniTest::Unit.output.extend ColorizeIO
|
40
|
+
|
41
|
+
describe "A rubyc cli" do
|
42
|
+
before do
|
43
|
+
@cli = Rubyc::CLI.new
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should map stdin to stdout" do
|
47
|
+
out_str = local_io("first\nsecond") do
|
48
|
+
@cli.map('l.upcase')
|
49
|
+
end
|
50
|
+
out_str.must_equal "FIRST\nSECOND\n"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should select line from stdin and send it to stdout" do
|
54
|
+
out_str = local_io("first\nsecond\nthird") do
|
55
|
+
@cli.select('l =~ /third/')
|
56
|
+
end
|
57
|
+
out_str.must_equal "third\n"
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should sum line from stdin and send it to stdout" do
|
61
|
+
out_str = local_io("1\n2\nthird\n4") do
|
62
|
+
@cli.sum('l.to_i * 2')
|
63
|
+
end
|
64
|
+
out_str.must_equal "14.0\n"
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should sort by stdin and send the result to stdout" do
|
68
|
+
out_str = local_io("a\nbbb\ncc\ndddd") do
|
69
|
+
@cli.sort_by('l.length')
|
70
|
+
end
|
71
|
+
out_str.must_equal "a\ncc\nbbb\ndddd\n"
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should grep stdin and send the result to stdout" do
|
75
|
+
out_str = local_io("bbbb\nbbb\ncc\ndddd") do
|
76
|
+
@cli.grep('/^b/', 'l.upcase')
|
77
|
+
end
|
78
|
+
out_str.must_equal "BBBB\nBBB\n"
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should count_by an algorithm and output to stdout" do
|
82
|
+
out_str = local_io("bbbb\nbbb\ncc\ndddd") do
|
83
|
+
@cli.count_by('l =~ /^(..)/;$1')
|
84
|
+
end
|
85
|
+
expected = {"bb" => 2, "cc" => 1, "dd" => 1}
|
86
|
+
|
87
|
+
YAML.load(out_str).must_equal expected
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should remove empty lines from stdin and output to stdout" do
|
91
|
+
out_str = local_io("bbbb\n\ncc\n") do
|
92
|
+
@cli.compact
|
93
|
+
end
|
94
|
+
out_str.must_equal "bbbb\ncc\n"
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should keep unique lines from stdin and output them to stdout" do
|
98
|
+
out_str = local_io("1\n2\n2\n3") do
|
99
|
+
@cli.uniq
|
100
|
+
end
|
101
|
+
out_str.must_equal "1\n2\n3\n"
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should merge lines in group of n output them to stdout" do
|
105
|
+
out_str = local_io("1\n2\n3\n4\n5\n6\n7\n8") do
|
106
|
+
@cli.merge(3, ",")
|
107
|
+
end
|
108
|
+
out_str.must_equal "1,2,3\n4,5,6\n7,8\n"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
$:.unshift File.expand_path('..', __FILE__)
|
2
|
+
$:.unshift File.expand_path('../../lib', __FILE__)
|
3
|
+
require 'rubyc'
|
4
|
+
require 'minitest/spec'
|
5
|
+
require 'minitest/autorun'
|
6
|
+
|
7
|
+
module SpecHelper
|
8
|
+
def local_io(in_str)
|
9
|
+
old_stdin, old_stdout = $stdin, $stdout
|
10
|
+
$stdin = StringIO.new(in_str)
|
11
|
+
$stdout = StringIO.new
|
12
|
+
yield
|
13
|
+
out_str = $stdout.string
|
14
|
+
$stdin, $stdout = old_stdin, old_stdout
|
15
|
+
out_str
|
16
|
+
end
|
17
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubyc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 63
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 16
|
10
|
+
version: 0.0.16
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Martin Chabot
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-09-04 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
prerelease: false
|
@@ -29,8 +29,8 @@ dependencies:
|
|
29
29
|
- 0
|
30
30
|
version: "0"
|
31
31
|
requirement: *id001
|
32
|
-
type: :runtime
|
33
32
|
name: thor
|
33
|
+
type: :runtime
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: &id002 !ruby/object:Gem::Requirement
|
@@ -43,8 +43,8 @@ dependencies:
|
|
43
43
|
- 0
|
44
44
|
version: "0"
|
45
45
|
requirement: *id002
|
46
|
-
type: :development
|
47
46
|
name: rake
|
47
|
+
type: :development
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: &id003 !ruby/object:Gem::Requirement
|
@@ -58,8 +58,36 @@ dependencies:
|
|
58
58
|
- 0
|
59
59
|
version: "1.0"
|
60
60
|
requirement: *id003
|
61
|
-
type: :development
|
62
61
|
name: bundler
|
62
|
+
type: :development
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
hash: 3
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
version: "0"
|
74
|
+
requirement: *id004
|
75
|
+
name: minitest
|
76
|
+
type: :development
|
77
|
+
- !ruby/object:Gem::Dependency
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
hash: 3
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
version: "0"
|
88
|
+
requirement: *id005
|
89
|
+
name: aruba
|
90
|
+
type: :development
|
63
91
|
description: Adds Ruby's powers to the command line
|
64
92
|
email:
|
65
93
|
- chabotm@gmail.com
|
@@ -75,9 +103,16 @@ files:
|
|
75
103
|
- README.rdoc
|
76
104
|
- Rakefile
|
77
105
|
- bin/rubyc
|
106
|
+
- features/rubyc.feature
|
107
|
+
- features/step_definitions/.rubyc_steps.rb.swp
|
108
|
+
- features/step_definitions/rubyc_steps.rb
|
109
|
+
- features/support/env.rb
|
78
110
|
- lib/rubyc.rb
|
111
|
+
- lib/rubyc/cli.rb
|
79
112
|
- lib/rubyc/version.rb
|
80
113
|
- rubyc.gemspec
|
114
|
+
- spec/rubyc_spec.rb
|
115
|
+
- spec/spec_helper.rb
|
81
116
|
homepage: https://github.com/martinos/rubyc
|
82
117
|
licenses: []
|
83
118
|
|
@@ -111,5 +146,10 @@ rubygems_version: 1.8.11
|
|
111
146
|
signing_key:
|
112
147
|
specification_version: 3
|
113
148
|
summary: Adds Ruby's powers to the command line
|
114
|
-
test_files:
|
115
|
-
|
149
|
+
test_files:
|
150
|
+
- features/rubyc.feature
|
151
|
+
- features/step_definitions/.rubyc_steps.rb.swp
|
152
|
+
- features/step_definitions/rubyc_steps.rb
|
153
|
+
- features/support/env.rb
|
154
|
+
- spec/rubyc_spec.rb
|
155
|
+
- spec/spec_helper.rb
|