stickyflag 0.2.0
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.
- data/.gitignore +7 -0
- data/.rspec +4 -0
- data/.simplecov +9 -0
- data/.travis.yml +13 -0
- data/Gemfile +2 -0
- data/LICENSE.md +7 -0
- data/README.md +49 -0
- data/Rakefile +19 -0
- data/TODO.md +3 -0
- data/bin/stickyflag +6 -0
- data/features/clear.feature +14 -0
- data/features/clear_quietly.feature +23 -0
- data/features/configuration.feature +14 -0
- data/features/get.feature +14 -0
- data/features/get_quietly.feature +23 -0
- data/features/set.feature +14 -0
- data/features/set_quietly.feature +22 -0
- data/features/step_definitions/configuration_steps.rb +31 -0
- data/features/step_definitions/database_steps.rb +41 -0
- data/features/step_definitions/pending_steps.rb +5 -0
- data/features/step_definitions/tag_steps.rb +62 -0
- data/features/support/cukegem.rb +82 -0
- data/features/support/env.rb +37 -0
- data/features/tags.feature +18 -0
- data/features/unset.feature +14 -0
- data/features/unset_quietly.feature +23 -0
- data/lib/stickyflag/configuration.rb +66 -0
- data/lib/stickyflag/database.rb +162 -0
- data/lib/stickyflag/external_cmds.rb +64 -0
- data/lib/stickyflag/patches/tempfile_encoding.rb +22 -0
- data/lib/stickyflag/patches/tmpnam.rb +38 -0
- data/lib/stickyflag/paths.rb +47 -0
- data/lib/stickyflag/tag_factory.rb +108 -0
- data/lib/stickyflag/tags/c.rb +25 -0
- data/lib/stickyflag/tags/mmd.rb +168 -0
- data/lib/stickyflag/tags/pdf.rb +119 -0
- data/lib/stickyflag/tags/png.rb +61 -0
- data/lib/stickyflag/tags/source_code.rb +99 -0
- data/lib/stickyflag/tags/tex.rb +25 -0
- data/lib/stickyflag/version.rb +12 -0
- data/lib/stickyflag.rb +253 -0
- data/spec/spec_helper.rb +22 -0
- data/spec/stickyflag/configuration_spec.rb +132 -0
- data/spec/stickyflag/database_spec.rb +331 -0
- data/spec/stickyflag/external_cmds_spec.rb +175 -0
- data/spec/stickyflag/patches/tempfile_encoding_spec.rb +26 -0
- data/spec/stickyflag/patches/tmpnam_spec.rb +35 -0
- data/spec/stickyflag/paths_spec.rb +29 -0
- data/spec/stickyflag/tag_factory_spec.rb +185 -0
- data/spec/stickyflag/tags/c_spec.rb +14 -0
- data/spec/stickyflag/tags/mmd_spec.rb +40 -0
- data/spec/stickyflag/tags/pdf_spec.rb +39 -0
- data/spec/stickyflag/tags/png_spec.rb +6 -0
- data/spec/stickyflag/tags/tex_spec.rb +6 -0
- data/spec/stickyflag_spec.rb +482 -0
- data/spec/support/examples/c_all_comments.c +3 -0
- data/spec/support/examples/c_no_tags.c +5 -0
- data/spec/support/examples/c_with_tag.c +6 -0
- data/spec/support/examples/mmd_all_meta.mmd +6 -0
- data/spec/support/examples/mmd_crazy_keys.mmd +8 -0
- data/spec/support/examples/mmd_crazy_tags.mmd +9 -0
- data/spec/support/examples/mmd_no_tags.mmd +1 -0
- data/spec/support/examples/mmd_with_tag.mmd +3 -0
- data/spec/support/examples/pdf_no_tags.pdf +0 -0
- data/spec/support/examples/pdf_with_tag.pdf +0 -0
- data/spec/support/examples/png_no_tags.png +0 -0
- data/spec/support/examples/png_with_tag.png +0 -0
- data/spec/support/examples/tex_no_tags.tex +10 -0
- data/spec/support/examples/tex_with_tag.tex +11 -0
- data/spec/support/examples/untaggable.txt +0 -0
- data/spec/support/examples.rb +32 -0
- data/spec/support/run_with_args.rb +36 -0
- data/spec/support/silence_stream.rb +12 -0
- data/spec/support/tag_handler_behavior.rb +125 -0
- data/stickyflag.gemspec +48 -0
- metadata +399 -0
@@ -0,0 +1,132 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'stickyflag/paths'
|
3
|
+
require 'stickyflag/configuration'
|
4
|
+
|
5
|
+
class ConfigTester < Thor
|
6
|
+
include StickyFlag::Paths
|
7
|
+
include StickyFlag::Configuration
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'StickyFlag::Configuration' do
|
11
|
+
describe '#initialize' do
|
12
|
+
it 'loads default configuration values' do
|
13
|
+
@obj = ConfigTester.new
|
14
|
+
@obj.stub(:load_config!) { }
|
15
|
+
@obj.stub(:save_config!) { }
|
16
|
+
|
17
|
+
StickyFlag::Configuration::DEFAULT_CONFIG.keys.each do |k|
|
18
|
+
@obj.get_config(k).should eq(StickyFlag::Configuration::DEFAULT_CONFIG[k])
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '.get_config' do
|
24
|
+
before(:each) do
|
25
|
+
@obj = ConfigTester.new
|
26
|
+
|
27
|
+
@obj.stub(:load_config!) { }
|
28
|
+
@obj.stub(:save_config!) { }
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'with good keys' do
|
32
|
+
it 'reads default values' do
|
33
|
+
@obj.get_config(:have_pdftk).should eq(false)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'reads updated values' do
|
37
|
+
@obj.set_config :have_pdftk, true
|
38
|
+
@obj.get_config(:have_pdftk).should eq(true)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'with bad keys' do
|
43
|
+
it 'raises an error on get' do
|
44
|
+
expect { @obj.get_config(:bad_key) }.to raise_error
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'raises an error on set' do
|
48
|
+
expect { @obj.set_config(:bad_key, 'test') }.to raise_error
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '.reset_config!' do
|
54
|
+
before(:each) do
|
55
|
+
@obj = ConfigTester.new
|
56
|
+
|
57
|
+
@obj.stub(:load_config!) { }
|
58
|
+
@obj.stub(:save_config!) { }
|
59
|
+
|
60
|
+
@obj.set_config :have_pdftk, true
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'resets changed values to defaults' do
|
64
|
+
@obj.reset_config!
|
65
|
+
@obj.get_config(:have_pdftk).should eq(false)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe '.dump_config' do
|
70
|
+
before(:each) do
|
71
|
+
@obj = ConfigTester.new
|
72
|
+
|
73
|
+
@obj.stub(:load_config!) { }
|
74
|
+
@obj.stub(:save_config!) { }
|
75
|
+
|
76
|
+
@obj.set_config :pdftk_path, 'wut'
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'prints out the set configuration values' do
|
80
|
+
@obj.stub(:say) {}
|
81
|
+
@obj.should_receive(:say).with(/pdftk_path: 'wut'/)
|
82
|
+
@obj.dump_config
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe '.load_config!' do
|
87
|
+
before(:each) do
|
88
|
+
@obj = ConfigTester.new
|
89
|
+
|
90
|
+
@obj.stub(:save_config!) { }
|
91
|
+
|
92
|
+
@config_file = File.join(File.dirname(__FILE__), 'config.yml')
|
93
|
+
@obj.stub(:config_path) { @config_file }
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'should load from the requested YAML file' do
|
97
|
+
config = {
|
98
|
+
:have_pdftk => true,
|
99
|
+
:pdftk_path => 'wut'
|
100
|
+
}
|
101
|
+
File.open(@config_file, 'w:UTF-8') do |f|
|
102
|
+
YAML.dump(config, f)
|
103
|
+
end
|
104
|
+
|
105
|
+
@obj.load_config!
|
106
|
+
@obj.get_config(:pdftk_path).should eq('wut')
|
107
|
+
|
108
|
+
File.delete(@config_file)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe '.save_config!' do
|
113
|
+
before(:each) do
|
114
|
+
@obj = ConfigTester.new
|
115
|
+
|
116
|
+
@obj.stub(:load_config!) { }
|
117
|
+
|
118
|
+
@config_file = File.join(File.dirname(__FILE__), 'config.yml')
|
119
|
+
@obj.stub(:config_path) { @config_file }
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'should save to the requested YAML file' do
|
123
|
+
@obj.set_config :pdftk_path, 'wut'
|
124
|
+
@obj.save_config!
|
125
|
+
|
126
|
+
config = YAML::load(File.open(@config_file, 'r:UTF-8'))
|
127
|
+
config[:pdftk_path].should eq('wut')
|
128
|
+
|
129
|
+
File.delete(@config_file)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
@@ -0,0 +1,331 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'stickyflag/paths'
|
3
|
+
require 'stickyflag/configuration'
|
4
|
+
require 'stickyflag/external_cmds'
|
5
|
+
require 'stickyflag/tag_factory'
|
6
|
+
require 'stickyflag/database'
|
7
|
+
|
8
|
+
class DatabaseTester < Thor
|
9
|
+
include StickyFlag::Paths
|
10
|
+
include StickyFlag::Configuration
|
11
|
+
include StickyFlag::ExternalCmds
|
12
|
+
include StickyFlag::TagFactory
|
13
|
+
include StickyFlag::Database
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'StickyFlag::Database' do
|
17
|
+
before(:each) do
|
18
|
+
@obj = DatabaseTester.new
|
19
|
+
|
20
|
+
@obj.stub(:load_config!) { }
|
21
|
+
@obj.stub(:save_config!) { }
|
22
|
+
@obj.stub(:database_path) { ":memory:" }
|
23
|
+
|
24
|
+
@obj.find_external_cmds
|
25
|
+
@obj.load_database
|
26
|
+
|
27
|
+
# Save this out for (lots of) later use
|
28
|
+
@database = @obj.instance_variable_get(:@database)
|
29
|
+
end
|
30
|
+
|
31
|
+
after(:each) do
|
32
|
+
# We've disabled automatic cleanup, so make sure we do this
|
33
|
+
@database.disconnect
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '.load_database' do
|
37
|
+
it 'sets the member variable' do
|
38
|
+
@database.should be
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '.update_database_from_files' do
|
43
|
+
context 'without a specific directory' do
|
44
|
+
before(:each) do
|
45
|
+
@obj.update_database_from_files
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'has some files in the database' do
|
49
|
+
@database[:tagged_files].should_not be_empty
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'has found the test and asdf tags' do
|
53
|
+
@obj.tag_list.should include('asdf')
|
54
|
+
@obj.tag_list.should include('test')
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'has found a sample markdown file' do
|
58
|
+
path = example_path 'mmd_crazy_keys.mmd'
|
59
|
+
@obj.files_for_tags(['test']).map { |f| File.expand_path(f) }.should include(path)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'with an empty directory' do
|
64
|
+
before(:each) do
|
65
|
+
@dir = File.tmpnam('.dir')
|
66
|
+
Dir.mkdir(@dir)
|
67
|
+
|
68
|
+
@obj.update_database_from_files(@dir)
|
69
|
+
end
|
70
|
+
|
71
|
+
after(:each) do
|
72
|
+
Dir.rmdir(@dir)
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'has no files in the database' do
|
76
|
+
@database[:tagged_files].should be_empty
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context 'with some bad files in the directory' do
|
81
|
+
before(:each) do
|
82
|
+
@dir = File.tmpnam('.dir')
|
83
|
+
Dir.mkdir(@dir)
|
84
|
+
|
85
|
+
file = File.new(File.join(@dir, 'bad.pdf'), 'w:UTF-8')
|
86
|
+
file.puts('test bad')
|
87
|
+
file.close
|
88
|
+
end
|
89
|
+
|
90
|
+
after(:each) do
|
91
|
+
File.unlink(File.join(@dir, 'bad.pdf'))
|
92
|
+
Dir.rmdir(@dir)
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'does not throw an exception' do
|
96
|
+
expect { @obj.update_database_from_files(@dir) }.to_not raise_error
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'prints a warning' do
|
100
|
+
@obj.should_receive(:say_status).with(:warning, kind_of(String), kind_of(Symbol))
|
101
|
+
@obj.update_database_from_files(@dir)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context 'with a full directory' do
|
106
|
+
before(:each) do
|
107
|
+
@obj.update_database_from_files(example_root)
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'has some files in the database' do
|
111
|
+
@database[:tagged_files].should_not be_empty
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'has found the test and asdf tags' do
|
115
|
+
@obj.tag_list.should include('asdf')
|
116
|
+
@obj.tag_list.should include('test')
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'has found a sample markdown file' do
|
120
|
+
path = example_path 'mmd_crazy_keys.mmd'
|
121
|
+
@obj.files_for_tags(['test']).map { |f| File.expand_path(f) }.should include(path)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe '.set_database_tag' do
|
127
|
+
context 'with an already extant tag' do
|
128
|
+
before(:each) do
|
129
|
+
@obj.update_database_from_files example_root
|
130
|
+
@path = example_path 'mmd_with_tag.mmd'
|
131
|
+
@obj.set_database_tag(@path, 'asdf')
|
132
|
+
end
|
133
|
+
|
134
|
+
it "adds the record for the tagged file" do
|
135
|
+
file_id = @database[:file_list].where(:file_name => @path).get(:id)
|
136
|
+
file_id.should_not be_nil
|
137
|
+
|
138
|
+
tag_id = @database[:tag_list].where(:tag_name => 'asdf').get(:id)
|
139
|
+
tag_id.should_not be_nil
|
140
|
+
|
141
|
+
ds = @database[:tagged_files].where(:file => file_id).and(:tag => tag_id)
|
142
|
+
ds.should_not be_empty
|
143
|
+
ds.count.should eq(1)
|
144
|
+
end
|
145
|
+
|
146
|
+
it "doesn't duplicate the entry for the tag" do
|
147
|
+
ds = @database[:tag_list].where(:tag_name => 'asdf')
|
148
|
+
ds.count.should eq(1)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
context 'with a new tag' do
|
153
|
+
before(:each) do
|
154
|
+
@obj.update_database_from_files example_root
|
155
|
+
@path = example_path 'mmd_with_tag.mmd'
|
156
|
+
@obj.set_database_tag(@path, 'zuzzax')
|
157
|
+
end
|
158
|
+
|
159
|
+
it "adds a new record for the new tag" do
|
160
|
+
ds = @database[:tag_list].where(:tag_name => 'zuzzax')
|
161
|
+
ds.should_not be_empty
|
162
|
+
ds.count.should eq(1)
|
163
|
+
end
|
164
|
+
|
165
|
+
it "adds the record for the tagged file" do
|
166
|
+
file_id = @database[:file_list].where(:file_name => @path).get(:id)
|
167
|
+
file_id.should_not be_nil
|
168
|
+
|
169
|
+
tag_id = @database[:tag_list].where(:tag_name => 'zuzzax').get(:id)
|
170
|
+
tag_id.should_not be_nil
|
171
|
+
|
172
|
+
ds = @database[:tagged_files].where(:file => file_id).and(:tag => tag_id)
|
173
|
+
ds.should_not be_empty
|
174
|
+
ds.count.should eq(1)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
describe '.unset_database_tag' do
|
180
|
+
context 'with a multiply-present tag' do
|
181
|
+
before(:each) do
|
182
|
+
@obj.update_database_from_files example_root
|
183
|
+
@path = example_path 'mmd_with_tag.mmd'
|
184
|
+
end
|
185
|
+
|
186
|
+
it 'removes the record for the tagged file' do
|
187
|
+
@obj.unset_database_tag(@path, 'test')
|
188
|
+
|
189
|
+
file_id = @database[:file_list].where(:file_name => @path).get(:id)
|
190
|
+
file_id.should_not be_nil
|
191
|
+
|
192
|
+
tag_id = @database[:tag_list].where(:tag_name => 'test').get(:id)
|
193
|
+
tag_id.should_not be_nil
|
194
|
+
|
195
|
+
ds = @database[:tagged_files].where(:file => file_id).and(:tag => tag_id)
|
196
|
+
ds.should be_empty
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
context 'with a singly-present tag' do
|
201
|
+
before(:each) do
|
202
|
+
@obj.update_database_from_files example_root
|
203
|
+
@path = example_path 'mmd_crazy_tags.mmd'
|
204
|
+
end
|
205
|
+
|
206
|
+
it 'removes the record for the tagged file' do
|
207
|
+
file_id = @database[:file_list].where(:file_name => @path).get(:id)
|
208
|
+
file_id.should_not be_nil
|
209
|
+
|
210
|
+
tag_id = @database[:tag_list].where(:tag_name => 'qwer').get(:id)
|
211
|
+
tag_id.should_not be_nil
|
212
|
+
|
213
|
+
@obj.unset_database_tag(@path, 'qwer')
|
214
|
+
|
215
|
+
ds = @database[:tagged_files].where(:file => file_id).and(:tag => tag_id)
|
216
|
+
ds.should be_empty
|
217
|
+
end
|
218
|
+
|
219
|
+
it 'removes the record of the tag' do
|
220
|
+
@obj.unset_database_tag(@path, 'qwer')
|
221
|
+
ds = @database[:tag_list].where(:tag_name => 'qwer')
|
222
|
+
ds.should be_empty
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
describe '.clear_database_tags' do
|
228
|
+
before(:each) do
|
229
|
+
@obj.update_database_from_files example_root
|
230
|
+
@path = example_path 'mmd_crazy_tags.mmd'
|
231
|
+
@obj.clear_database_tags(@path)
|
232
|
+
end
|
233
|
+
|
234
|
+
it 'removes all tag records for the file' do
|
235
|
+
file_id = @database[:file_list].where(:file_name => @path).get(:id)
|
236
|
+
file_id.should_not be_nil
|
237
|
+
|
238
|
+
ds = @database[:tagged_files].where(:file => file_id)
|
239
|
+
ds.should be_empty
|
240
|
+
end
|
241
|
+
|
242
|
+
it 'removes the tag after clearing single-instance tags' do
|
243
|
+
ds = @database[:tag_list].where(:tag_name => 'qwer')
|
244
|
+
ds.should be_empty
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
describe '.files_for_tags' do
|
249
|
+
before(:each) do
|
250
|
+
@obj.update_database_from_files example_root
|
251
|
+
end
|
252
|
+
|
253
|
+
context 'with good, single tags' do
|
254
|
+
it 'includes one of the markdown files' do
|
255
|
+
path = example_path 'mmd_crazy_keys.mmd'
|
256
|
+
@obj.files_for_tags([ 'test' ]).should include(path)
|
257
|
+
end
|
258
|
+
|
259
|
+
it 'does not include files that lack a tag' do
|
260
|
+
path = example_path 'mmd_with_tag.mmd'
|
261
|
+
@obj.files_for_tags([ 'asdf' ]).should_not include(path)
|
262
|
+
end
|
263
|
+
|
264
|
+
it 'does not include untaggable files' do
|
265
|
+
path = example_path 'untaggable.txt'
|
266
|
+
@obj.files_for_tags([ 'test' ]).should_not include(path)
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
context 'with multiple tags' do
|
271
|
+
it 'combines with boolean AND' do
|
272
|
+
path1 = example_path 'mmd_crazy_tags.mmd'
|
273
|
+
path2 = example_path 'mmd_with_tag.mmd'
|
274
|
+
|
275
|
+
files = @obj.files_for_tags([ 'sdfg', 'asdf', 'qwer' ])
|
276
|
+
files.should include(path1)
|
277
|
+
files.should_not include(path2)
|
278
|
+
end
|
279
|
+
|
280
|
+
it 'prints a warning if no files have all those tags' do
|
281
|
+
@obj.should_receive(:say_status).with(:warning, kind_of(String), kind_of(Symbol))
|
282
|
+
@obj.files_for_tags([ 'asdf', 'test' ])
|
283
|
+
end
|
284
|
+
|
285
|
+
it 'returns an empty array if no files have all those tags' do
|
286
|
+
@obj.files_for_tags([ 'asdf', 'test' ]).should be_empty
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
context 'with missing tags' do
|
291
|
+
it "doesn't throw" do
|
292
|
+
expect { @obj.files_for_tags([ 'zuzzax' ]) }.to_not raise_error
|
293
|
+
end
|
294
|
+
|
295
|
+
it 'prints a warning' do
|
296
|
+
@obj.should_receive(:say_status).with(:warning, kind_of(String), kind_of(Symbol))
|
297
|
+
@obj.files_for_tags([ 'zuzzax' ])
|
298
|
+
end
|
299
|
+
|
300
|
+
it 'returns an empty array' do
|
301
|
+
@obj.files_for_tags([ 'zuzzax', 'test' ]).should be_empty
|
302
|
+
end
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
describe '.tag_list' do
|
307
|
+
context 'prior to loading anything into the database' do
|
308
|
+
it 'is empty' do
|
309
|
+
@obj.tag_list.should be_empty
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
context 'after loading files into the database' do
|
314
|
+
before(:each) do
|
315
|
+
@obj.update_database_from_files example_root
|
316
|
+
end
|
317
|
+
|
318
|
+
it 'includes multiply-present tags' do
|
319
|
+
@obj.tag_list.should include('test')
|
320
|
+
end
|
321
|
+
|
322
|
+
it 'includes singly-present tags' do
|
323
|
+
@obj.tag_list.should include('qwer')
|
324
|
+
end
|
325
|
+
|
326
|
+
it 'does not include absent tags' do
|
327
|
+
@obj.tag_list.should_not include('zuzzax')
|
328
|
+
end
|
329
|
+
end
|
330
|
+
end
|
331
|
+
end
|
@@ -0,0 +1,175 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'tmpdir'
|
3
|
+
require 'thor'
|
4
|
+
require 'stickyflag/paths'
|
5
|
+
require 'stickyflag/configuration'
|
6
|
+
require 'stickyflag/external_cmds'
|
7
|
+
|
8
|
+
class ExternalCmdsTester < Thor
|
9
|
+
include StickyFlag::Paths
|
10
|
+
include StickyFlag::Configuration
|
11
|
+
include StickyFlag::ExternalCmds
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'StickyFlag::ExternalCmds' do
|
15
|
+
# We want to handle the path manually here
|
16
|
+
def add_to_path(file_name)
|
17
|
+
ENV['PATH'] = Dir.tmpdir
|
18
|
+
|
19
|
+
path = File.join(Dir.tmpdir, file_name)
|
20
|
+
File.open(path, 'w:UTF-8') { |f| f.write('test') }
|
21
|
+
File.chmod(0755, path)
|
22
|
+
|
23
|
+
@files_to_delete << path
|
24
|
+
end
|
25
|
+
|
26
|
+
before(:each) do
|
27
|
+
@files_to_delete = []
|
28
|
+
@old_path = ENV['PATH']
|
29
|
+
ENV['PATH'] = ''
|
30
|
+
end
|
31
|
+
|
32
|
+
after(:each) do
|
33
|
+
ENV['PATH'] = @old_path
|
34
|
+
@files_to_delete.each { |f| File.delete f }
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '.find_external_cmds' do
|
38
|
+
describe 'with no configuration set, no pdftk' do
|
39
|
+
before(:each) do
|
40
|
+
@obj = ExternalCmdsTester.new
|
41
|
+
@obj.stub(:load_config!) { }
|
42
|
+
@obj.stub(:save_config!) { }
|
43
|
+
|
44
|
+
@obj.set_config :pdftk_path, ''
|
45
|
+
@obj.set_config :have_pdftk, false
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'sets have_pdftk to false' do
|
49
|
+
@obj.find_external_cmds
|
50
|
+
@obj.get_config(:have_pdftk).should eq(false)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'outputs a warning message' do
|
54
|
+
@obj.should_receive(:say_status).with(:warning, kind_of(String), kind_of(Symbol))
|
55
|
+
@obj.find_external_cmds
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe 'with no configuration set, with pdftk' do
|
60
|
+
before(:each) do
|
61
|
+
@obj = ExternalCmdsTester.new
|
62
|
+
@obj.stub(:load_config!) { }
|
63
|
+
@obj.stub(:save_config!) { }
|
64
|
+
|
65
|
+
@obj.set_config :pdftk_path, ''
|
66
|
+
@obj.set_config :have_pdftk, false
|
67
|
+
|
68
|
+
add_to_path('pdftk')
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'sets have_pdftk to true' do
|
72
|
+
@obj.find_external_cmds
|
73
|
+
@obj.get_config(:have_pdftk).should eq(true)
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'sets the right pdftk path' do
|
77
|
+
@obj.find_external_cmds
|
78
|
+
|
79
|
+
path = File.expand_path(File.join(Dir.tmpdir, 'pdftk'))
|
80
|
+
@obj.get_config(:pdftk_path).should eq(path)
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'should not print any messages' do
|
84
|
+
@obj.should_not_receive(:say)
|
85
|
+
@obj.should_not_receive(:say_status)
|
86
|
+
@obj.find_external_cmds
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe 'with configuration set, non-executable pdftk' do
|
91
|
+
before(:each) do
|
92
|
+
@obj = ExternalCmdsTester.new
|
93
|
+
@obj.stub(:load_config!) { }
|
94
|
+
@obj.stub(:save_config!) { }
|
95
|
+
|
96
|
+
@obj.set_config :pdftk_path, __FILE__
|
97
|
+
@obj.set_config :have_pdftk, true
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'resets have_pdftk to false' do
|
101
|
+
@obj.find_external_cmds
|
102
|
+
@obj.get_config(:have_pdftk).should be(false)
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'unsets the pdftk path' do
|
106
|
+
@obj.find_external_cmds
|
107
|
+
@obj.get_config(:pdftk_path).should eq('')
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'prints out an error message' do
|
111
|
+
@obj.stub(:say_status) {}
|
112
|
+
@obj.should_receive(:say_status).with(:error, kind_of(String), kind_of(Symbol))
|
113
|
+
@obj.find_external_cmds
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe 'with configuration set, non-existent pdftk' do
|
118
|
+
before(:each) do
|
119
|
+
@obj = ExternalCmdsTester.new
|
120
|
+
@obj.stub(:load_config!) { }
|
121
|
+
@obj.stub(:save_config!) { }
|
122
|
+
|
123
|
+
@obj.set_config :pdftk_path, '/nope/wut'
|
124
|
+
@obj.set_config :have_pdftk, true
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'resets have_pdftk to false' do
|
128
|
+
@obj.find_external_cmds
|
129
|
+
@obj.get_config(:have_pdftk).should be(false)
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'unsets the pdftk path' do
|
133
|
+
@obj.find_external_cmds
|
134
|
+
@obj.get_config(:pdftk_path).should eq('')
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'prints out an error message' do
|
138
|
+
@obj.stub(:say_status) {}
|
139
|
+
@obj.should_receive(:say_status).with(:error, kind_of(String), kind_of(Symbol))
|
140
|
+
@obj.find_external_cmds
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
describe 'with configuration set, with pdftk' do
|
145
|
+
before(:each) do
|
146
|
+
@obj = ExternalCmdsTester.new
|
147
|
+
@obj.stub(:load_config!) { }
|
148
|
+
@obj.stub(:save_config!) { }
|
149
|
+
|
150
|
+
@obj.set_config :pdftk_path, File.expand_path(File.join(Dir.tmpdir, 'pdftk'))
|
151
|
+
@obj.set_config :have_pdftk, true
|
152
|
+
|
153
|
+
add_to_path('pdftk')
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'leaves have_pdftk true' do
|
157
|
+
@obj.find_external_cmds
|
158
|
+
@obj.get_config(:have_pdftk).should eq(true)
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'leaves the right pdftk path' do
|
162
|
+
@obj.find_external_cmds
|
163
|
+
|
164
|
+
path = File.expand_path(File.join(Dir.tmpdir, 'pdftk'))
|
165
|
+
@obj.get_config(:pdftk_path).should eq(path)
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'should not print any messages' do
|
169
|
+
@obj.should_not_receive(:say)
|
170
|
+
@obj.should_not_receive(:say_status)
|
171
|
+
@obj.find_external_cmds
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'stickyflag/patches/tempfile_encoding'
|
3
|
+
|
4
|
+
describe 'Tempfile' do
|
5
|
+
describe '.new_with_encoding' do
|
6
|
+
it 'successfully creates temporary files' do
|
7
|
+
f = Tempfile.new_with_encoding 'asdf'
|
8
|
+
f.should be
|
9
|
+
|
10
|
+
f.unlink
|
11
|
+
f.close
|
12
|
+
end
|
13
|
+
|
14
|
+
# JRuby <1.7.0 implements Ruby 1.9 but doesn't follow the spec for Tempfile
|
15
|
+
if RUBY_VERSION >= "1.9.0" && (RUBY_PLATFORM != 'java' || JRUBY_VERSION >= '1.7.0')
|
16
|
+
it 'sets the correct external encoding' do
|
17
|
+
f = Tempfile.new_with_encoding 'asdf'
|
18
|
+
f.external_encoding.should be
|
19
|
+
f.external_encoding.name.should eq('UTF-8')
|
20
|
+
|
21
|
+
f.unlink
|
22
|
+
f.close
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
require 'fileutils'
|
3
|
+
require 'stickyflag/patches/tmpnam'
|
4
|
+
|
5
|
+
describe 'File' do
|
6
|
+
describe '.tmpnam' do
|
7
|
+
it "creates file names that don't exist" do
|
8
|
+
File.exist?(File.tmpnam).should be_false
|
9
|
+
end
|
10
|
+
|
11
|
+
it "puts extensions on files (no dot)" do
|
12
|
+
path = File.tmpnam('txt')
|
13
|
+
path[-4..-1].should eq('.txt')
|
14
|
+
end
|
15
|
+
|
16
|
+
it "puts extensions on files (with dot)" do
|
17
|
+
path = File.tmpnam('txt')
|
18
|
+
path[-4..-1].should eq('.txt')
|
19
|
+
end
|
20
|
+
|
21
|
+
it "puts files in the temporary directory" do
|
22
|
+
File.tmpnam.should start_with(Dir.tmpdir)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "can create lots and lots in a row" do
|
26
|
+
files = []
|
27
|
+
(1..1000).each do |i|
|
28
|
+
files << File.tmpnam
|
29
|
+
FileUtils.touch(files.last)
|
30
|
+
end
|
31
|
+
|
32
|
+
files.each { |f| File.unlink(f) }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|