stickyflag 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. data/TODO.md +2 -1
  2. data/lib/stickyflag/version.rb +1 -1
  3. data/stickyflag.gemspec +5 -4
  4. metadata +8 -116
  5. data/.gitignore +0 -7
  6. data/.rspec +0 -4
  7. data/.simplecov +0 -9
  8. data/.travis.yml +0 -13
  9. data/features/clear.feature +0 -14
  10. data/features/clear_quietly.feature +0 -23
  11. data/features/configuration.feature +0 -14
  12. data/features/get.feature +0 -14
  13. data/features/get_quietly.feature +0 -23
  14. data/features/set.feature +0 -14
  15. data/features/set_quietly.feature +0 -22
  16. data/features/step_definitions/configuration_steps.rb +0 -31
  17. data/features/step_definitions/database_steps.rb +0 -41
  18. data/features/step_definitions/pending_steps.rb +0 -5
  19. data/features/step_definitions/tag_steps.rb +0 -62
  20. data/features/support/cukegem.rb +0 -82
  21. data/features/support/env.rb +0 -37
  22. data/features/tags.feature +0 -18
  23. data/features/unset.feature +0 -14
  24. data/features/unset_quietly.feature +0 -23
  25. data/spec/spec_helper.rb +0 -22
  26. data/spec/stickyflag/configuration_spec.rb +0 -132
  27. data/spec/stickyflag/database_spec.rb +0 -331
  28. data/spec/stickyflag/external_cmds_spec.rb +0 -175
  29. data/spec/stickyflag/patches/tempfile_encoding_spec.rb +0 -26
  30. data/spec/stickyflag/patches/tmpnam_spec.rb +0 -35
  31. data/spec/stickyflag/paths_spec.rb +0 -29
  32. data/spec/stickyflag/tag_factory_spec.rb +0 -126
  33. data/spec/stickyflag/tags/c_spec.rb +0 -14
  34. data/spec/stickyflag/tags/mkv_spec.rb +0 -54
  35. data/spec/stickyflag/tags/mmd_spec.rb +0 -40
  36. data/spec/stickyflag/tags/pdf_spec.rb +0 -39
  37. data/spec/stickyflag/tags/png_spec.rb +0 -6
  38. data/spec/stickyflag/tags/tex_spec.rb +0 -6
  39. data/spec/stickyflag_spec.rb +0 -482
  40. data/spec/support/examples.rb +0 -32
  41. data/spec/support/examples/c_all_comments.c +0 -3
  42. data/spec/support/examples/c_no_tags.c +0 -5
  43. data/spec/support/examples/c_with_tag.c +0 -6
  44. data/spec/support/examples/mkv_no_tags.mkv +0 -0
  45. data/spec/support/examples/mkv_with_tag.mkv +0 -0
  46. data/spec/support/examples/mmd_all_meta.mmd +0 -6
  47. data/spec/support/examples/mmd_crazy_keys.mmd +0 -8
  48. data/spec/support/examples/mmd_crazy_tags.mmd +0 -9
  49. data/spec/support/examples/mmd_no_tags.mmd +0 -1
  50. data/spec/support/examples/mmd_with_tag.mmd +0 -3
  51. data/spec/support/examples/pdf_no_tags.pdf +0 -0
  52. data/spec/support/examples/pdf_with_tag.pdf +0 -0
  53. data/spec/support/examples/png_no_tags.png +0 -0
  54. data/spec/support/examples/png_with_tag.png +0 -0
  55. data/spec/support/examples/tex_no_tags.tex +0 -10
  56. data/spec/support/examples/tex_with_tag.tex +0 -11
  57. data/spec/support/examples/untaggable.txt +0 -0
  58. data/spec/support/run_with_args.rb +0 -36
  59. data/spec/support/silence_stream.rb +0 -12
  60. data/spec/support/tag_handler_behavior.rb +0 -125
