ztk 3.0.4 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bdc8f617cd4946e08ae511019c8c824602e10690
4
- data.tar.gz: d59c97edbd63a148a7453aa5ccfc5ade274928b0
3
+ metadata.gz: 1209eb8e5e2897a3911c0e7048080bc532b86c43
4
+ data.tar.gz: 0b41dee03dac4f105de394722dfa9608e98fc221
5
5
  SHA512:
6
- metadata.gz: d2ba6a6764ad01b16e5e7dfd33e704f34b7c33c666299745622035c8eeefc0fc0c71d9bacb18f4587e24de74c5688a6a6a20d8b3fe4dc5e966a54dc8d4be3292
7
- data.tar.gz: 6f715ee4bb05e8cc3430756556834f6057d0cd9e4d7525a054836c2240d0b2f3f8c355dbb9b6fd41df81d61b3b7ed9515eca9708237ed49017dd0de782327a1c
6
+ metadata.gz: d79fceb184898082b9db8edb3c040aee94edb10f07b25588daf7700c5813699652f3c7dc0973ef23f29a0e6e601e8d93590cc3c01e86e086603074f27d300789
7
+ data.tar.gz: 7759484bac6dff0b686c7ae43e54a6e60ca10bfbaa288b5f9522fd0acab96816d0212c89bc4e0de1f6ae5445576822ae83a2b7541362ec317d36f20151dcca17
@@ -11,6 +11,7 @@ module ZTK
11
11
 
12
12
  def start
13
13
  reset
14
+ @@start_time = Time.now.utc
14
15
 
15
16
  true
16
17
  end
@@ -22,7 +23,7 @@ module ZTK
22
23
  end
23
24
 
24
25
  def reset
25
- @@start_time = Time.now.utc
26
+ @@start_time = nil
26
27
  @@end_time = nil
27
28
  @@timer_stack = Array.new
28
29
  Timer.reset
@@ -54,8 +55,12 @@ module ZTK
54
55
  end
55
56
 
56
57
  def total_time
57
- stop
58
- @@end_time - @@start_time
58
+ if @@start_time.nil?
59
+ raise ProfilerError, "You must start the profiler in order to calculate a total time!"
60
+ else
61
+ stop
62
+ @@end_time - @@start_time
63
+ end
59
64
  end
60
65
 
61
66
  def report(options={})
data/lib/ztk/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module ZTK
2
2
 
3
3
  # ZTK Version String
4
- VERSION = "3.0.4"
4
+ VERSION = "3.1.0"
5
5
 
6
6
  end
@@ -27,7 +27,7 @@ describe "ZTK::ANSI Module" do
27
27
  describe "module" do
28
28
 
29
29
  it "should be ZTK::ANSI" do
30
- subject.should be ZTK::ANSI
30
+ expect(subject).to be ZTK::ANSI
31
31
  end
32
32
 
33
33
  end
@@ -36,11 +36,11 @@ end
36
36
 
37
37
  describe "ZTK::ANSI Monkey-Patch String Class" do
38
38
 
39
- subject {
39
+ subject do
40
40
  class String
41
41
  include ZTK::ANSI
42
42
  end
43
- }
43
+ end
44
44
 
45
45
  describe "class" do
46
46
 
@@ -27,7 +27,7 @@ describe ZTK::Background do
27
27
  describe "class" do
28
28
 
29
29
  it "should be an instance of ZTK::Background" do
30
- subject.should be_an_instance_of ZTK::Background
30
+ expect(subject).to be_an_instance_of ZTK::Background
31
31
  end
32
32
 
33
33
  end
@@ -35,7 +35,7 @@ describe ZTK::Background do
35
35
  describe "behaviour" do
36
36
 
37
37
  it "should throw an exception if the process method is called without a block" do
38
- lambda{ subject.process }.should raise_error ZTK::BackgroundError, "You must supply a block to the process method!"
38
+ expect{ subject.process }.to raise_error ZTK::BackgroundError, "You must supply a block to the process method!"
39
39
  end
40
40
 
41
41
  describe "process" do
@@ -46,9 +46,9 @@ describe ZTK::Background do
46
46
  end
47
47
 
48
48
  subject.wait
49
- subject.result.should be_kind_of Integer
50
- subject.result.should > 0
51
- subject.result.should_not == Process.pid
49
+ expect(subject.result).to be_kind_of Integer
50
+ expect(subject.result).to be > 0
51
+ expect(subject.result).not_to be == Process.pid
52
52
  end
53
53
 
54
54
  end
@@ -59,11 +59,11 @@ describe ZTK::Background do
59
59
  subject.process do
60
60
  sleep(WAIT_SMALL)
