logaling-command 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,31 +17,33 @@
17
17
 
18
18
  require File.join(File.dirname(__FILE__), "..", "spec_helper")
19
19
 
20
- describe Logaling::Command do
21
- let(:base_options) { {"glossary"=>"spec", "source-language"=>"en", "target-language"=>"ja"} }
22
- let(:command) { Logaling::Command.new([], base_options) }
23
- let(:glossary_path) { Logaling::Glossary.build_path('spec', 'en', 'ja') }
24
- let(:target_project_path) { File.join(LOGALING_HOME, "projects", "spec") }
25
- let(:repository) { Logaling::Repository.new(LOGALING_HOME) }
20
+ describe Logaling::Command::Application do
21
+ let(:logaling_home) { @logaling_home }
22
+ let(:logaling_config) { File.join(File.dirname(__FILE__), "..", "tmp", ".logaling") }
23
+ let(:base_options) { {"glossary"=>"spec", "source-language"=>"en", "target-language"=>"ja", "logaling-config" => logaling_config} }
24
+ let(:command) { Logaling::Command::Application.new([], base_options) }
25
+ let(:glossary) { Logaling::Glossary.new('spec', 'en', 'ja', logaling_home) }
26
+ let(:glossary_path) { glossary.source_path }
27
+ let(:target_project_path) { File.join(logaling_home, "projects", "spec") }
28
+ let(:repository) { Logaling::Repository.new(logaling_home) }
26
29
 
27
30
  before do
28
- FileUtils.remove_entry_secure(Logaling::Command::LOGALING_CONFIG, true)
29
- FileUtils.remove_entry_secure(File.join(LOGALING_HOME, 'projects', 'spec'), true)
31
+ FileUtils.remove_entry_secure(File.join(logaling_home, 'projects', 'spec'), true)
30
32
  end
31
33
 
32
34
  describe '#new' do
33
35
  before do
34
- @project_counts = Dir[File.join(LOGALING_HOME, "projects", "*")].size
36
+ @n_projects = Dir[File.join(logaling_home, "projects", "*")].size
35
37
  end
36
38
 
37
39
  context 'when .logaling already exists' do
38
40
  before do
39
- FileUtils.mkdir_p(Logaling::Command::LOGALING_CONFIG)
41
+ command.new('spec', 'en', 'ja')
40
42
  @stdout = capture(:stdout) { command.new('spec', 'en', 'ja') }
41
43
  end
42
44
 
43
45
  it 'print message \"<.logaling path> already exists.\"' do
44
- @stdout.should == "#{Logaling::Command::LOGALING_CONFIG} already exists.\n"
46
+ @stdout.should include "#{logaling_config} already exists.\n"
45
47
  end
46
48
  end
47
49
 
@@ -52,12 +54,12 @@ describe Logaling::Command do
52
54
  end
53
55
 
54
56
  it 'should create .logaling' do
55
- File.exist?(Logaling::Command::LOGALING_CONFIG).should be_true
57
+ File.should be_exist(logaling_config)
56
58
  end
57
59
 
58
60
  it 'should register .logaling as project' do
59
- File.exist?(target_project_path).should be_true
60
- Dir[File.join(LOGALING_HOME, "projects", "*")].size.should == @project_counts + 1
61
+ File.should be_exist(target_project_path)
62
+ Dir[File.join(logaling_home, "projects", "*")].size.should == @n_projects + 1
61
63
  end
62
64
  end
63
65
 
@@ -68,12 +70,12 @@ describe Logaling::Command do
68
70
  end
69
71
 
70
72
  it 'should create .logaling' do
71
- File.exist?(Logaling::Command::LOGALING_CONFIG).should be_true
73
+ File.should be_exist(logaling_config)
72
74
  end
73
75
 
74
76
  it 'should not register .logaling as project' do
75
- File.exist?(target_project_path).should be_false
76
- Dir[File.join(LOGALING_HOME, "projects", "*")].size.should == @project_counts
77
+ File.should_not be_exist(target_project_path)
78
+ Dir[File.join(logaling_home, "projects", "*")].size.should == @n_projects
77
79
  end
78
80
  end
79
81
  end
@@ -82,17 +84,17 @@ describe Logaling::Command do
82
84
  describe '#register' do
83
85
  before do
84
86
  sleep(1)
85
- @project_counts = Dir[File.join(LOGALING_HOME, "projects", "*")].size
87
+ @n_projects = Dir[File.join(logaling_home, "projects", "*")].size
86
88
  end
