lookfile 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ce9191567c230128333e294860e28e5ac8a3bd84
4
- data.tar.gz: c0ed5b2d5f54bb581a0279f83d81272922be5e40
3
+ metadata.gz: 82e911dedd72a0e516d25ec0662f0a48530feeda
4
+ data.tar.gz: 2ba8ec5b58aebc55cc40eee67bb4dc3106aef40d
5
5
  SHA512:
6
- metadata.gz: 250c2bfb54cb3c54ef387de079e6e27c0cac068654751309b55810a047c52defac37b634bac54f4582a5cc49146fc12de26592632ce9ec21b779f2128691380c
7
- data.tar.gz: 28eb3c258ee06b8a4f61d93a31ce811f45add4bf4ca7d727ecb4ac1aed538adac21cfe4e829fe4343016035e1f4f014656b0880722e037ea4c9bde617852f966
6
+ metadata.gz: ce88c689716986ccaacd06eeed9cc5ebabf7daa0e87fd52a99e4718e655e901051c777a10882011461447f4f7373f3edc5326e0917ce86c19e3438f80de9dd4d
7
+ data.tar.gz: f5d51457cbfa87bdfedad291fba9c904dc71bf593c2a6f38773b4255338bf5b02bc515f018de7e4011d83a149e4c2b9311e7b4cb87679ac3f493591c0b6b789b
@@ -1,3 +1,3 @@
1
1
  module Lookfile
2
- VERSION = '0.1.4'.freeze
2
+ VERSION = '0.1.5'.freeze
3
3
  end
data/lookfile.gemspec CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.license = 'Expat'
24
24
 
25
25
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
- f.match(%r{^(test|spec|features)/})
26
+ f.match(%r{^(test|features)/})
27
27
  end
28
28
  spec.bindir = 'bin'
29
29
  spec.executables << 'lookfile'