61
61
  end
62
- subject.alive?.should be true
62
+ expect(subject.alive?).to be == true
63
63
 
64
64
  subject.wait
65
- subject.result.should be_kind_of Integer
66
- subject.result.should > 0
65
+ expect(subject.result).to be_kind_of Integer
66
+ expect(subject.result).to be > 0
67
67
  end
68
68
 
69
69
  it "should respond false when the process is no longer running" do
@@ -73,11 +73,11 @@ describe ZTK::Background do
73
73
  subject.wait
74
74
  sleep(WAIT_SMALL)
75
75
 
76
- subject.alive?.should be false
76
+ expect(subject.alive?).to be == false
77
77
 
78
- subject.result.should be_kind_of Integer
79
- subject.result.should > 0
80
- subject.result.should_not == Process.pid
78
+ expect(subject.result).to be_kind_of Integer
79
+ expect(subject.result).to be > 0
80
+ expect(subject.result).not_to be == Process.pid
81
81
  end
82
82
 
83
83
  end
@@ -89,12 +89,12 @@ describe ZTK::Background do
89
89
  sleep(WAIT_SMALL)
90
90
  WAIT_SMALL
91
91
  end
92
- subject.dead?.should be false
92
+ expect(subject.dead?).to be false
93
93
 
94
94
  subject.wait
95
- subject.result.should be_kind_of Integer
96
- subject.result.should > 0
97
- subject.result.should == WAIT_SMALL
95
+ expect(subject.result).to be_kind_of Integer
96
+ expect(subject.result).to be > 0
97
+ expect(subject.result).to be == WAIT_SMALL
98
98
  end
99
99
 
100
100
  it "should respond true when the process is no longer running" do
@@ -104,11 +104,11 @@ describe ZTK::Background do
104
104
  subject.wait
105
105
  sleep(WAIT_SMALL)
106
106
 
107
- subject.dead?.should be true
107
+ expect(subject.dead?).to be true
108
108
 
109
- subject.result.should be_kind_of Integer
110
- subject.result.should > 0
111
- subject.result.should_not == Process.pid
109
+ expect(subject.result).to be_kind_of Integer
110
+ expect(subject.result).to be > 0
111
+ expect(subject.result).not_to be == Process.pid
112
112
  end
113
113
 
114
114
  end
@@ -127,8 +127,8 @@ describe ZTK::Background do
127
127
  end
128
128
  subject.wait
129
129
 
130
- subject.result.should be_kind_of BackgroundMarshalTest
131
- subject.result.hello_world.should == "Hello World"
130
+ expect(subject.result).to be_kind_of BackgroundMarshalTest
131
+ expect(subject.result.hello_world).to be == "Hello World"
132
132
  end
133
133
 
134
134
  end
@@ -27,7 +27,7 @@ describe ZTK::Base do
27
27
  describe "class" do
28
28
 
29
29
  it "should be ZTK::Base" do
30
- subject.should be ZTK::Base
30
+ expect(subject).to be ZTK::Base
31
31
  end
32
32
 
33
33
  end
@@ -22,20 +22,14 @@ require "spec_helper"
22
22
 
23
23
  describe ZTK::Benchmark do
24
24
 
25
- before(:each) do
26
- @ui = ZTK::UI.new(
27
- :stdout => StringIO.new,
28
- :stderr => StringIO.new,
29
- :stdin => StringIO.new
30
- )
31
- end
25
+ let(:ui) { ZTK::UI.new(:stdout => StringIO.new, :stderr => StringIO.new, :stdin => StringIO.new) }
32
26
 
33
27
  subject { ZTK::Benchmark }
34
28
 
35
29
  describe "class" do
36
30
 
37
31
  it "should be ZTK::Benchmark" do
38
- subject.should be ZTK::Benchmark
32
+ expect(subject).to be ZTK::Benchmark
39
33
  end
40
34
 
41
35
  end
@@ -43,44 +37,43 @@ describe ZTK::Benchmark do
43
37
  describe "behaviour" do
44
38
 
45
39
  it "should throw an exception if executed without a block" do
46
- lambda {
47
- ZTK::Benchmark.bench
48
- }.should raise_error ZTK::BenchmarkError, "You must supply a block!"
40
+ expect{ ZTK::Benchmark.bench }.to raise_error ZTK::BenchmarkError
49
41
  end
50
42
 
51
43
  it "should return the benchmark of the given block" do
52
44
  mark = ZTK::Benchmark.bench do
53
45
  sleep(0.1)
54
46
  end
55
- mark.should be_an_instance_of Float
47
+ expect(mark).to be_an_instance_of Float
56
48
  end