87
89
 
88
90
  context "when can not find .logaling" do
89
91
  before(:all) do
90
- FileUtils.remove_entry_secure(Logaling::Command::LOGALING_CONFIG, true)
92
+ FileUtils.remove_entry_secure(logaling_config, true)
91
93
  @stdout = capture(:stdout) {command.register}
92
94
  end
93
95
 
94
96
  it 'register nothing' do
95
- Dir[File.join(LOGALING_HOME, "projects", "*")].size.should == @project_counts
97
+ Dir[File.join(logaling_home, "projects", "*")].size.should == @n_projects
96
98
  end
97
99
 
98
100
  it "print message \"Try 'loga new' first.\"" do
@@ -107,29 +109,25 @@ describe Logaling::Command do
107
109
  end
108
110
 
109
111
  it 'register .logaling as project' do
110
- File.exist?(target_project_path).should be_true
111
- Dir[File.join(LOGALING_HOME, "projects", "*")].size.should == @project_counts + 1
112
- end
113
-
114
- after do
115
- FileUtils.remove_entry_secure(Logaling::Command::LOGALING_CONFIG, true)
112
+ File.should be_exist(target_project_path)
113
+ Dir[File.join(logaling_home, "projects", "*")].size.should == @n_projects + 1
116
114
  end
117
115
  end
118
116
  end
119
117
 
120
118
  describe '#unregister' do
121
119
  before do
122
- @project_counts = Dir[File.join(LOGALING_HOME, "projects", "*")].size
120
+ @n_projects = Dir[File.join(logaling_home, "projects", "*")].size
123
121
  end
124
122
 
125
123
  context "when can not find .logaling" do
126
124
  before do
127
- FileUtils.remove_entry_secure(Logaling::Command::LOGALING_CONFIG, true)
125
+ #FileUtils.remove_entry_secure(logaling_config, true)
128
126
  end
129
127
 
130
128
  context "and call without option" do
131
129
  before do
132
- command.options = base_options.merge("glossary" => nil)
130
+ base_options["glossary"] = nil
133
131
  @stdout = capture(:stdout) {command.unregister}
134
132
  end
135
133
 
@@ -144,7 +142,7 @@ describe Logaling::Command do
144
142
  @stdout = capture(:stdout) {command.unregister}
145
143
  end
146
144
  it 'should unregister symlink' do
147
- Dir[File.join(LOGALING_HOME, "projects", "*")].size.should == @project_counts
145
+ Dir[File.join(logaling_home, "projects", "*")].size.should == @n_projects
148
146
  end
149
147
  end
150
148
  end
@@ -158,8 +156,8 @@ describe Logaling::Command do
158
156
  end
159
157
 
160
158
  it 'unregister .logaling' do
161
- File.exist?(target_project_path).should be_false
162
- Dir[File.join(LOGALING_HOME, "projects", "*")].size.should == @project_counts
159
+ File.should_not be_exist(target_project_path)
160
+ Dir[File.join(logaling_home, "projects", "*")].size.should == @n_projects
163
161
  end
164
162
  end
165
163
 
@@ -178,8 +176,8 @@ describe Logaling::Command do
178
176
  end
179
177
 
180
178
  describe '#config' do
181
- let(:project_config) { File.join(Logaling::Command::LOGALING_CONFIG, 'config') }
182
- let(:global_config) { File.join(LOGALING_HOME, 'config') }
179
+ let(:project_config) { File.join(logaling_config, 'config') }
180
+ let(:global_config) { File.join(logaling_home, 'config') }
183
181
 
184
182
  subject { File.read(project_config) }
185
183
 
@@ -214,7 +212,7 @@ describe Logaling::Command do
214
212
 
215
213
  subject { File.read(global_config) }
216
214
 
217
- it 'should create LOGALING_HOME/config and write target-language' do
215
+ it 'should create {logaling_home}/config and write target-language' do
218
216
  should include "--target-language ja"
219
217
  end
220
218
 
@@ -225,12 +223,9 @@ describe Logaling::Command do
225
223
  end
226
224
 
227
225
  describe '#add' do
228
- before do
229
- command.new('spec', 'en', 'ja')
230
- end
231
-
232
226
  context 'with arguments have only bilingual pair' do
233
227
  before do
228
+ command.new('spec', 'en', 'ja')
234
229
  command.add("spec", "テスト")
235
230
  end
236
231
 
@@ -247,6 +242,7 @@ describe Logaling::Command do
247
242
 
