signore 0.2.2 → 0.2.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/.rubocop.yml +4 -10
- data/Gemfile.lock +38 -33
- data/README.md +0 -12
- data/Rakefile +5 -3
- data/bin/signore +1 -1
- data/config/reek.yml +8 -5
- data/lib/signore/cli.rb +28 -0
- data/lib/signore/database.rb +32 -19
- data/lib/signore/settings.rb +36 -0
- data/lib/signore/sig_finder.rb +24 -0
- data/lib/signore/sig_from_stream.rb +38 -0
- data/lib/signore/signature.rb +37 -39
- data/lib/signore/tags.rb +7 -0
- data/lib/signore.rb +1 -9
- data/signore.gemspec +13 -10
- data/spec/signore/cli_spec.rb +92 -0
- data/spec/signore/database_spec.rb +46 -33
- data/spec/signore/settings_spec.rb +47 -0
- data/spec/signore/sig_finder_spec.rb +46 -0
- data/spec/signore/sig_from_stream_spec.rb +54 -0
- data/spec/signore/signature_spec.rb +85 -74
- data/spec/spec_helper.rb +4 -4
- metadata +49 -12
- data/lib/signore/executable.rb +0 -69
- data/spec/signore/executable_spec.rb +0 -125
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
require_relative '../spec_helper'
|
|
2
|
-
|
|
3
|
-
module Signore describe Executable do
|
|
4
|
-
describe '#initialize' do
|
|
5
|
-
it 'prints usage if no command is given' do
|
|
6
|
-
capture_io do
|
|
7
|
-
-> { Executable.new [] }.must_raise SystemExit
|
|
8
|
-
end.last.must_include 'usage: signore prego|pronto [tag, …]'
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
it 'prints usage if a bogus command is given' do
|
|
12
|
-
capture_io do
|
|
13
|
-
-> { Executable.new ['bogus'] }.must_raise SystemExit
|
|
14
|
-
end.last.must_include 'usage: signore prego|pronto [tag, …]'
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
it 'loads the signature database from the specified location' do
|
|
18
|
-
db_factory = MiniTest::Mock.new.expect :new, nil, ['signatures.yml']
|
|
19
|
-
Executable.new %w(-d signatures.yml prego), db_factory: db_factory
|
|
20
|
-
db_factory.verify
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
it 'defaults to ~/.local/share/signore/signatures.yml' do
|
|
24
|
-
begin
|
|
25
|
-
orig = ENV.delete 'XDG_DATA_HOME'
|
|
26
|
-
default_path = File.expand_path '~/.local/share/signore/signatures.yml'
|
|
27
|
-
db_factory = MiniTest::Mock.new
|
|
28
|
-
db_factory.expect :new, nil, [default_path]
|
|
29
|
-
Executable.new ['prego'], db_factory: db_factory
|
|
30
|
-
db_factory.verify
|
|
31
|
-
ensure
|
|
32
|
-
ENV['XDG_DATA_HOME'] = orig if orig
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
it 'defaults to $XDG_DATA_HOME/signore/signatures.yml' do
|
|
37
|
-
begin
|
|
38
|
-
orig = ENV.delete 'XDG_DATA_HOME'
|
|
39
|
-
ENV['XDG_DATA_HOME'] = Dir.tmpdir
|
|
40
|
-
default_path = "#{ENV['XDG_DATA_HOME']}/signore/signatures.yml"
|
|
41
|
-
db_factory = MiniTest::Mock.new
|
|
42
|
-
db_factory.expect :new, nil, [default_path]
|
|
43
|
-
Executable.new ['prego'], db_factory: db_factory
|
|
44
|
-
db_factory.verify
|
|
45
|
-
ensure
|
|
46
|
-
orig ? ENV['XDG_DATA_HOME'] = orig : ENV.delete('XDG_DATA_HOME')
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
describe '#run' do
|
|
52
|
-
describe 'prego' do
|
|
53
|
-
it 'prints a signature tagged with the provided tags' do
|
|
54
|
-
args = %w(-d spec/fixtures/signatures.yml prego tech programming)
|
|
55
|
-
output = "// sometimes I believe compiler ignores all my comments\n"
|
|
56
|
-
stdout = capture_io { Executable.new(args).run }.first
|
|
57
|
-
stdout.must_equal output
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
it 'prints a signature based on allowed and forbidden tags' do
|
|
61
|
-
path = 'spec/fixtures/signatures.yml'
|
|
62
|
-
args = %W(-d #{path} prego ~programming tech ~security)
|
|
63
|
-
out = capture_io { Executable.new(args).run }.first
|
|
64
|
-
out.must_equal <<-end.dedent
|
|
65
|
-
You do have to be mad to work here, but it doesn’t help.
|
|
66
|
-
[Gary Barnes, asr]
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
describe 'pronto' do
|
|
72
|
-
before do
|
|
73
|
-
@file = Tempfile.new ''
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
it 'asks about signature parts and saves resulting signature' do
|
|
77
|
-
input = StringIO.new <<-end.dedent
|
|
78
|
-
The Wikipedia page on ADHD is like 20 pages long. That’s just cruel.
|
|
79
|
-
|
|
80
|
-
Mark Pilgrim\n\n\n
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
capture_io do
|
|
84
|
-
args = %W(-d #{@file.path} pronto Wikipedia ADHD)
|
|
85
|
-
Executable.new(args).run input: input
|
|
86
|
-
end.first.must_equal <<-end.dedent
|
|
87
|
-
text?
|
|
88
|
-
author?
|
|
89
|
-
subject?
|
|
90
|
-
source?
|
|
91
|
-
The Wikipedia page on ADHD is like 20 pages long. That’s just cruel.
|
|
92
|
-
[Mark Pilgrim]
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
capture_io do
|
|
96
|
-
Executable.new(%W(-d #{@file.path} prego Wikipedia ADHD)).run
|
|
97
|
-
end.first.must_equal <<-end.dedent
|
|
98
|
-
The Wikipedia page on ADHD is like 20 pages long. That’s just cruel.
|
|
99
|
-
[Mark Pilgrim]
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
it 'handles multi-line signatures' do
|
|
104
|
-
input = StringIO.new <<-end.dedent
|
|
105
|
-
‘You’ve got an interesting accent. Subtle. I can’t place it.’
|
|
106
|
-
‘It’s text-to-speech… I was raised by smartphones.’
|
|
107
|
-
|
|
108
|
-
Patrick Ewing\n\n\n
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
capture_io do
|
|
112
|
-
Executable.new(['-d', @file.path, 'pronto']).run input: input
|
|
113
|
-
end.first.must_equal <<-end.dedent
|
|
114
|
-
text?
|
|
115
|
-
author?
|
|
116
|
-
subject?
|
|
117
|
-
source?
|
|
118
|
-
‘You’ve got an interesting accent. Subtle. I can’t place it.’
|
|
119
|
-
‘It’s text-to-speech… I was raised by smartphones.’
|
|
120
|
-
[Patrick Ewing]
|
|
121
|
-
end
|
|
122
|
-
end
|
|
123
|
-
end
|
|
124
|
-
end
|
|
125
|
-
end end
|