infopark-user_io 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +142 -0
- data/.ruby-version +1 -0
- data/Gemfile +9 -0
- data/Rakefile +3 -1
- data/lib/infopark/user_io/global.rb +10 -4
- data/lib/infopark/user_io/version.rb +3 -1
- data/lib/infopark/user_io.rb +263 -254
- data/lib/infopark-user_io.rb +3 -1
- data/spec/progress_spec.rb +114 -115
- data/spec/spec_helper.rb +51 -51
- data/spec/user_io/global_spec.rb +7 -5
- data/spec/user_io_spec.rb +297 -305
- data/user_io.gemspec +10 -10
- metadata +13 -53
data/spec/progress_spec.rb
CHANGED
@@ -1,157 +1,156 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
module Infopark
|
4
4
|
COLOR_BRIGHT_GREEN = "\e[1;32m"
|
5
5
|
COLOR_NORMAL = "\e[22;39m"
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
subject(:progress) { UserIO::Progress.new("the label", user_io) }
|
7
|
+
RSpec.describe(UserIO::Progress) do
|
8
|
+
let(:user_io) { UserIO.new }
|
10
9
|
|
11
|
-
|
10
|
+
subject(:progress) { UserIO::Progress.new("the label", user_io) }
|
12
11
|
|
13
|
-
|
14
|
-
subject(:start) { progress.start }
|
12
|
+
before { allow($stdout).to(receive(:write)) }
|
15
13
|
|
16
|
-
|
17
|
-
|
18
|
-
start
|
19
|
-
end
|
20
|
-
|
21
|
-
context "if already started" do
|
22
|
-
before { progress.start }
|
14
|
+
describe "#start" do
|
15
|
+
subject(:start) { progress.start }
|
23
16
|
|
24
|
-
it "
|
25
|
-
expect($stdout).
|
17
|
+
it "starts the progress" do
|
18
|
+
expect($stdout).to(receive(:write).with("the label "))
|
26
19
|
start
|
27
20
|
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "#increment" do
|
32
|
-
subject(:increment) { progress.increment }
|
33
21
|
|
34
|
-
|
35
|
-
|
22
|
+
context "if already started" do
|
23
|
+
before { progress.start }
|
36
24
|
|
37
|
-
|
38
|
-
|
39
|
-
|
25
|
+
it "does nothing" do
|
26
|
+
expect($stdout).to_not(receive(:write))
|
27
|
+
start
|
28
|
+
end
|
40
29
|
end
|
41
30
|
end
|
42
31
|
|
43
|
-
|
44
|
-
|
45
|
-
expect { increment }.to raise_error(/not started/)
|
46
|
-
end
|
47
|
-
end
|
32
|
+
describe "#increment" do
|
33
|
+
subject(:increment) { progress.increment }
|
48
34
|
|
49
|
-
|
50
|
-
|
51
|
-
progress.start
|
52
|
-
progress.finish
|
53
|
-
end
|
35
|
+
context "on a started progress" do
|
36
|
+
before { progress.start }
|
54
37
|
|
55
|
-
|
56
|
-
|
38
|
+
it "increments" do
|
39
|
+
expect($stdout).to(receive(:write).with("."))
|
40
|
+
increment
|
41
|
+
end
|
57
42
|
end
|
58
|
-
end
|
59
|
-
end
|
60
43
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
context "on a started progress" do
|
66
|
-
before { progress.start }
|
67
|
-
|
68
|
-
it "spins" do
|
69
|
-
expect($stdout).to receive(:write).with("-\b").ordered
|
70
|
-
progress.spin
|
71
|
-
expect($stdout).to receive(:write).with("\\\b").ordered
|
72
|
-
progress.spin
|
73
|
-
expect($stdout).to receive(:write).with("|\b").ordered
|
74
|
-
progress.spin
|
75
|
-
expect($stdout).to receive(:write).with("/\b").ordered
|
76
|
-
progress.spin
|
77
|
-
expect($stdout).to receive(:write).with("-\b").ordered
|
78
|
-
progress.spin
|
79
|
-
expect($stdout).to receive(:write).with("\\\b").ordered
|
80
|
-
progress.spin
|
81
|
-
expect($stdout).to receive(:write).with("|\b").ordered
|
82
|
-
progress.spin
|
83
|
-
expect($stdout).to receive(:write).with("/\b").ordered
|
84
|
-
progress.spin
|
44
|
+
context "on a not started progress" do
|
45
|
+
it "fails" do
|
46
|
+
expect { increment }.to(raise_error(/not started/))
|
47
|
+
end
|
85
48
|
end
|
86
49
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
expect($stdout).to receive(:write).with("\\\b").ordered
|
97
|
-
progress.spin
|
98
|
-
expect($stdout).to receive(:write).with("|\b").ordered
|
99
|
-
progress.spin
|
100
|
-
expect($stdout).to receive(:write).with("/\b").ordered
|
101
|
-
progress.spin
|
50
|
+
context "on a finished progress" do
|
51
|
+
before do
|
52
|
+
progress.start
|
53
|
+
progress.finish
|
54
|
+
end
|
55
|
+
|
56
|
+
it "fails" do
|
57
|
+
expect { increment }.to(raise_error(/not started/))
|
58
|
+
end
|
102
59
|
end
|
103
60
|
end
|
104
61
|
|
105
|
-
|
106
|
-
|
107
|
-
|
62
|
+
describe "#spin" do
|
63
|
+
subject(:spin) { progress.spin }
|
64
|
+
|
65
|
+
context "on a started progress" do
|
66
|
+
before { progress.start }
|
67
|
+
|
68
|
+
it "spins" do
|
69
|
+
expect($stdout).to(receive(:write).with("-\b").ordered)
|
70
|
+
progress.spin
|
71
|
+
expect($stdout).to(receive(:write).with("\\\b").ordered)
|
72
|
+
progress.spin
|
73
|
+
expect($stdout).to(receive(:write).with("|\b").ordered)
|
74
|
+
progress.spin
|
75
|
+
expect($stdout).to(receive(:write).with("/\b").ordered)
|
76
|
+
progress.spin
|
77
|
+
expect($stdout).to(receive(:write).with("-\b").ordered)
|
78
|
+
progress.spin
|
79
|
+
expect($stdout).to(receive(:write).with("\\\b").ordered)
|
80
|
+
progress.spin
|
81
|
+
expect($stdout).to(receive(:write).with("|\b").ordered)
|
82
|
+
progress.spin
|
83
|
+
expect($stdout).to(receive(:write).with("/\b").ordered)
|
84
|
+
progress.spin
|
85
|
+
end
|
86
|
+
|
87
|
+
it "starts spinning from begin when interrupted by an increment" do
|
88
|
+
expect($stdout).to(receive(:write).with("-\b").ordered)
|
89
|
+
progress.spin
|
90
|
+
expect($stdout).to(receive(:write).with("\\\b").ordered)
|
91
|
+
progress.spin
|
92
|
+
expect($stdout).to(receive(:write).with(".").ordered)
|
93
|
+
progress.increment
|
94
|
+
expect($stdout).to(receive(:write).with("-\b").ordered)
|
95
|
+
progress.spin
|
96
|
+
expect($stdout).to(receive(:write).with("\\\b").ordered)
|
97
|
+
progress.spin
|
98
|
+
expect($stdout).to(receive(:write).with("|\b").ordered)
|
99
|
+
progress.spin
|
100
|
+
expect($stdout).to(receive(:write).with("/\b").ordered)
|
101
|
+
progress.spin
|
102
|
+
end
|
108
103
|
end
|
109
|
-
end
|
110
104
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
105
|
+
context "on a not started progress" do
|
106
|
+
it "fails" do
|
107
|
+
expect { spin }.to(raise_error(/not started/))
|
108
|
+
end
|
115
109
|
end
|
116
110
|
|
117
|
-
|
118
|
-
|
111
|
+
context "on a finished progress" do
|
112
|
+
before do
|
113
|
+
progress.start
|
114
|
+
progress.finish
|
115
|
+
end
|
116
|
+
|
117
|
+
it "fails" do
|
118
|
+
expect { spin }.to(raise_error(/not started/))
|
119
|
+
end
|
119
120
|
end
|
120
121
|
end
|
121
|
-
end
|
122
122
|
|
123
|
-
|
124
|
-
|
123
|
+
describe "#finish" do
|
124
|
+
subject(:finish) { progress.finish }
|
125
125
|
|
126
|
-
|
127
|
-
|
126
|
+
context "on a started progress" do
|
127
|
+
before { progress.start }
|
128
128
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
129
|
+
it "finishes" do
|
130
|
+
expect($stdout).to(receive(:write).with("… "))
|
131
|
+
expect($stdout).to(receive(:write).with("#{COLOR_BRIGHT_GREEN}OK#{COLOR_NORMAL}\n"))
|
132
|
+
finish
|
133
|
+
end
|
133
134
|
end
|
134
|
-
end
|
135
135
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
136
|
+
context "on a not started progress" do
|
137
|
+
it "does nothing" do
|
138
|
+
expect($stdout).to_not(receive(:write))
|
139
|
+
finish
|
140
|
+
end
|
140
141
|
end
|
141
|
-
end
|
142
142
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
143
|
+
context "on a finished progress" do
|
144
|
+
before do
|
145
|
+
progress.start
|
146
|
+
progress.finish
|
147
|
+
end
|
148
148
|
|
149
|
-
|
150
|
-
|
151
|
-
|
149
|
+
it "does nothing" do
|
150
|
+
expect($stdout).to_not(receive(:write))
|
151
|
+
finish
|
152
|
+
end
|
152
153
|
end
|
153
154
|
end
|
154
155
|
end
|
155
156
|
end
|
156
|
-
|
157
|
-
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../lib/infopark-user_io"
|
2
4
|
|
3
5
|
RSpec.configure do |config|
|
4
|
-
config.expect_with
|
6
|
+
config.expect_with(:rspec) do |expectations|
|
5
7
|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
6
8
|
end
|
7
9
|
|
8
|
-
config.mock_with
|
10
|
+
config.mock_with(:rspec) do |mocks|
|
9
11
|
mocks.verify_partial_doubles = true
|
10
12
|
end
|
11
13
|
|
@@ -13,52 +15,50 @@ RSpec.configure do |config|
|
|
13
15
|
|
14
16
|
config.example_status_persistence_file_path = "spec/examples.txt"
|
15
17
|
|
16
|
-
# The settings below are suggested to provide a good initial experience
|
17
|
-
# with RSpec, but feel free to customize to your heart's content.
|
18
|
-
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
|
25
|
-
|
26
|
-
#
|
27
|
-
#
|
28
|
-
# - http://
|
29
|
-
# - http://
|
30
|
-
#
|
31
|
-
|
32
|
-
|
33
|
-
#
|
34
|
-
#
|
35
|
-
|
36
|
-
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
#
|
48
|
-
#
|
49
|
-
#
|
50
|
-
|
51
|
-
|
52
|
-
#
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
56
|
-
|
57
|
-
|
58
|
-
#
|
59
|
-
#
|
60
|
-
#
|
61
|
-
#
|
62
|
-
Kernel.srand config.seed
|
63
|
-
=end
|
18
|
+
# The settings below are suggested to provide a good initial experience
|
19
|
+
# with RSpec, but feel free to customize to your heart's content.
|
20
|
+
# # This allows you to limit a spec run to individual examples or groups
|
21
|
+
# # you care about by tagging them with `:focus` metadata. When nothing
|
22
|
+
# # is tagged with `:focus`, all examples get run. RSpec also provides
|
23
|
+
# # aliases for `it`, `describe`, and `context` that include `:focus`
|
24
|
+
# # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
25
|
+
# config.filter_run_when_matching :focus
|
26
|
+
#
|
27
|
+
# # Limits the available syntax to the non-monkey patched syntax that is
|
28
|
+
# # recommended. For more details, see:
|
29
|
+
# # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
30
|
+
# # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
31
|
+
# # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
32
|
+
# config.disable_monkey_patching!
|
33
|
+
#
|
34
|
+
# # This setting enables warnings. It's recommended, but in some cases may
|
35
|
+
# # be too noisy due to issues in dependencies.
|
36
|
+
# config.warnings = true
|
37
|
+
#
|
38
|
+
# # Many RSpec users commonly either run the entire suite or an individual
|
39
|
+
# # file, and it's useful to allow more verbose output when running an
|
40
|
+
# # individual spec file.
|
41
|
+
# if config.files_to_run.one?
|
42
|
+
# # Use the documentation formatter for detailed output,
|
43
|
+
# # unless a formatter has already been configured
|
44
|
+
# # (e.g. via a command-line flag).
|
45
|
+
# config.default_formatter = "doc"
|
46
|
+
# end
|
47
|
+
#
|
48
|
+
# # Print the 10 slowest examples and example groups at the
|
49
|
+
# # end of the spec run, to help surface which specs are running
|
50
|
+
# # particularly slow.
|
51
|
+
# config.profile_examples = 10
|
52
|
+
#
|
53
|
+
# # Run specs in random order to surface order dependencies. If you find an
|
54
|
+
# # order dependency and want to debug it, you can fix the order by providing
|
55
|
+
# # the seed, which is printed after each run.
|
56
|
+
# # --seed 1234
|
57
|
+
# config.order = :random
|
58
|
+
#
|
59
|
+
# # Seed global randomization in this process using the `--seed` CLI option.
|
60
|
+
# # Setting this allows you to use `--seed` to deterministically reproduce
|
61
|
+
# # test failures related to randomization by passing the same `--seed` value
|
62
|
+
# # as the one that triggered the failure.
|
63
|
+
# Kernel.srand config.seed
|
64
64
|
end
|
data/spec/user_io/global_spec.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class GlobalTest
|
4
|
+
include ::Infopark::UserIO::Global
|
5
|
+
end
|
5
6
|
|
7
|
+
RSpec.describe(Infopark::UserIO::Global) do
|
6
8
|
subject(:global_included) { GlobalTest.new }
|
7
9
|
|
8
10
|
let(:user_io) { ::Infopark::UserIO.new }
|
@@ -14,6 +16,6 @@ RSpec.describe Infopark::UserIO::Global do
|
|
14
16
|
end
|
15
17
|
|
16
18
|
it "provides convenience access to UserIO.global" do
|
17
|
-
expect(global_included.user_io).to
|
19
|
+
expect(global_included.user_io).to(be(user_io))
|
18
20
|
end
|
19
21
|
end
|