248
243
  context 'with arguments have bilingual pair and note' do
249
244
  before do
245
+ command.new('spec', 'en', 'ja')
250
246
  command.add("spec", "テスト", "備考")
251
247
  end
252
248
 
@@ -262,28 +258,25 @@ describe Logaling::Command do
262
258
  end
263
259
 
264
260
  context 'project config does not have TARGET-LANGUAGE' do
265
- let(:command2) { Logaling::Command.new([], {}) }
266
- let(:global_config) { File.join(LOGALING_HOME, 'config') }
261
+ let(:global_config) { File.join(logaling_home, 'config') }
262
+ let(:base_options) { {"glossary"=>"spec", "source-language"=>"en", "output" => "terminal", "logaling-config" => logaling_config} }
267
263
  before do
268
- FileUtils.remove_entry_secure(Logaling::Command::LOGALING_CONFIG, true)
269
- command2.new('spec2', 'en')
264
+ # create global config file
270
265
  FileUtils.touch(global_config)
271
- File.open(global_config, "w") do |f|
272
- f.puts "--target-language fr"
273
- end
266
+ File.open(global_config, "w"){|f| f.puts "--target-language fr"}
267
+ command.new('spec', 'en')
274
268
  end
275
269
 
276
270
  context 'but global config have it' do
277
271
  before do
278
- command2.add('config test', '設定ファイルのテスト')
279
- @stdout = capture(:stdout) {command2.lookup("config")}
272
+ command.add('test-logaling', '設定ファイルのテスト')
273
+ command.options = base_options.merge("no-pager" => true)
274
+ @stdout = capture(:stdout) {command.lookup("test-logaling")}
280
275
  end
281
276
 
282
277
  it "should use global config's TARGET-LANGUAGE" do
283
- @stdout.should include "config"
284
- @stdout.should include "test"
278
+ @stdout.should include "test-logaling"
285
279
  @stdout.should include "設定ファイルのテスト"
286
- @stdout.should include "(spec2)"
287
280
  end
288
281
  end
289
282
 
@@ -295,7 +288,6 @@ describe Logaling::Command do
295
288
 
296
289
  describe "#update" do
297
290
  before do
298
- FileUtils.remove_entry_secure(File.join(LOGALING_HOME, "db", "index_at"), true)
299
291
  command.new('spec', 'en', 'ja')
300
292
  command.add("spec", "テスト", "備考")
301
293
  end
@@ -335,6 +327,7 @@ describe Logaling::Command do
335
327
 
336
328
  describe '#lookup' do
337
329
  before do
330
+ command.options = base_options.merge("output" => "terminal", "no-pager" => true)
338
331
  command.new('spec', 'en', 'ja')
339
332
  command.add("spec", "スペック", "備考")
340
333
  end
@@ -355,33 +348,34 @@ describe Logaling::Command do
355
348
  describe "#delete" do
356
349
  before do
357
350
  command.new('spec', 'en', 'ja')
358
- command.add('spec', 'スペック', '備考')
359
- command.add('user', 'ユーザ', '備考')
351
+ command.add('spec', 'スペックろがりん', '備考')
360
352
  command.add('test', 'てすと1', '備考')
361
353
  command.add('test', 'てすと2', '備考')
362
354
  end
363
355
 
364
356
  context 'with arguments exist term' do
365
357
  before do
366
- command.delete('spec', 'スペック')
358
+ command.delete('spec', 'スペックろがりん')
359
+ command.options = base_options.merge("no-pager" => true)
367
360
  @stdout = capture(:stdout) {command.lookup("spec")}
368
361
  end
369
362
 
370
363
  it 'should delete the term' do
371
- @stdout.should_not include "spec : スペック # 備考"
364
+ @stdout.should_not include "スペックろがりん"
372
365
  end
373
366
  end
374
367
 
375
368
  context 'without target_term' do
376
369
  context 'only 1 bilingual pair exist' do
377
- before do
378
- command.delete('user')
379
- @stdout = capture(:stdout) {command.lookup("user")}
380
- end
370
+ before do
371
+ command.delete('spec')
372
+ command.options = base_options.merge("no-pager" => true)
373
+ @stdout = capture(:stdout) {command.lookup("spec")}
374
+ end
381
375
 
382
- it 'should delete the term' do
383
- @stdout.should_not include "user : ユーザ # 備考"
384
- end
376
+ it 'should delete the term' do
377
+ @stdout.should_not include "スペックろがりん"
378
+ end
385
379
  end
