code_snippet 0.2.7 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +7 -5
- data/README.md +4 -7
- data/bin/code_snippet +20 -0
- data/bin/snippet +11 -53
- data/code_snippet.gemspec +1 -0
- data/lib/code_snippet/cli.rb +71 -27
- data/lib/code_snippet/commands/list_snippets.rb +41 -0
- data/lib/code_snippet/commands/print_path.rb +20 -0
- data/lib/code_snippet/commands/print_version.rb +19 -0
- data/lib/code_snippet/commands/show_snippet.rb +57 -0
- data/lib/code_snippet/commands.rb +13 -0
- data/lib/code_snippet/manager.rb +5 -1
- data/lib/code_snippet/version.rb +1 -1
- data/spec/code_snippet/cli_spec.rb +203 -0
- data/spec/code_snippet/commands/list_snippets_spec.rb +67 -0
- data/spec/code_snippet/commands/print_path_spec.rb +22 -0
- data/spec/code_snippet/commands/print_version_spec.rb +21 -0
- data/spec/code_snippet/commands/show_snippet_spec.rb +202 -0
- data/spec/{snippet → code_snippet}/manager_spec.rb +25 -2
- data/spec/{snippet → code_snippet}/snip_spec.rb +0 -0
- metadata +37 -15
- data/bitbucket-pipelines.yml +0 -18
- data/lib/code_snippet/cli/commands.rb +0 -82
- data/lib/code_snippet/cli/presenters.rb +0 -42
- data/spec/snippet/cli/commands_spec.rb +0 -104
- data/spec/snippet/cli/presenters_spec.rb +0 -72
- data/spec/snippet/cli_spec.rb +0 -91
@@ -1,72 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe CodeSnippet::CLI::Presenters do
|
4
|
-
let(:snippets) { [snip, snip] }
|
5
|
-
|
6
|
-
let(:snip) { double(CodeSnippet::Snip) }
|
7
|
-
let(:name) { 'snippet' }
|
8
|
-
let(:ext) { '.snip' }
|
9
|
-
let(:path) { 'path/to/snippet' }
|
10
|
-
let(:content) { 'snip-content' }
|
11
|
-
|
12
|
-
before do
|
13
|
-
allow(CodeSnippet::CLI).to receive(:print_message).and_return(double)
|
14
|
-
allow(snip).to receive(:name).and_return(name)
|
15
|
-
allow(snip).to receive(:ext).and_return(ext)
|
16
|
-
allow(snip).to receive(:path).and_return(path)
|
17
|
-
allow(snip).to receive(:content).and_return(content)
|
18
|
-
end
|
19
|
-
describe '.pick_from' do
|
20
|
-
let(:question) { 'are you sure?' }
|
21
|
-
let(:snips) { [snip, snip] }
|
22
|
-
let(:prompt) { double(TTY::Prompt) }
|
23
|
-
|
24
|
-
before do
|
25
|
-
allow(TTY::Prompt).to receive(:new).and_return(prompt)
|
26
|
-
allow(prompt).to receive(:select).and_return(path)
|
27
|
-
@choice = subject.pick_from(question, snips)
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'asks which path' do
|
31
|
-
expect(prompt).to have_received(:select)
|
32
|
-
.with(question, [path, path])
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'returns chosen path' do
|
36
|
-
expect(@choice).to eq snip
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe '.show' do
|
41
|
-
before do
|
42
|
-
described_class.show(snip)
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'puts content to STDOUT' do
|
46
|
-
expect(CodeSnippet::CLI).to have_received(:print_message).with(content)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
describe '.list_snippets' do
|
51
|
-
let(:table) { double(TTY::Table) }
|
52
|
-
before do
|
53
|
-
allow(TTY::Table).to receive(:new).and_return(table)
|
54
|
-
allow(table).to receive(:render)
|
55
|
-
described_class.list_snippets(snippets)
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'sets up render' do
|
59
|
-
expect(TTY::Table).to have_received(:new).with(
|
60
|
-
%w[NAME LANG PATH],
|
61
|
-
[
|
62
|
-
[name, ext, path],
|
63
|
-
[name, ext, path]
|
64
|
-
]
|
65
|
-
)
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'renders table' do
|
69
|
-
expect(table).to have_received(:render).with(:ascii)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
data/spec/snippet/cli_spec.rb
DELETED
@@ -1,91 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe CodeSnippet::CLI do
|
4
|
-
let(:logger) { double(Logger) }
|
5
|
-
let(:message) { 'lorem ipsum' }
|
6
|
-
|
7
|
-
before do
|
8
|
-
allow(described_class).to receive(:exit).and_return(double)
|
9
|
-
end
|
10
|
-
|
11
|
-
describe '.snip_dir' do
|
12
|
-
let(:snippet_dir) { 'path/to/snippets' }
|
13
|
-
let(:exists) { true }
|
14
|
-
|
15
|
-
before do
|
16
|
-
allow(ENV)
|
17
|
-
.to receive(:[])
|
18
|
-
.with('SNIPPET_DIR')
|
19
|
-
.and_return(snippet_dir)
|
20
|
-
|
21
|
-
allow(File).to receive(:exist?).and_return(exists)
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'returns path to snippets' do
|
25
|
-
expect(described_class.snip_dir).to eq snippet_dir
|
26
|
-
end
|
27
|
-
|
28
|
-
context 'when the environment variable is not set' do
|
29
|
-
let(:snippet_dir) { nil }
|
30
|
-
|
31
|
-
it 'raises error' do
|
32
|
-
expect do
|
33
|
-
described_class.snip_dir
|
34
|
-
end.to raise_error 'SNIPPET_DIR environment variable not set'
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
context 'when the snippet directory does not exist' do
|
39
|
-
let(:exists) { false }
|
40
|
-
|
41
|
-
it 'raises error' do
|
42
|
-
expect do
|
43
|
-
described_class.snip_dir
|
44
|
-
end.to raise_error "SNIPPET_DIR #{snippet_dir} does not exist"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe '.logger' do
|
50
|
-
before do
|
51
|
-
allow(Logger).to receive(:new).and_return(logger)
|
52
|
-
allow(logger).to receive(:formatter=)
|
53
|
-
@logger = subject.logger
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'creates a new logger to STDOUT' do
|
57
|
-
expect(Logger).to have_received(:new).with(STDOUT)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe '.print_message' do
|
62
|
-
let(:logger) { double(Logger) }
|
63
|
-
|
64
|
-
before do
|
65
|
-
allow(described_class).to receive(:logger).and_return(logger)
|
66
|
-
allow(logger).to receive(:info)
|
67
|
-
described_class.print_message(message)
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'prints message to stdout' do
|
71
|
-
expect(logger).to have_received(:info).with(message)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
describe '.print_message_and_exit' do
|
76
|
-
let(:exit_code) { 2 }
|
77
|
-
|
78
|
-
before do
|
79
|
-
allow(described_class).to receive(:print_message)
|
80
|
-
described_class.print_message_and_exit(message, exit_code)
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'prints message' do
|
84
|
-
expect(described_class).to have_received(:print_message).with(message)
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'exits with set status' do
|
88
|
-
expect(described_class).to have_received(:exit).with(exit_code)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|