@@ -1,175 +0,0 @@
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)).at_least(:once)
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).with(/pdftk/)
85
- @obj.should_not_receive(:say_status).with(:warning, /pdftk/, kind_of(Symbol))
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, /pdftk/, 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, /pdftk/, 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).with(/pdftk/)
170
- @obj.should_not_receive(:say_status).with(:warning, /pdftk/, kind_of(Symbol))
171
- @obj.find_external_cmds
172
- end
173
- end
174
- end
175
- end
@@ -1,26 +0,0 @@
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
@@ -1,35 +0,0 @@
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
@@ -1,29 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- require 'stickyflag/paths'
3
-
4
- class PathsTester
5
- include StickyFlag::Paths
6
- end
7
-
8
- describe 'StickyFlag::Paths' do
9
- describe '.config_path' do
10
- it 'includes the config.yml file name' do
11
- PathsTester.new.config_path.should include('config.yml')
12
- end
13
-
14
- it "doesn't include any tildes" do
15
- PathsTester.new.config_path.should_not include('~')
16
- end
17
- end
18
-
19
- describe '.database_path' do
20
- it 'includes the db.sqlite file name' do
21
- PathsTester.new.database_path.should include('db.sqlite')
22
- end
23
-
24
- it "doesn't include any tildes" do
25
- PathsTester.new.database_path.should_not include('~')
26
- end
27
- end
28
- end
29
-
@@ -1,126 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- require 'thor'
3
- require 'stickyflag/patches/tempfile_encoding'
4
- require 'stickyflag/paths'
5
- require 'stickyflag/configuration'
6
- require 'stickyflag/tag_factory'
7
- require 'stickyflag/external_cmds'
8
- require 'stickyflag/database'
9
-
10
- class TagFactoryTester < Thor
11
- include StickyFlag::Paths
12
- include StickyFlag::Configuration
13
- include StickyFlag::TagFactory
14
- include StickyFlag::ExternalCmds
15
- include StickyFlag::Database
16
- end
17
-
18
- describe 'StickyFlag::TagFactory' do
19
- before(:each) do
20
- @obj = TagFactoryTester.new
21
-
22
- @obj.stub(:load_config!) { }
23
- @obj.stub(:save_config!) { }
24
-
25
- @obj.stub(:load_database) { }
26
- @obj.stub(:update_database_from_files) { }
27
- @obj.stub(:set_database_tag) { }
28
- @obj.stub(:unset_database_tag) { }
29
- @obj.stub(:clear_database_tags) { }
30
- @obj.stub(:files_for_tags) { [] }
31
-
32
- @obj.find_external_cmds
33
- end
34
-
35
- describe '.available_tagging_extensions' do
36
- it 'should be able to call through to a class method for every good extension' do
37
- @obj.available_tagging_extensions.each do |ext|
38
- # This is a bit of a hack -- call TagClass::respond_to?, which takes
39
- # one argument
40
- expect { @obj.call_tag_method("test#{ext}", :respond_to?) }.to_not raise_error
41
- end
42
- end
43
- end
44
-
45
- describe '.get_tags_for' do
46
- it 'should delegate to PDF' do
47
- path = example_path('pdf_no_tags.pdf')
48
-
49
- StickyFlag::Tags::PDF.should_receive(:get).with(path, kind_of(String))
50
- @obj.get_tags_for(path)
51
- end
52
-
53
- it 'should raise error for unknown extensions' do
54
- expect {
55
- @obj.get_tags_for('asdf.zzy')
56
- }.to raise_error(Thor::Error)
57
- end
58
- end
59
-
60
- describe '.set_tag_for' do
61
- it 'should delegate to PDF' do
62
- path = example_path('pdf_no_tags.pdf')
63
-
64
- StickyFlag::Tags::PDF.should_receive(:set).with(path, 'lol', kind_of(String))
65
- @obj.set_tag_for(path, 'lol')
66
- end
67
-
68
- it 'should not call through if the tag is already set' do
69
- path = example_path('pdf_with_tag.pdf')
70
-
71
- StickyFlag::Tags::PDF.should_not_receive(:set)
72
- @obj.set_tag_for(path, 'test')
73
- end
74
-
75
- it 'should raise error for unknown extensions' do
76
- @obj.stub(:get_tags_for) { [] }
77
- expect {
78
- @obj.set_tag_for('asdf.zzy', 'lol')
79
- }.to raise_error(Thor::Error)
80
- end
81
- end
82
-
83
- describe '.unset_tag_for' do
84
- it 'should delegate to PDF' do
85
- path = copy_example('pdf_with_tag.pdf')
86
-
87
- StickyFlag::Tags::PDF.should_receive(:unset).with(path, 'test', kind_of(String))
88
- @obj.unset_tag_for(path, 'test')
89
-
90
- File.delete(path)
91
- end
92
-
93
- it 'should not call through if the tag is not set' do
94
- path = example_path('pdf_no_tags.pdf')
95
-
96
- StickyFlag::Tags::PDF.should_not_receive(:unset)
97
- expect {
98
- @obj.unset_tag_for(path, 'test')
99
- }.to raise_error(Thor::Error)
100
- end
101
-
102
- it 'should raise error for unknown extensions' do
103
- @obj.stub(:get_tags_for) { [ 'lol' ] }
104
- expect {
105
- @obj.unset_tag_for('asdf.zzy', 'lol')
106
- }.to raise_error(Thor::Error)
107
- end
108
- end
109
-
110
- describe '.clear_tags_for' do
111
- it 'should delegate to PDF' do
112
- path = copy_example('pdf_with_tag.pdf')
113
-
114
- StickyFlag::Tags::PDF.should_receive(:clear).with(path, kind_of(String))
115
- @obj.clear_tags_for(path)
116
-
117
- File.delete(path)
118
- end
119
-
120
- it 'should raise error for unknown extensions' do
121
- expect {
122
- @obj.clear_tags_for('asdf.zzy')
123
- }.to raise_error(Thor::Error)
124
- end
125
- end
126
- end
@@ -1,14 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- require 'stickyflag/tags/c'
3
-
4
- describe StickyFlag::Tags::C do
5
- it_behaves_like 'a tag handler'
6
-
7
- it 'can open a file with all comments and no tags' do
8
- ret = nil
9
- expect {
10
- ret = StickyFlag::Tags::C.get(example_path('c_all_comments.c'))
11
- }.to_not raise_error
12
- ret.should be_empty
13
- end
14
- end
@@ -1,54 +0,0 @@
1
- # -*- encoding : utf-8 -*-
2
- require 'stickyflag/tags/mkv'
3
- require 'stickyflag/paths'
4
- require 'stickyflag/configuration'
5
- require 'stickyflag/external_cmds'
6
-
7
- class GetConfiguration
8
- include StickyFlag::Paths
9
- include StickyFlag::Configuration
10
- include StickyFlag::ExternalCmds
11
- end
12
-
13
- describe StickyFlag::Tags::MKV do
14
- before(:each) do
15
- config = GetConfiguration.new
16
- config.stub(:load_config!) { }
17
- config.stub(:save_config!) { }
18
-
19
- config.find_external_cmds
20
-
21
- @mkve = config.get_config(:mkvextract_path)
22
- @mkvp = config.get_config(:mkvpropedit_path)
23
- end
24
-
25
- it_behaves_like 'a tag handler' do
26
- let(:params) {
27
- [ @mkve, @mkvp ]
28
- }
29
- end
30
-
31
- context 'when we set our own tag' do
32
- it "doesn't wipe out other tags set on the file" do
33
- path = copy_example("mkv_with_tag.mkv")
34
- StickyFlag::Tags::MKV.set(path, 'test2', @mkve, @mkvp)
35
-
36
- # This is an internal method, but it's too useful not to use
37
- xml_doc = StickyFlag::Tags::MKV.get_tag_xml(path, @mkve, @mkvp)
38
-
39
- # This is one of the original tags on the file
40
- tag = xml_doc.at_xpath("/Tags/Tag[Targets[TargetTypeValue = '50']]/Simple[Name = 'TITLE']")
41
- tag.should_not be_nil
42
- tag.at_xpath("String").content.should eq('Big Buck Bunny - test 1')
43
- end
44
- end
45
-
46
- context 'with bad mkv utility paths' do
47
- it 'raises errors for everything' do
48
- expect { StickyFlag::Tags::MKV.get(example_path("mkv_with_tag.mkv"), '/wut/bad', '/wut/no') }.to raise_error(Thor::Error)
49
- expect { StickyFlag::Tags::MKV.clear(example_path("mkv_with_tag.mkv"), '/wut/bad', '/wut/no') }.to raise_error(Thor::Error)
50
- expect { StickyFlag::Tags::MKV.set(example_path("mkv_with_tag.mkv"), 'test2', '/wut/bad', '/wut/no') }.to raise_error(Thor::Error)
51
- expect { StickyFlag::Tags::MKV.unset(example_path("mkv_with_tag.mkv"), 'test', '/wut/bad', '/wut/no') }.to raise_error(Thor::Error)
52
- end
53
- end
54
- end