386
380
 
387
381
  context 'some bilingual pair exist' do
@@ -391,25 +385,28 @@ describe Logaling::Command do
391
385
  end
392
386
 
393
387
  it "should print usage" do
394
- @stdout.should == "There are duplicate terms in glossary.\n" +
395
- "If you really want to delete, please put `loga delete [SOURCE_TERM] --force`\n" +
396
- " or `loga delete [SOURCE_TERM] [TARGET_TERM]`\n"
388
+ @stdout.should include "There are duplicate terms in glossary."
389
+ @stdout.should include "loga delete [SOURCE_TERM] --force"
390
+ @stdout.should include "loga delete [SOURCE_TERM] [TARGET_TERM]"
397
391
  end
398
392
  end
399
393
 
400
394
  context "and called with '--force=true'" do
401
395
  before do
396
+ FileUtils.remove_entry_secure(logaling_config, true)
397
+ FileUtils.remove_entry_secure(File.join(logaling_home, 'projects', 'spec'), true)
402
398
  command.options = base_options.merge("force" => true)
403
399
  command.new('spec', 'en', 'ja')
404
400
  command.add('term', '用語1', '備考')
405
401
  command.add('term', '用語2', '備考')
406
402
  command.delete("term")
403
+ command.options = base_options.merge("no-pager" => true)
407
404
  @stdout = capture(:stdout) {command.lookup("term")}
408
405
  end
409
406
 
410
407
  it 'should delete bilingual pairs' do
411
- @stdout.should_not include "term : 用語1 # 備考"
412
- @stdout.should_not include "term : 用語2 # 備考"
408
+ @stdout.should_not include "用語1"
409
+ @stdout.should_not include "用語2"
413
410
  end
414
411
  end
415
412
  end
@@ -420,37 +417,22 @@ describe Logaling::Command do
420
417
  let(:csv_path) { File.join(File.dirname(glossary_path), "spec.ja.en.csv") }
421
418
  before do
422
419
  command.new('spec', 'en', 'ja')
423
- command.add("spec", "スペック", "備考")
424
420
  command.add("spec-test", "スペックてすと", "備考")
425
- command.add("spec-test-test", "スペックてすとてすと", "備考")
426
421
 
427
422
  FileUtils.mkdir_p(File.dirname(glossary_path))
428
423
  FileUtils.touch(csv_path)
429
- File.open(csv_path, "w"){|f| f.puts "test_logaling,テスト"}
424
+ File.open(csv_path, "w"){|f| f.puts "test_logaling,テストろがりん"}
430
425
  end
431
426
 
432
427
  context 'when .logaling exists' do
433
428
  before do
429
+ command.options = base_options.merge("no-pager" => true)
434
430
  @stdout = capture(:stdout) {command.show}
435
431
  end
436
432
 
437
433
  it 'should show translation list' do
438
- @stdout.should include "spec"
439
- @stdout.should include "spec-test"
440
- @stdout.should include "spec-test-test"
441
- @stdout.should_not include "test_logaling"
442
- end
443
- end
444
-
445
- context 'with arguments glossary' do
446
- before do
447
- command.options = base_options.merge("glossary" => "spec", "source-language" => "ja", "target-language" => "en")
448
- @stdout = capture(:stdout) {command.show}
449
- end
450
-
451
- it 'should show translation list' do
452
- @stdout.should include "test_logaling"
453
- @stdout.should_not include "spec-test-test"
434
+ @stdout.should include "スペックてすと"
435
+ @stdout.should_not include "テストろがりん"
454
436
  end
455
437
  end
456
438
 
@@ -460,9 +442,14 @@ describe Logaling::Command do
460
442
  end
461
443
 
462
444
  describe '#list' do
445
+ before do
446
+ command.new('spec', 'en', 'ja')
447
+ command.add('spec logaling', 'すぺっくろがりん')
448
+ end
449
+
463
450
  context 'when some glossaries are registered' do
464
451
  before do
465
- command.new('spec', 'en', 'ja')
452
+ command.options = base_options.merge("no-pager" => true)
466
453
  @stdout = capture(:stdout) {command.list}
467
454
  end
468
455
 
@@ -473,8 +460,8 @@ describe Logaling::Command do
473
460
 
474
461
  context 'when a glossary is unregistered' do
475
462
  before do
476
- command.new('spec', 'en', 'ja')
477
463
  repository.unregister('spec')