@@ -0,0 +1,237 @@
1
+ require 'spec_helper'
2
+ require 'fileutils'
3
+ require 'commands/init'
4
+ require 'commands/add'
5
+ require 'commands/push'
6
+ require 'commands/status'
7
+ require 'commands/show'
8
+ require 'commands/restore'
9
+ require 'commands/set_repository'
10
+
11
+ describe Command do
12
+ before do
13
+ $stdin = STDIN
14
+ $stdout = STDOUT
15
+ stub_const('Lookfile::BASE_DIR', BASE_DIR)
16
+ Dir.mkdir(BASE_DIR)
17
+ Dir.mkdir(GIT_DIR)
18
+ `git -C '#{GIT_DIR}' init --bare`
19
+ FileUtils.touch(TEST_FILE)
20
+ end
21
+
22
+ after do
23
+ FileUtils.rm_rf(BASE_DIR)
24
+ FileUtils.rm_rf(GIT_DIR)
25
+ FileUtils.rm_rf(TEST_FILE)
26
+ end
27
+
28
+ describe '$ lookfile init' do
29
+ it 'init Lookfile' do
30
+ $stdout = StringIO.new
31
+ Init.run
32
+ $stdout.rewind
33
+
34
+ expect_message = "Initialize lookfile on: #{Lookfile.load_lookfile_dir}"
35
+ expect_message += "\n"
36
+ expect($stdout.gets).to eq(expect_message)
37
+ end
38
+
39
+ it 'dont init Lookfile if its already initialized' do
40
+ Init.run
41
+
42
+ $stdout = StringIO.new
43
+ Init.run
44
+ $stdout.rewind
45
+
46
+ expect_message = "lookfile was already initialized\n"
47
+ expect($stdout.gets).to eq(expect_message)
48
+ end
49
+ end
50
+
51
+ describe '$ lookfile add' do
52
+ it 'add new file into Lookfile' do
53
+ $stdout = StringIO.new
54
+ Add.run([TEST_FILE])
55
+ $stdout.rewind
56
+
57
+ expect($stdout.gets).to eq("Added files:\n")
58
+ expect($stdout.gets).to eq(" #{TEST_FILE}\n")
59
+ end
60
+ end
61
+
62
+ describe '$ lookfile status' do
63
+ it 'status of added file' do
64
+ repository_ssh_name = "file://#{GIT_DIR}"
65
+ Lookfile.initialize
66
+ Lookfile.set_repository(repository_ssh_name)
67
+ Lookfile.add_files(TEST_FILE)
68
+
69
+ $stdout = StringIO.new
70
+ Status.run
71
+ $stdout.rewind
72
+
73
+ expect($stdout.gets).to eq("Added files:\n")
74
+ expect($stdout.gets).to eq(" #{TEST_FILE[1..-1]}\n")
75
+ end
76
+
77
+ it 'status of modified file' do
78
+ repository_ssh_name = "file://#{GIT_DIR}"
79
+ Lookfile.initialize
80
+ Lookfile.set_repository(repository_ssh_name)
81
+ Lookfile.add_files(TEST_FILE)
82
+ Lookfile.push
83
+ open(TEST_FILE, 'a') { |file| file.puts('modified') }
84
+
85
+ $stdout = StringIO.new
86
+ Status.run
87
+ $stdout.rewind
88
+
89
+ expect($stdout.gets).to eq("Modified files:\n")
90
+ expect($stdout.gets).to eq(" #{TEST_FILE[1..-1]}\n")
91
+ end
92
+
93
+ it 'status of deleted file' do
94
+ repository_ssh_name = "file://#{GIT_DIR}"
95
+ Lookfile.initialize
96
+ Lookfile.set_repository(repository_ssh_name)
97
+ Lookfile.add_files(TEST_FILE)
98
+ Lookfile.push
99
+ lookfile_dir = Lookfile.load_lookfile_dir
100
+ FileUtils.rm_rf(lookfile_dir + TEST_FILE)
101
+
102
+ $stdout = StringIO.new
103
+ Status.run
104
+ $stdout.rewind
105
+
106
+ expect($stdout.gets).to eq("Deleted files:\n")
107
+ expect($stdout.gets).to eq(" #{TEST_FILE[1..-1]}\n")
108
+ end
109
+
110
+ it 'dont show status if not have files on Lookfile' do
111
+ repository_ssh_name = "file://#{GIT_DIR}"
112
+ Lookfile.initialize
113
+ Lookfile.set_repository(repository_ssh_name)
114
+
115
+ $stdout = StringIO.new
116
+ Status.run
117
+ $stdout.rewind
118
+
119
+ expect($stdout.gets).to eq("\n")
120
+ end
121
+ end
122
+
123
+ describe '$ lookfile push' do
124
+ it 'push a file' do
125
+ repository_ssh_name = "file://#{GIT_DIR}"
126
+ Lookfile.initialize
127
+ Lookfile.set_repository(repository_ssh_name)
128
+ Lookfile.add_files(TEST_FILE)
129
+
130
+ $stdout = StringIO.new
131
+ Push.run
132
+ $stdout.rewind
133
+
134
+ expect($stdout.gets).to eq("Added files:\n")
135
+ expect($stdout.gets).to eq(" #{TEST_FILE[1..-1]}\n")
136
+ end
137
+
138
+ it 'dont push if not have files to push' do
139
+ repository_ssh_name = "file://#{GIT_DIR}"
140
+ Lookfile.initialize
141
+ Lookfile.set_repository(repository_ssh_name)
142
+
143
+ $stdout = StringIO.new
144
+ Push.run
145
+ $stdout.rewind
146
+
147
+ expect($stdout.gets).to eq("Nothing to update\n")
148
+ end
149
+ end
150
+
151
+ describe '$ lookfile show' do
152
+ it 'show files on lookfile' do
153
+ repository_ssh_name = "file://#{GIT_DIR}"
154
+ Lookfile.initialize
155
+ Lookfile.set_repository(repository_ssh_name)
156
+ Lookfile.add_files(TEST_FILE)
157
+
158
+ $stdout = StringIO.new
159
+ Show.run
160
+ $stdout.rewind
161
+
162
+ expect($stdout.gets).to eq("Files on lookfile:\n")
163
+ expect($stdout.gets).to eq(" #{TEST_FILE}\n")
164
+ end
165
+
166
+ it 'dont show files on lookfile if not have files' do
167
+ repository_ssh_name = "file://#{GIT_DIR}"
168
+ Lookfile.initialize
169
+ Lookfile.set_repository(repository_ssh_name)
170
+
171
+ $stdout = StringIO.new
172
+ Show.run
173
+ $stdout.rewind
174
+
175
+ expect($stdout.gets).to eq("\n")
176
+ end
177
+ end
178
+
179
+ describe '$ lookfile restore' do
180
+ it 'restore a file from lookfile' do
181
+ begin
182
+ repository_ssh_name = "file://#{GIT_DIR}"
183
+ Lookfile.initialize
184
+ Lookfile.set_repository(repository_ssh_name)
185
+ Lookfile.add_files(TEST_FILE)
186
+
187
+ $stdin, write = IO.pipe
188
+ write.puts 'y'
189
+ $stdout = StringIO.new
190
+ Restore.run
191
+ $stdout.rewind
192
+
193
+ expect_message = "Restore file #{TEST_FILE} (Y/n): Restore Files:\n"
194
+ expect($stdout.gets).to eq(expect_message)
195
+ expect($stdout.gets).to eq(" #{TEST_FILE}\n")
196
+ ensure
197
+ write.close
198
+ end
199
+ end
200
+
201
+ it 'not restore a file from lookfile if not have files' do
202
+ repository_ssh_name = "file://#{GIT_DIR}"
203
+ Lookfile.initialize
204
+ Lookfile.set_repository(repository_ssh_name)
205
+
206
+ $stdout = StringIO.new
207
+ Restore.run
208
+ $stdout.rewind
209
+
210
+ expect($stdout.gets).to eq("Restore Files:\n")
211
+ end
212
+ end
213
+
214
+ describe '$ lookfile set_repository' do
215
+ it 'set repository to lookfile' do
216
+ repository_ssh_name = "file://#{GIT_DIR}"
217
+ Lookfile.initialize
218
+
219
+ $stdout = StringIO.new
220
+ SetRepository.run([repository_ssh_name])
221
+ $stdout.rewind
222
+
223
+ expect_message = "Setted repository to: #{repository_ssh_name}\n"
224
+ expect($stdout.gets).to eq(expect_message)
225
+ end
226
+
227
+ it 'dont set repository to lookfile if not have repository name' do
228
+ Lookfile.initialize
229
+
230
+ $stdout = StringIO.new
231
+ SetRepository.run([])
232
+ $stdout.rewind
233
+
234
+ expect($stdout.gets).to eq(" Usage:\n")
235
+ end
236
+ end
237
+ end
@@ -0,0 +1,149 @@
1
+ require 'spec_helper'
2
+ require 'fileutils'
3
+
4
+ describe Lookfile do
5
+ before do
6
+ stub_const('Lookfile::BASE_DIR', BASE_DIR)
7
+ Dir.mkdir(BASE_DIR)
8
+ Dir.mkdir(GIT_DIR)
9
+ `git -C '#{GIT_DIR}' init --bare`
10
+ FileUtils.touch(TEST_FILE)
11
+ end
12
+
13
+ after do
14
+ FileUtils.rm_rf(BASE_DIR)
15
+ FileUtils.rm_rf(GIT_DIR)
16
+ FileUtils.rm_rf(TEST_FILE)
17
+ end
18
+
19
+ it 'has a version number' do
20
+ expect(Lookfile::VERSION).not_to be nil
21
+ end
22
+
23
+ describe 'Initialize Lookfile directory' do
24
+ it 'get lookfile_dir on base dir' do
25
+ lookfile_dir = Lookfile.load_lookfile_dir
26
+ default_base_dir = File.expand_path(Lookfile::BASE_DIR)
27
+
28
+ expect(lookfile_dir).to include(default_base_dir)
29
+ expect(lookfile_dir).to include(Lookfile::LOOKFILE_DIR)
30
+ end
31
+
32
+ it 'initialize lookfile' do
33
+ lookfile_dir = Lookfile.initialize
34
+ git_status = `GIT_DIR=#{lookfile_dir}/.git git status`
35
+
36
+ expect(lookfile_dir).to eq "#{BASE_DIR}/#{Lookfile::LOOKFILE_DIR}"
37
+ expect(git_status).to include('On branch master')
38
+ end
39
+ end
40
+
41
+ describe 'Add files to lookfile folder' do
42
+ it 'can add an existing file' do
43
+ added_files, = Lookfile.add_files(TEST_FILE)
44
+
45
+ expect(added_files).to include(TEST_FILE)
46
+ end
47
+
48
+ it 'can not add an non existent file' do
49
+ non_existent_file_name = '~/.lookfile_non_existent_file'
50
+ non_existent_file_name = File.expand_path(non_existent_file_name)
51
+ _, error_files = Lookfile.add_files(non_existent_file_name)
52
+
53
+ expect(error_files).to include(non_existent_file_name)
54
+ end
55
+
56
+ it 'show files on lookfile' do
57
+ Lookfile.add_files(TEST_FILE)
58
+ message = Lookfile.show
59
+
60
+ expect(message).to include('Files on lookfile:')
61
+ expect(message).to include(TEST_FILE)
62
+ end
63
+ end
64
+
65
+ describe 'Version files on repository' do
66
+ it 'add a new file' do
67
+ repository_ssh_name = "file://#{GIT_DIR}"
68
+ Lookfile.initialize
69
+ Lookfile.set_repository(repository_ssh_name)
70
+ Lookfile.add_files(TEST_FILE)
71
+ message = Lookfile.push
72
+ git_head_message = `git -C '#{GIT_DIR}' show HEAD`
73
+ n_commits = `git -C '#{GIT_DIR}' log | grep 'commit' -c`
74
+
75
+ expect(n_commits).to eq("1\n")
76
+ expect(message).to include('Added files')
77
+ expect(message).to include(TEST_FILE[1..-1])
78
+ expect(git_head_message).to include('Added files')
79
+ expect(git_head_message).to include(TEST_FILE[1..-1])
80
+ end
81
+
82
+ it 'modify a file' do
83
+ repository_ssh_name = "file://#{GIT_DIR}"
84
+ Lookfile.initialize
85
+ Lookfile.set_repository(repository_ssh_name)
86
+ Lookfile.add_files(TEST_FILE)
87
+ Lookfile.push
88
+ open(TEST_FILE, 'a') { |file| file.puts('modified') }
89
+ message = Lookfile.push
90
+ git_head_message = `git -C '#{GIT_DIR}' show HEAD`
91
+ n_commits = `git -C '#{GIT_DIR}' log | grep 'commit' -c`
92
+
93
+ expect(n_commits).to eq("2\n")
94
+ expect(message).to include('Modified files')
95
+ expect(message).to include(TEST_FILE[1..-1])
96
+ expect(git_head_message).to include('Modified files')
97
+ expect(git_head_message).to include(TEST_FILE[1..-1])
98
+ end
99
+
100
+ it 'remove a file' do
101
+ repository_ssh_name = "file://#{GIT_DIR}"
102
+ Lookfile.initialize
103
+ Lookfile.set_repository(repository_ssh_name)
104
+ Lookfile.add_files(TEST_FILE)
105
+ Lookfile.push
106
+ lookfile_dir = Lookfile.load_lookfile_dir
107
+ FileUtils.rm_rf(lookfile_dir + TEST_FILE)
108
+ message = Lookfile.push
109
+ git_head_message = `git -C '#{GIT_DIR}' show HEAD`
110
+ n_commits = `git -C '#{GIT_DIR}' log | grep 'commit' -c`
111
+
112
+ expect(n_commits).to eq("2\n")
113
+ expect(message).to include('Deleted files')
114
+ expect(message).to include(TEST_FILE[1..-1])
115
+ expect(git_head_message).to include('Deleted files')
116
+ expect(git_head_message).to include(TEST_FILE[1..-1])
117
+ end
118
+
119
+ it 'do nothing if not have changes on file' do
120
+ repository_ssh_name = "file://#{GIT_DIR}"
121
+ Lookfile.initialize
122
+ Lookfile.set_repository(repository_ssh_name)
123
+ Lookfile.add_files(TEST_FILE)
124
+ Lookfile.push
125
+ message = Lookfile.push
126
+ n_commits = `git -C '#{GIT_DIR}' log | grep 'commit' -c`
127
+
128
+ expect(message).to include('Nothing to update')
129
+ expect(n_commits).to eq("1\n")
130
+ end
131
+
132
+ it 'do restore a file' do
133
+ repository_ssh_name = "file://#{GIT_DIR}"
134
+ Lookfile.initialize
135
+ Lookfile.set_repository(repository_ssh_name)
136
+ Lookfile.add_files(TEST_FILE)
137
+ Lookfile.push
138
+
139
+ original_file = File.open(TEST_FILE, &:read)
140
+ FileUtils.rm_rf(TEST_FILE)
141
+ files_path = Lookfile.list_files
142
+ message = Lookfile.restore(files_path)
143
+ restored_file = File.open(TEST_FILE, &:read)
144
+
145
+ expect(message).to include(TEST_FILE)
146
+ expect(original_file).to eq(restored_file)
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,6 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'lookfile'
3
+
4
+ BASE_DIR = File.expand_path('~/.test_lookfile')
5
+ GIT_DIR = File.expand_path('~/.test_lookfile_git')
6
+ TEST_FILE = File.expand_path('~/.test_file')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lookfile
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luciano Prestes Cavalcanti
@@ -90,6 +90,9 @@ files:
90
90
  - lib/lookfile/version.rb
91
91
  - lookfile.1
92
92
  - lookfile.gemspec
93
+ - spec/commands_spec.rb
94
+ - spec/lookfile_spec.rb
95
+ - spec/spec_helper.rb
93
96
  homepage: https://github.com/LucianoPC/lookfile
94
97
  licenses:
95
98
  - Expat