57
49
 
58
50
  it "should not throw an exception if executed with a message but without a mark" do
59
- expect {
60
- ZTK::Benchmark.bench(:ui => @ui, :message => "Hello World") do
51
+ expect{
52
+ ZTK::Benchmark.bench(:ui => ui, :message => "Hello World") do
53
+ sleep(0.1)
61
54
  end
62
55
  }.not_to raise_error
63
56
  end
64
57
 
65
58
  it "should not throw an exception if executed without a message but with a mark" do
66
- expect {
67
- ZTK::Benchmark.bench(:ui => @ui, :mark => "%0.4f") do
59
+ expect{
60
+ ZTK::Benchmark.bench(:ui => ui, :mark => "%0.4f") do
68
61
  end
69
62
  }.not_to raise_error
70
63
  end
71
64
 
72
65
  it "should not write to STDOUT if not given a message or mark" do
73
- ZTK::Benchmark.bench(:ui => @ui, :use_spinner => false) do
66
+ ZTK::Benchmark.bench(:ui => ui, :use_spinner => false) do
74
67
  sleep(0.1)
75
68
  end
76
- @ui.stdout.size.should == 0
69
+ expect(ui.stdout.size).to be == 0
77
70
  end
78
71
 
79
72
  it "should write to STDOUT if given a message and mark" do
80
- ZTK::Benchmark.bench(:ui => @ui, :message => "Hello World", :mark => "%0.4f") do
73
+ ZTK::Benchmark.bench(:ui => ui, :message => "Hello World", :mark => "%0.4f") do
81
74
  sleep(0.1)
82
75
  end
83
- @ui.stdout.size.should > 0
76
+ expect(ui.stdout.size).to be > 0
84
77
  end
85
78
 
86
79
  end
@@ -22,20 +22,14 @@ require "spec_helper"
22
22
 
23
23
  describe ZTK::Command do
24
24
 
25
- before(:each) do
26
- @ui = ZTK::UI.new(
27
- :stdout => StringIO.new,
28
- :stderr => StringIO.new,
29
- :stdin => StringIO.new
30
- )
31
- end
25
+ let(:ui) { ZTK::UI.new(:stdout => StringIO.new, :stderr => StringIO.new, :stdin => StringIO.new) }
32
26
 
33
- subject { ZTK::Command.new(:ui => @ui) }
27
+ subject { ZTK::Command.new }
34
28
 
35
29
  describe "class" do
36
30
 
37
31
  it "should be an instance of ZTK::Command" do
38
- subject.should be_an_instance_of ZTK::Command
32
+ expect(subject).to be_an_instance_of ZTK::Command
39
33
  end
40
34
 
41
35
  end
@@ -45,86 +39,80 @@ describe ZTK::Command do
45
39
  describe "execute" do
46
40
 
47
41
  it "should be able to execute the command \"hostname\"" do
48
- subject.config do |config|
49
- config.ui = @ui
50
- end
42
+ subject.config.ui = ui
43
+
51
44
  hostname = %x(hostname).chomp
52
45
  status = subject.exec("hostname")
53
- status.exit_code.should == 0
54
- @ui.stdout.rewind
55
- @ui.stdout.read.chomp.should == hostname
46
+ expect(status.exit_code).to be == 0
47
+ ui.stdout.rewind
48
+ expect(ui.stdout.read.chomp).to match(hostname)
56
49
  end
57
50
 
58
51
  it "should timeout after the period specified" do
59
52
  subject.config do |config|
60
- config.ui = @ui
53
+ config.ui = ui
61
54
  config.timeout = WAIT_SMALL
62
55
  end
63
56
  hostname = %x(hostname).chomp
64
- lambda { subject.exec("hostname ; sleep 10") }.should raise_error ZTK::CommandError
57
+ expect{ subject.exec("hostname ; sleep 10") }.to raise_error ZTK::CommandError
65
58
  end
66
59
 
67
60
  it "should throw an exception if the exit status is not as expected" do
68
- subject.config do |config|
69
- config.ui = @ui
70
- end
71
- lambda { subject.exec("/bin/bash -c 'exit 64'") }.should raise_error ZTK::CommandError
61
+ subject.config.ui = ui
62
+
63
+ expect{ subject.exec("/bin/bash -c 'exit 64'") }.to raise_error ZTK::CommandError
72
64
  end
73
65
 
74
66
  it "should return a instance of an OpenStruct object" do
75
- subject.config do |config|
76
- config.ui = @ui
77
- end
67
+ subject.config.ui = ui
68
+
78
69
  result = subject.exec(%q{echo "Hello World"})
79
- result.should be_an_instance_of OpenStruct
70
+ expect(result).to be_an_instance_of OpenStruct
80
71
  end
81
72
 
82
73
  it "should return the exit code" do
83
- subject.config do |config|
84
- config.ui = @ui
85
- end
74
+ subject.config.ui = ui
75
+
86
76
  data = 64
87
77
 
88
- result = subject.exec(%Q{/bin/bash -c 'exit #{data}'}, :exit_code => data)
89
- result.exit_code.should == data
78
+ result = subject.exec(%{exit #{data}}, :exit_code => data)
79
+ expect(result.exit_code).to be == data
90
80
  end
91
81
 
92
82
  it "should return the output" do
93
- subject.config do |config|
94
- config.ui = @ui
95
- end
83
+ subject.config.ui = ui
84
+
96
85
  data = "Hello World @ #{Time.now.utc}"
97
86
 
98
- result = subject.exec(%Q{echo "#{data}"})
99
- result.output.match(data).should_not be nil
87
+ result = subject.exec(%{echo "#{data}"})
88
+ expect(result.output).to match(data)
100
89
  end
101
90
 
102
91
  it "should allow us to change the expected exit code" do
103
- subject.config do |config|
104
- config.ui = @ui
105
- end
92
+ subject.config.ui = ui
93
+
106
94
  data = 32
107
- result = subject.exec(%Q{/bin/bash -c 'exit #{data}'}, :exit_code => data)
95
+ result = subject.exec(%{exit #{data}}, :exit_code => data)
96
+ expect(result.exit_code).to be == data
108
97
  end
109
98
 
110
99
  describe "stdout" do
111
100
 
112
101
  it "should capture STDOUT and send it to the appropriate pipe" do
113
- subject.config do |config|
114
- config.ui = @ui
115
- end
102
+ subject.config.ui = ui
103
+
116
104
  data = "Hello World @ #{Time.now.utc}"
117
105
 
118
- subject.exec(%Q{echo "#{data}" >&1})
106
+ subject.exec(%{echo "#{data}" >&1})
119
107
 
120
- @ui.stdout.rewind
121
- @ui.stdout.read.match(data).should_not be nil
108
+ ui.stdout.rewind
109
+ expect(ui.stdout.read).to match(data)
122
110
 
123
- @ui.stderr.rewind
124
- @ui.stderr.read.match(data).should be nil
111
+ ui.stderr.rewind
112
+ expect(ui.stderr.read).to be_empty
125
113
 
126
- @ui.stdin.rewind
127
- @ui.stdin.read.match(data).should be nil
114
+ ui.stdin.rewind
115
+ expect(ui.stdin.read).to be_empty
128
116
  end
129
117
 
130
118
  end
@@ -132,21 +120,20 @@ describe ZTK::Command do
132
120
  describe "stderr" do
133
121
 
134
122
  it "should capture STDERR and send it to the appropriate pipe" do
135
- subject.config do |config|
136
- config.ui = @ui
137
- end
123
+ subject.config.ui = ui
124
+
138
125
  data = "Hello World @ #{Time.now.utc}"
139
126
 
140
- subject.exec(%Q{echo "#{data}" >&2})
127
+ subject.exec(%{echo "#{data}" >&2})
141
128
 
142
- @ui.stdout.rewind
143
- @ui.stdout.read.match(data).should be nil
129
+ ui.stdout.rewind
130
+ expect(ui.stdout.read).to be_empty
144
131
 
145
- @ui.stderr.rewind
146
- @ui.stderr.read.match(data).should_not be nil
132
+ ui.stderr.rewind
133
+ expect(ui.stderr.read).to match(data)
147
134
 
148
- @ui.stdin.rewind
149
- @ui.stdin.read.match(data).should be nil
135
+ ui.stdin.rewind
136
+ expect(ui.stdin.read).to be_empty
150
137
  end
151
138
  end
152
139
 
@@ -155,7 +142,7 @@ describe ZTK::Command do
155
142
  describe "upload" do
156
143
 
157
144
  it "should raise a 'Not Supported' exception when attempting to upload" do
158
- lambda { subject.upload("abc", "123") }.should raise_error
145
+ expect{ subject.upload("abc", "123") }.to raise_error ZTK::CommandError
159
146
  end
160
147
 
161
148
  end
@@ -163,7 +150,7 @@ describe ZTK::Command do
163
150
  describe "download" do
164
151
 
165
152
  it "should raise a 'Not Supported' exception when attempting to download" do
166
- lambda { subject.download("abc", "123") }.should raise_error
153
+ expect{ subject.download("abc", "123") }.to raise_error ZTK::CommandError
167
154
  end
168
155
 
169
156
  end