464
+ command.options = base_options.merge("no-pager" => true)
478
465
  @stdout = capture(:stdout) {command.list}
479
466
  end
480
467
 
@@ -485,7 +472,7 @@ describe Logaling::Command do
485
472
  end
486
473
 
487
474
  after do
488
- FileUtils.remove_entry_secure(Logaling::Command::LOGALING_CONFIG, true)
489
- FileUtils.remove_entry_secure(File.join(LOGALING_HOME, 'projects', 'spec'), true)
475
+ FileUtils.remove_entry_secure(logaling_config, true)
476
+ FileUtils.remove_entry_secure(File.join(logaling_home, 'projects', 'spec'), true)
490
477
  end
491
478
  end
@@ -21,12 +21,13 @@ require "fileutils"
21
21
  module Logaling
22
22
  describe Glossary do
23
23
  let(:project) { "spec" }
24
- let(:glossary) { Glossary.new(project, 'en', 'ja') }
25
- let(:glossary_path) { Glossary.build_path(project, 'en', 'ja') }
26
- let(:repository) { Logaling::Repository.new(LOGALING_HOME) }
24
+ let(:logaling_home) { @logaling_home }
25
+ let(:glossary) { Glossary.new(project, 'en', 'ja', logaling_home) }
26
+ let(:glossary_path) { glossary.source_path }
27
+ let(:repository) { Logaling::Repository.new(logaling_home) }
27
28
 
28
29
  before do
29
- FileUtils.remove_entry_secure(File.join(LOGALING_HOME, 'projects', 'spec'), true)
30
+ FileUtils.remove_entry_secure(File.join(logaling_home, 'projects', 'spec'), true)
30
31
  FileUtils.mkdir_p(File.dirname(glossary_path))
31
32
  end
32
33
 
@@ -100,7 +101,7 @@ module Logaling
100
101
  glossary.add("delete_logaling", "てすと2", "備考")
101
102
  glossary.delete("delete_logaling", "てすと1")
102
103
  repository.index
103
- @result = repository.lookup("delete_logaling", "en", "ja", project)
104
+ @result = repository.lookup("delete_logaling", glossary)
104
105
  end
105
106
 
106
107
  it 'should delete the bilingual pair' do
@@ -137,7 +138,7 @@ module Logaling
137
138
  glossary.add("user_logaling", "ユーザ", "備考")
138
139
  glossary.delete_all("user_logaling")
139
140
  repository.index
140
- @result = repository.lookup("user_logaling", "en", "ja", project)
141
+ @result = repository.lookup("user_logaling", glossary)
141
142
  end
142
143
 
143
144
  it 'should delete the term' do
@@ -152,8 +153,7 @@ module Logaling
152
153
  glossary.add("delete_logaling", "てすと1", "備考")
153
154
  glossary.add("delete_logaling", "てすと2", "備考")
154
155
  glossary.delete_all("delete_logaling", true)
155
- repository.index
156
- @result = repository.lookup("delete_logaling", "en", "ja", project)
156
+ @result = Logaling::Glossary.load_glossary_yml(glossary_path)
157
157
  end
158
158
 
159
159
  it {
@@ -161,15 +161,17 @@ module Logaling
161
161
  }
162
162
 
163
163
  it "should delete terms when force option is true" do
164
- @result.any?{|term| term[:source_term] == "delete_logaling" && term[:target_term] == "てすと1"}.should be_false
165
- @result.any?{|term| term[:source_term] == "delete_logaling" && term[:target_term] == "てすと2"}.should be_false
164
+ @result.any?{|term| term == {"source_term"=>"delete_logaling", "target_term"=>"てすと1", "note"=>"備考"}}.should be_false
165
+ @result.any?{|term| term == {"source_term"=>"delete_logaling", "target_term"=>"てすと2", "note"=>"備考"}}.should be_false
166
+ @result.any?{|term| term == {"source_term"=>"user_logaling", "target_term"=>"ユーザ1", "note"=>"備考"}}.should be_true
167
+ @result.any?{|term| term == {"source_term"=>"user_logaling", "target_term"=>"ユーザ2", "note"=>"備考"}}.should be_true
166
168
  end
167
169
  end
168
170
  end
169
171
  end
170
172
 
171
173
  after do
172
- FileUtils.remove_entry_secure(File.join(LOGALING_HOME, 'projects', 'spec'), true)
174
+ FileUtils.remove_entry_secure(File.join(logaling_home, 'projects', 'spec'), true)
173
175
  end
174
176
  end
175
177
  end