mycmd 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/mycmd/cli.rb +2 -2
- data/lib/mycmd/clis/config_commands.rb +2 -2
- data/lib/mycmd/clis/settings_commands.rb +64 -0
- data/lib/mycmd/configuration.rb +10 -0
- data/lib/mycmd/printer.rb +24 -6
- data/lib/mycmd/version.rb +1 -1
- data/spec/mycmd/cli_spec.rb +86 -1
- data/spec/mycmd/clis/config_commands_spec.rb +75 -0
- data/spec/mycmd/clis/settings_commands_spec.rb +47 -0
- data/spec/mycmd/configuration_spec.rb +35 -8
- data/spec/mycmd/printer_spec.rb +89 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/support/spec_utils.rb +61 -0
- metadata +10 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8c336e5ee888d89abcf88b847b4b014992d5d53
|
4
|
+
data.tar.gz: 0314ddffcabc62fa4de866899f4497be744795b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b67247b0b25dcf6b14fab62bf02da1dabdd26e646edf1f42eb812e28605d1740230e47b84cdca6033367d4ca0ee0d9b3783f45ea5d730d013e513b875596c73a
|
7
|
+
data.tar.gz: 33fad2267c9e8a4ab357e397433b5b3fc64ba17397d6df5ff9be3b0e0f28a7fbdf277d836858278431adccd87ce3c52cea3b9f238085a0ed92f5ac7c26bb1008
|
data/lib/mycmd/cli.rb
CHANGED
@@ -11,7 +11,7 @@ module Mycmd
|
|
11
11
|
|
12
12
|
desc "console", "console will start sql shell."
|
13
13
|
def console
|
14
|
-
raise "mysql not found" unless system("which mysql > /dev/null")
|
14
|
+
raise "mysql not found" unless Kernel.system("which mysql > /dev/null")
|
15
15
|
conf = Configuration.new
|
16
16
|
cmd = conf.to_hash.inject(["mysql"]) do |c,(k,v)|
|
17
17
|
case k
|
@@ -23,7 +23,7 @@ module Mycmd
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
system(cmd.join(" "))
|
26
|
+
Kernel.system(cmd.join(" "))
|
27
27
|
end
|
28
28
|
|
29
29
|
desc 'query "[SQL]"', "query will execute sql."
|
@@ -14,14 +14,14 @@ module Mycmd
|
|
14
14
|
def cat
|
15
15
|
conf = Configuration.config_find
|
16
16
|
raise "config not found" if conf.nil?
|
17
|
-
open(conf, "r").each {|line| puts line}
|
17
|
+
File.open(conf, "r").each {|line| puts line}
|
18
18
|
end
|
19
19
|
|
20
20
|
desc "edit", "edit will edit configuration"
|
21
21
|
def edit
|
22
22
|
conf = Configuration.config_find
|
23
23
|
raise "config not found" if conf.nil?
|
24
|
-
system("#{ENV['EDITOR']} #{conf}")
|
24
|
+
Kernel.system("#{ENV['EDITOR']} #{conf}")
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -4,11 +4,75 @@ module Mycmd
|
|
4
4
|
class SettingsCommands < Thor
|
5
5
|
namespace :settings
|
6
6
|
|
7
|
+
GLOBAL_BUFFERS = [
|
8
|
+
:innodb_buffer_pool_size,
|
9
|
+
:innodb_log_buffer_size,
|
10
|
+
:innodb_additional_mem_pool_size,
|
11
|
+
:key_buffer_size,
|
12
|
+
:query_cache_size
|
13
|
+
].freeze
|
14
|
+
|
15
|
+
THREAD_BUFFERS = [
|
16
|
+
:sort_buffer_size,
|
17
|
+
:read_buffer_size,
|
18
|
+
:read_rnd_buffer_size,
|
19
|
+
:join_buffer_size,
|
20
|
+
:tmp_table_size,
|
21
|
+
:max_heap_table_size,
|
22
|
+
:net_buffer_length,
|
23
|
+
:max_allowed_packet,
|
24
|
+
:thread_stack
|
25
|
+
].freeze
|
26
|
+
|
7
27
|
desc "search innodb_buffer_pool_size", "search will print settings"
|
8
28
|
def search(keyword)
|
9
29
|
client = Configuration.connect
|
10
30
|
printer = Printer.new(client.query("SHOW GLOBAL VARIABLES LIKE \"%#{keyword}%\""))
|
11
31
|
printer.print
|
12
32
|
end
|
33
|
+
|
34
|
+
desc "memories", "memories will print memory settings"
|
35
|
+
def memories
|
36
|
+
variables = Configuration.get_variables
|
37
|
+
global, gtotal = create_result_variables(GLOBAL_BUFFERS, variables)
|
38
|
+
thread, ttotal = create_result_variables(THREAD_BUFFERS, variables)
|
39
|
+
expected = expected_memory_used(gtotal, variables)
|
40
|
+
Printer.print_title("GLOBAL BUFFERS")
|
41
|
+
Printer.new(global).print
|
42
|
+
Printer.print_title("THREAD BUFFERS", true)
|
43
|
+
Printer.new(thread).print
|
44
|
+
Printer.print_title("EXPECTED MEMORY USED", true)
|
45
|
+
Printer.new(expected).print
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
def create_result_variables(keys, variables)
|
50
|
+
rows = []
|
51
|
+
total = keys.inject(0) do |t,key|
|
52
|
+
bytes = variables[key].to_i
|
53
|
+
rows << [key.to_s ,"#{bytes} bytes (#{bytes.to_f/1024/1024} MB)"]
|
54
|
+
t + bytes
|
55
|
+
end
|
56
|
+
return rows, total
|
57
|
+
end
|
58
|
+
|
59
|
+
def expected_memory_used(global, variables)
|
60
|
+
max_connections = variables[:max_connections].to_i
|
61
|
+
threads = expected_threads(variables, max_connections)
|
62
|
+
total = global + threads
|
63
|
+
[
|
64
|
+
["max_connections", "#{max_connections} connections"],
|
65
|
+
["expected memory use of global", "#{global} bytes (#{global.to_f/1024/1024} MB)"],
|
66
|
+
["expected memory use of threads", "#{threads} bytes (#{threads.to_f/1024/1024} MB)"],
|
67
|
+
["expected total", "#{total} bytes (#{total.to_f/1024/1024} MB)"]
|
68
|
+
]
|
69
|
+
end
|
70
|
+
|
71
|
+
def expected_threads(variables, max_connections)
|
72
|
+
base = variables[:net_buffer_length].to_i + variables[:thread_stack].to_i
|
73
|
+
tmp = variables[:tmp_table_size].to_i * 0.1
|
74
|
+
buffer = THREAD_BUFFERS[0..3].inject(0){|b,k| b + (variables[k].to_i * 0.5)}
|
75
|
+
((base + tmp + buffer) * max_connections)
|
76
|
+
end
|
13
77
|
end
|
14
78
|
end
|
data/lib/mycmd/configuration.rb
CHANGED
@@ -67,6 +67,16 @@ module Mycmd
|
|
67
67
|
conf.connect
|
68
68
|
end
|
69
69
|
|
70
|
+
def get_variables
|
71
|
+
sql = "SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES"
|
72
|
+
client = self.connect
|
73
|
+
variables = {}
|
74
|
+
client.query(sql).each do |row|
|
75
|
+
variables.store(row["VARIABLE_NAME"].downcase.to_sym, row["VARIABLE_VALUE"])
|
76
|
+
end
|
77
|
+
variables
|
78
|
+
end
|
79
|
+
|
70
80
|
def config_find(path = File.expand_path("."))
|
71
81
|
file = File.join(path, CONFIG_FILE)
|
72
82
|
if File.exists?(file)
|
data/lib/mycmd/printer.rb
CHANGED
@@ -2,25 +2,36 @@
|
|
2
2
|
|
3
3
|
module Mycmd
|
4
4
|
class Printer
|
5
|
+
BORDER = "*" * 30
|
6
|
+
attr_accessor :result, :header, :width
|
7
|
+
|
5
8
|
def initialize(result, header=false)
|
6
|
-
@result = result
|
7
|
-
@header = header
|
9
|
+
@result = result.is_a?(Mysql2::Result) ? result_to_array(result) : result
|
10
|
+
@header = result.is_a?(Mysql2::Result) ? result.fields : header
|
8
11
|
end
|
9
12
|
|
10
13
|
def print
|
11
14
|
if @result.respond_to? :each
|
12
15
|
set_width
|
13
|
-
print_line(@
|
14
|
-
@result.each
|
16
|
+
print_line(@header) if @header
|
17
|
+
@result.each do |row|
|
15
18
|
print_line(row)
|
16
19
|
end
|
17
20
|
end
|
18
21
|
end
|
19
22
|
|
20
23
|
private
|
24
|
+
def result_to_array(result)
|
25
|
+
result_array = []
|
26
|
+
result.each(as: :array) do |row|
|
27
|
+
result_array << row
|
28
|
+
end
|
29
|
+
result_array
|
30
|
+
end
|
31
|
+
|
21
32
|
def set_width
|
22
|
-
@width = @
|
23
|
-
@result.each
|
33
|
+
@width = @header ? @header.map{|f| f.size} : Array.new(@result.first.size){0}
|
34
|
+
@result.each do |row|
|
24
35
|
row.each_with_index do |v,i|
|
25
36
|
@width[i] = v.to_s.size if @width[i] < v.to_s.size
|
26
37
|
end
|
@@ -30,5 +41,12 @@ module Mycmd
|
|
30
41
|
def print_line(line_array)
|
31
42
|
puts line_array.map.with_index {|f,i| f.to_s.ljust(@width[i], " ")}.join("\t")
|
32
43
|
end
|
44
|
+
|
45
|
+
class << self
|
46
|
+
def print_title(title, empty_line=false)
|
47
|
+
puts if empty_line
|
48
|
+
puts "#{BORDER}\n#{title}\n#{BORDER}"
|
49
|
+
end
|
50
|
+
end
|
33
51
|
end
|
34
52
|
end
|
data/lib/mycmd/version.rb
CHANGED
data/spec/mycmd/cli_spec.rb
CHANGED
@@ -1,4 +1,89 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe Mycmd::CLI do
|
3
|
+
describe Mycmd::CLI do
|
4
|
+
let(:conn_mock) {double("connection mock").as_null_object}
|
5
|
+
let(:printer_mock) {double("printer mock").as_null_object}
|
6
|
+
|
7
|
+
describe "#console" do
|
8
|
+
let(:args) {["console"]}
|
9
|
+
|
10
|
+
before do
|
11
|
+
Mycmd::Configuration.stub(:config_find).and_return(nil)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should call Kernel.system" do
|
15
|
+
conf = Mycmd::Configuration.new
|
16
|
+
conf.password = "secret"
|
17
|
+
conf.database = "test"
|
18
|
+
Mycmd::Configuration.should_receive(:new).and_return(conf)
|
19
|
+
Kernel.should_receive(:system).exactly(2).and_return(true)
|
20
|
+
expect {
|
21
|
+
Mycmd::CLI.start(args)
|
22
|
+
}.not_to raise_error
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should generate exception if mysql command not found" do
|
26
|
+
Kernel.should_receive(:system).and_return(false)
|
27
|
+
expect {
|
28
|
+
Mycmd::CLI.start(args)
|
29
|
+
}.to raise_error
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#query" do
|
34
|
+
before do
|
35
|
+
Mycmd::Configuration.stub(:connect).and_return(conn_mock)
|
36
|
+
Mycmd::Printer.stub(:new).and_return(printer_mock)
|
37
|
+
end
|
38
|
+
|
39
|
+
after do
|
40
|
+
expect {
|
41
|
+
Mycmd::CLI.start(["query", "some sql"])
|
42
|
+
}.not_to raise_error
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should call Configuration.connect" do
|
46
|
+
Mycmd::Configuration.should_receive(:connect).and_return(conn_mock)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should create Printer object" do
|
50
|
+
Mycmd::Printer.should_receive(:new).with(conn_mock, true).and_return(printer_mock)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should call Printer#print" do
|
54
|
+
printer_mock.should_receive(:print)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "#tasks" do
|
59
|
+
let(:config_mock) {double("configuration mock").as_null_object}
|
60
|
+
|
61
|
+
before do
|
62
|
+
config_mock.stub(:connect).and_return(conn_mock)
|
63
|
+
Mycmd::Configuration.stub(:new).and_return(config_mock)
|
64
|
+
Mycmd::Printer.stub(:new).and_return(printer_mock)
|
65
|
+
end
|
66
|
+
|
67
|
+
after do
|
68
|
+
expect {
|
69
|
+
Mycmd::CLI.start(["tasks", "some task"])
|
70
|
+
}.not_to raise_error
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should create Configuration object" do
|
74
|
+
Mycmd::Configuration.should_receive(:new).and_return(config_mock)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should call Configuration#connect" do
|
78
|
+
config_mock.should_receive(:connect).and_return(conn_mock)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should create Printer object" do
|
82
|
+
Mycmd::Printer.should_receive(:new).with(conn_mock, true).and_return(printer_mock)
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should call Printer#print" do
|
86
|
+
printer_mock.should_receive(:print)
|
87
|
+
end
|
88
|
+
end
|
4
89
|
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Mycmd::ConfigCommands do
|
4
|
+
describe "#which" do
|
5
|
+
let(:args) {["which"]}
|
6
|
+
|
7
|
+
it "should call Configuration.config_find" do
|
8
|
+
Mycmd::Configuration.should_receive(:config_find).and_return(nil)
|
9
|
+
expect(
|
10
|
+
capture(:stdout){
|
11
|
+
Mycmd::ConfigCommands.start(args)
|
12
|
+
}
|
13
|
+
).not_to be_nil
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should print not found message if file not found" do
|
17
|
+
Mycmd::Configuration.stub(:config_find).and_return(nil)
|
18
|
+
expect(
|
19
|
+
capture(:stdout){
|
20
|
+
Mycmd::ConfigCommands.start(args)
|
21
|
+
}
|
22
|
+
).to eq("config not found\n")
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should print config path" do
|
26
|
+
config = "/Users/i2bskn/.mycmd.yml"
|
27
|
+
Mycmd::Configuration.stub(:config_find).and_return(config)
|
28
|
+
expect(
|
29
|
+
capture(:stdout){
|
30
|
+
Mycmd::ConfigCommands.start(args)
|
31
|
+
}
|
32
|
+
).to eq("#{config}\n")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#edit" do
|
37
|
+
let(:args) {["edit"]}
|
38
|
+
|
39
|
+
it "should execute edit command" do
|
40
|
+
Mycmd::Configuration.stub(:config_find).and_return(".mycmd.yml")
|
41
|
+
Kernel.should_receive(:system).with("#{ENV['EDITOR']} .mycmd.yml")
|
42
|
+
Mycmd::ConfigCommands.start(args)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should generate exception if file not found" do
|
46
|
+
Mycmd::Configuration.stub(:config_find).and_return(nil)
|
47
|
+
expect {
|
48
|
+
Mycmd::ConfigCommands.start(args)
|
49
|
+
}.to raise_error(RuntimeError)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should call Configuration.config_find" do
|
53
|
+
Mycmd::Configuration.should_receive(:config_find).and_return(".mycmd.yml")
|
54
|
+
Kernel.stub(:system)
|
55
|
+
Mycmd::ConfigCommands.start(args)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "#cat" do
|
60
|
+
let(:args) {["cat"]}
|
61
|
+
|
62
|
+
it "should call Configuration.config_find" do
|
63
|
+
Mycmd::Configuration.should_receive(:config_find).and_return(".mycmd.yml")
|
64
|
+
File.stub(:open).and_return([])
|
65
|
+
Mycmd::ConfigCommands.start(args)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should generate exception if file not found" do
|
69
|
+
Mycmd::Configuration.stub(:config_find).and_return(nil)
|
70
|
+
expect {
|
71
|
+
Mycmd::ConfigCommands.start(args)
|
72
|
+
}.to raise_error(RuntimeError)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Mycmd::SettingsCommands do
|
4
|
+
describe "#search" do
|
5
|
+
let(:args) {["search", "param_name"]}
|
6
|
+
let(:conn_mock) do
|
7
|
+
mock = double("connection mock")
|
8
|
+
mock.stub(:query).and_return(create_result)
|
9
|
+
mock
|
10
|
+
end
|
11
|
+
|
12
|
+
before {Mycmd::Configuration.stub(:connect).and_return(conn_mock)}
|
13
|
+
|
14
|
+
after do
|
15
|
+
expect(
|
16
|
+
capture(:stdout) {
|
17
|
+
Mycmd::SettingsCommands.start(args)
|
18
|
+
}
|
19
|
+
).not_to be_nil
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should call Configuration.connect" do
|
23
|
+
Mycmd::Configuration.should_receive(:connect).and_return(conn_mock)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should create Printer object" do
|
27
|
+
Mycmd::Printer.should_receive(:new).and_return(double.as_null_object)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should call Printer#print" do
|
31
|
+
Mycmd::Printer.any_instance.should_receive(:print)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#memories" do
|
36
|
+
let(:args){["memories"]}
|
37
|
+
|
38
|
+
it "returns expected threads" do
|
39
|
+
Mycmd::Configuration.stub(:get_variables).and_return(create_variables)
|
40
|
+
expect(
|
41
|
+
capture(:stdout) {
|
42
|
+
Mycmd::SettingsCommands.start(args)
|
43
|
+
}
|
44
|
+
).not_to be_nil
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -53,21 +53,21 @@ describe Mycmd::Configuration do
|
|
53
53
|
end
|
54
54
|
|
55
55
|
describe "#reset" do
|
56
|
+
after do
|
57
|
+
expect {
|
58
|
+
Mycmd::Configuration.new
|
59
|
+
}.not_to raise_error
|
60
|
+
end
|
61
|
+
|
56
62
|
it "should load yaml file" do
|
57
63
|
Mycmd::Configuration.should_receive(:config_find).and_return(conf_file)
|
58
64
|
Mycmd::Configuration.any_instance.should_receive(:merge)
|
59
65
|
YAML.should_receive(:load_file).with(conf_file)
|
60
|
-
expect {
|
61
|
-
Mycmd::Configuration.new
|
62
|
-
}.not_to raise_error
|
63
66
|
end
|
64
67
|
|
65
68
|
it "should call #default if config not found" do
|
66
69
|
Mycmd::Configuration.should_receive(:config_find).and_return(nil)
|
67
70
|
Mycmd::Configuration.any_instance.should_receive(:default)
|
68
|
-
expect {
|
69
|
-
Mycmd::Configuration.new
|
70
|
-
}.not_to raise_error
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
@@ -87,7 +87,7 @@ describe Mycmd::Configuration do
|
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
|
-
describe "
|
90
|
+
describe ".#connect" do
|
91
91
|
it "should call #connect" do
|
92
92
|
mock = double("configuration mock")
|
93
93
|
mock.should_receive(:connect)
|
@@ -98,7 +98,34 @@ describe Mycmd::Configuration do
|
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
101
|
-
describe "
|
101
|
+
describe ".#get_variables" do
|
102
|
+
let(:conn_mock) {double("connection mock")}
|
103
|
+
|
104
|
+
before do
|
105
|
+
conn_mock.stub(:query).and_return([{"VARIABLE_NAME" => "innodb_buffer_pool_size", "VARIABLE_VALUE" => "268435456"}])
|
106
|
+
Mycmd::Configuration.stub(:connect).and_return(conn_mock)
|
107
|
+
end
|
108
|
+
|
109
|
+
after do
|
110
|
+
expect {
|
111
|
+
Mycmd::Configuration.get_variables
|
112
|
+
}.not_to raise_error
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should call .#connect" do
|
116
|
+
Mycmd::Configuration.should_receive(:connect).and_return(conn_mock)
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should call Mysql2::Client#query" do
|
120
|
+
conn_mock.should_receive(:query).and_return([])
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should return variables" do
|
124
|
+
expect(Mycmd::Configuration.get_variables).to eq({innodb_buffer_pool_size: "268435456"})
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe ".#config_find" do
|
102
129
|
let(:path) {Mycmd::Configuration.config_find(home_dir)}
|
103
130
|
|
104
131
|
it "returns config path" do
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Mycmd::Printer do
|
4
|
+
let(:result) {create_result}
|
5
|
+
let(:printer) {Mycmd::Printer.new(result)}
|
6
|
+
|
7
|
+
describe "#initialize" do
|
8
|
+
it "should set specified result" do
|
9
|
+
expect(printer.result).to eq(result)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should set default header flug" do
|
13
|
+
expect(printer.header).to be_false
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should set specified header flug" do
|
17
|
+
printer = Mycmd::Printer.new(result, true)
|
18
|
+
expect(printer.header).to be_true
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should generate exception if not specified arguments" do
|
22
|
+
expect {
|
23
|
+
Mycmd::Printer.new
|
24
|
+
}.to raise_error
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#print" do
|
29
|
+
after do
|
30
|
+
expect {
|
31
|
+
printer.print
|
32
|
+
}.not_to raise_error
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should call #set_width" do
|
36
|
+
printer.send(:set_width)
|
37
|
+
Mycmd::Printer.any_instance.should_receive(:set_width)
|
38
|
+
Mycmd::Printer.any_instance.stub(:print_line).and_return(nil)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should call #print_line" do
|
42
|
+
Mycmd::Printer.any_instance.should_receive(:print_line).exactly(3)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should not call #print_line if each method not found" do
|
46
|
+
Mycmd::Printer.any_instance.should_not_receive(:print_line)
|
47
|
+
result.should_receive(:respond_to?).and_return(false)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "#result_to_array" do
|
52
|
+
it "should convert to array from result" do
|
53
|
+
expect(printer.send(:result_to_array, create_result)).to eq([
|
54
|
+
["first", "one"],
|
55
|
+
["second", "two"],
|
56
|
+
["third", "three"]
|
57
|
+
])
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "#set_width" do
|
62
|
+
it "should set max length" do
|
63
|
+
printer.send(:set_width)
|
64
|
+
expect(printer.width).to eq([6,5])
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should hoge" do
|
68
|
+
printer.header = result.fields
|
69
|
+
printer.send(:set_width)
|
70
|
+
expect(printer.width).to eq([6,6])
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "#print_line" do
|
75
|
+
it "should print line" do
|
76
|
+
expect(capture(:stdout){printer.print}).not_to be_nil
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "#print_title" do
|
81
|
+
it "should print title" do
|
82
|
+
expect(capture(:stdout){Mycmd::Printer.print_title("title")}).not_to be_nil
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should print empty line" do
|
86
|
+
expect(capture(:stdout){Mycmd::Printer.print_title("title", true)}).to match(/^\n/)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,61 @@
|
|
1
|
+
require "stringio"
|
2
|
+
|
3
|
+
module SpecUtils
|
4
|
+
def capture(stream)
|
5
|
+
begin
|
6
|
+
stream = stream.to_s
|
7
|
+
eval "$#{stream} = StringIO.new"
|
8
|
+
yield
|
9
|
+
result = eval("$#{stream}").string
|
10
|
+
ensure
|
11
|
+
eval("$#{stream} = #{stream.upcase}")
|
12
|
+
end
|
13
|
+
result
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_variables
|
17
|
+
{
|
18
|
+
innodb_buffer_pool_size: "268435456",
|
19
|
+
innodb_log_buffer_size: "8388608",
|
20
|
+
innodb_additional_mem_pool_size: "16777216",
|
21
|
+
key_buffer_size: "16777216",
|
22
|
+
query_cache_size: "0",
|
23
|
+
sort_buffer_size: "524288",
|
24
|
+
read_buffer_size: "262144",
|
25
|
+
read_rnd_buffer_size: "524288",
|
26
|
+
join_buffer_size: "262144",
|
27
|
+
tmp_table_size: "16777216",
|
28
|
+
max_heap_table_size: "16777216",
|
29
|
+
net_buffer_length: "16384",
|
30
|
+
max_allowed_packet: "1048576",
|
31
|
+
thread_stack: "262144"
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
def create_result
|
36
|
+
Result.new
|
37
|
+
end
|
38
|
+
|
39
|
+
class Result
|
40
|
+
attr_reader :fields
|
41
|
+
|
42
|
+
def initialize
|
43
|
+
@data = [
|
44
|
+
["first", "one"],
|
45
|
+
["second", "two"],
|
46
|
+
["third", "three"]
|
47
|
+
]
|
48
|
+
@fields = ["order", "number"]
|
49
|
+
end
|
50
|
+
|
51
|
+
def first
|
52
|
+
@data.first
|
53
|
+
end
|
54
|
+
|
55
|
+
def each(params={})
|
56
|
+
@data.each do |d|
|
57
|
+
yield(d)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mycmd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- i2bskn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -105,8 +105,12 @@ files:
|
|
105
105
|
- lib/mycmd/version.rb
|
106
106
|
- mycmd.gemspec
|
107
107
|
- spec/mycmd/cli_spec.rb
|
108
|
+
- spec/mycmd/clis/config_commands_spec.rb
|
109
|
+
- spec/mycmd/clis/settings_commands_spec.rb
|
108
110
|
- spec/mycmd/configuration_spec.rb
|
111
|
+
- spec/mycmd/printer_spec.rb
|
109
112
|
- spec/spec_helper.rb
|
113
|
+
- spec/support/spec_utils.rb
|
110
114
|
homepage: https://github.com/i2bskn/mycmd
|
111
115
|
licenses:
|
112
116
|
- MIT
|
@@ -133,5 +137,9 @@ specification_version: 4
|
|
133
137
|
summary: MySQL command line tool
|
134
138
|
test_files:
|
135
139
|
- spec/mycmd/cli_spec.rb
|
140
|
+
- spec/mycmd/clis/config_commands_spec.rb
|
141
|
+
- spec/mycmd/clis/settings_commands_spec.rb
|
136
142
|
- spec/mycmd/configuration_spec.rb
|
143
|
+
- spec/mycmd/printer_spec.rb
|
137
144
|
- spec/spec_helper.rb
|
145
|
+
- spec/support/spec_utils.rb
|