monster_remote 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +5 -0
- data/LICENSE +0 -1
- data/README.md +141 -0
- data/Rakefile +12 -0
- data/bin/monster_remote +16 -0
- data/lib/monster/remote/cli.rb +104 -0
- data/lib/monster/remote/configuration.rb +53 -0
- data/lib/monster/remote/filters/filter.rb +24 -0
- data/lib/monster/remote/{content_name_based_filter.rb → filters/name_based_filter.rb} +9 -12
- data/lib/monster/remote/sync.rb +62 -30
- data/lib/monster/remote/wrappers/net_ftp.rb +107 -51
- data/lib/monster/remote.rb +14 -2
- data/lib/monster_remote.rb +8 -0
- data/monster_remote.gemspec +29 -0
- data/spec/monster/remote/cli_spec.rb +237 -0
- data/spec/monster/remote/configuration_spec.rb +124 -0
- data/spec/monster/remote/filters/filter_spec.rb +16 -0
- data/spec/monster/remote/filters/name_based_filter_spec.rb +57 -0
- data/spec/monster/remote/sync_spec.rb +108 -0
- data/spec/monster/remote/wrappers/net_ftp_spec.rb +220 -0
- data/spec/spec_helper.rb +55 -0
- metadata +38 -16
- data/lib/monster/remote/version.rb +0 -5
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'monster/remote/wrappers/net_ftp'
|
2
|
+
|
3
|
+
module Monster
|
4
|
+
module Remote
|
5
|
+
|
6
|
+
describe Sync do
|
7
|
+
|
8
|
+
let(:verbose) { double("some object with #puts").as_null_object }
|
9
|
+
|
10
|
+
def wrapper
|
11
|
+
w = double("wrapper contract").as_null_object
|
12
|
+
w.stub(:new).and_return(w)
|
13
|
+
w
|
14
|
+
end
|
15
|
+
|
16
|
+
def sync(wrapper)
|
17
|
+
Sync.new(wrapper, local_dir, remote_dir)
|
18
|
+
end
|
19
|
+
|
20
|
+
before do
|
21
|
+
FileUtils.mkdir_p(local_dir)
|
22
|
+
create_dir_structure
|
23
|
+
@wrapper = wrapper
|
24
|
+
@sync = sync(@wrapper)
|
25
|
+
end
|
26
|
+
|
27
|
+
context "#start" do
|
28
|
+
|
29
|
+
it "raise error if the local dir config is missing" do
|
30
|
+
missing_local_dir = Monster::Remote::MissingLocalDirError
|
31
|
+
sync = Sync.new(wrapper)
|
32
|
+
lambda { sync.start }.should raise_error(missing_local_dir)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "raise error if the remote dir config is missing" do
|
36
|
+
missing_remote_dir = Monster::Remote::MissingRemoteDirError
|
37
|
+
sync = Sync.new(wrapper, local_dir)
|
38
|
+
lambda { sync.start }.should raise_error(missing_remote_dir)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "raise error if asked to start without protocol wrapper" do
|
42
|
+
missing_wrapper = Monster::Remote::MissingProtocolWrapperError
|
43
|
+
lambda { Sync.new(nil).start }.should raise_error(missing_wrapper)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "call wrapper's #open when #start" do
|
47
|
+
@wrapper.should_receive(:open)
|
48
|
+
@sync.start
|
49
|
+
end
|
50
|
+
|
51
|
+
it "raise NoConnectionError when can't #open connection" do
|
52
|
+
@wrapper.should_receive(:open).and_raise(StandardError)
|
53
|
+
lambda{ @sync.start }.should raise_error
|
54
|
+
end
|
55
|
+
|
56
|
+
context "calling wrapper's #open" do
|
57
|
+
|
58
|
+
before do
|
59
|
+
@wrapper.stub(:open) { |&bloco| bloco && bloco.call(@wrapper) }
|
60
|
+
end
|
61
|
+
end# #open
|
62
|
+
end# #start
|
63
|
+
|
64
|
+
describe "turns verbose if a object which responds_to? :puts is passed" do
|
65
|
+
|
66
|
+
before do
|
67
|
+
@sync.verbose = verbose
|
68
|
+
end
|
69
|
+
|
70
|
+
it "calls #puts on the output object" do
|
71
|
+
verbose.should_receive(:puts).with("syncing from: #{local_dir} to: #{remote_dir}")
|
72
|
+
@sync.start
|
73
|
+
end
|
74
|
+
|
75
|
+
end # verbose
|
76
|
+
|
77
|
+
describe "with NetFTP wrapper" do
|
78
|
+
|
79
|
+
before { @ftp_dir = File.join(ftp_root, remote_dir) }
|
80
|
+
|
81
|
+
before(:each) do
|
82
|
+
sync = Sync.new(Wrappers::NetFTP, local_dir, remote_dir)
|
83
|
+
sync.start(ftp_user, ftp_password)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "replicate a local dir structure to remote" do
|
87
|
+
dir_structure.each do |dir, content|
|
88
|
+
File.directory?(File.join(@ftp_dir, dir)).should be_true
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
it "create copies all local files on the dir structure" do
|
93
|
+
dir_structure.each do |dir, content|
|
94
|
+
content.each do |f|
|
95
|
+
file = File.join(File.join(@ftp_dir, dir), f)
|
96
|
+
File.exists?(file).should be_true
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
after do
|
103
|
+
FileUtils.rm_rf(spec_tmp)
|
104
|
+
end
|
105
|
+
|
106
|
+
end# Sync
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,220 @@
|
|
1
|
+
module Monster
|
2
|
+
module Remote
|
3
|
+
module Wrappers
|
4
|
+
|
5
|
+
describe NetFTP, "copy some local directory, to the remote host" do
|
6
|
+
|
7
|
+
let(:host) { "host" }
|
8
|
+
let(:user) { "user" }
|
9
|
+
let(:password) { "pass" }
|
10
|
+
let(:port) { "port" }
|
11
|
+
|
12
|
+
let(:con) { double("Net::FTP::con mock").as_null_object }
|
13
|
+
|
14
|
+
let(:driver) {
|
15
|
+
d = double("Net::FTP mock").as_null_object
|
16
|
+
d.stub(:new).and_return(con)
|
17
|
+
d
|
18
|
+
}
|
19
|
+
|
20
|
+
let(:wrapper) { NetFTP.new(driver) }
|
21
|
+
|
22
|
+
before do
|
23
|
+
FileUtils.mkdir_p(local_dir)
|
24
|
+
create_dir_structure
|
25
|
+
end
|
26
|
+
|
27
|
+
it "create a Net::FTP object" do
|
28
|
+
driver.should_receive(:new).once
|
29
|
+
wrapper.open(host, user, password, port)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "connect to the right host and port" do
|
33
|
+
con.should_receive(:connect).with(host, port).once
|
34
|
+
wrapper.open(host, user, password, port)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "authenticate on server" do
|
38
|
+
con.should_receive(:login).with(user, password).once
|
39
|
+
wrapper.open(host, user, password, port)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "close connection" do
|
43
|
+
con.should_receive(:close).once
|
44
|
+
wrapper.open(host, user, password, port)
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "#open" do
|
48
|
+
|
49
|
+
context "yields a given block" do
|
50
|
+
|
51
|
+
it "yields a block" do
|
52
|
+
opalhes = 0
|
53
|
+
wrapper.open(host, user, password, port) { opalhes = 1 }
|
54
|
+
opalhes.should == 1
|
55
|
+
end
|
56
|
+
|
57
|
+
it "the first block arg responds_to? :create_dir" do
|
58
|
+
handler = nil
|
59
|
+
wrapper.open(host, user, password, port) {|h| handler = h }
|
60
|
+
handler.should respond_to(:create_dir)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "the first block arg responds_to? :copy_file" do
|
64
|
+
handler = nil
|
65
|
+
wrapper.open(host, user, password, port) {|h| handler = h }
|
66
|
+
handler.should respond_to(:copy_file)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "yields a given block passing the con as second argument" do
|
70
|
+
internal_con = nil
|
71
|
+
wrapper.open(host, user, password, port) {|first, con| internal_con = con }
|
72
|
+
internal_con.should be_equal(con)
|
73
|
+
end
|
74
|
+
|
75
|
+
end# yielding the block
|
76
|
+
|
77
|
+
context "uses a ftp connection" do
|
78
|
+
def ftp_cleanup
|
79
|
+
ftp = Net::FTP.new
|
80
|
+
ftp.connect("localhost")
|
81
|
+
ftp.login("tests", "t3st3")
|
82
|
+
list = ftp.list
|
83
|
+
|
84
|
+
dir_exists = list.select{ |item| item =~ /.* opalele$/ }.size > 0
|
85
|
+
if dir_exists
|
86
|
+
NetFTP.new.open("localhost", "tests", "t3st3", 21) do |remote|
|
87
|
+
remote.remove_dir("opalele")
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
file_exists = list.select{ |item| item =~ /.* zufa$/ }.size > 0
|
92
|
+
if file_exists
|
93
|
+
ftp.delete("zufa")
|
94
|
+
end
|
95
|
+
|
96
|
+
ftp.close
|
97
|
+
end
|
98
|
+
|
99
|
+
before(:each) do
|
100
|
+
ftp_cleanup
|
101
|
+
end
|
102
|
+
|
103
|
+
context "handling directories" do
|
104
|
+
|
105
|
+
it "creates a remote dir" do
|
106
|
+
NetFTP.new.open("localhost", "tests", "t3st3", 21) do |remote|
|
107
|
+
remote.create_dir("opalele")
|
108
|
+
end
|
109
|
+
File.directory?(File.join(ftp_root, "opalele")).should be_true
|
110
|
+
end
|
111
|
+
|
112
|
+
it "creates a dir recursivelly" do
|
113
|
+
NetFTP.new.open("localhost", "tests", "t3st3", 21) do |remote|
|
114
|
+
remote.create_dir("zaz/zumzum/goal/")
|
115
|
+
end
|
116
|
+
File.directory?(File.join(ftp_root, "zaz/zumzum/goal")).should be_true
|
117
|
+
end
|
118
|
+
|
119
|
+
it "copies a file recursivelly" do
|
120
|
+
file = File.join(local_dir, "amulek")
|
121
|
+
File.open(file, "w") { |f| f.write("go!go!") }
|
122
|
+
NetFTP.new.open("localhost", "tests", "t3st3", 21) do |remote|
|
123
|
+
remote.create_dir("opalele")
|
124
|
+
remote.copy_file(file, "opalele/amulek")
|
125
|
+
File.exists?(File.join(ftp_root, "opalele/amulek")).should be_true
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
it "removes a dir" do
|
130
|
+
NetFTP.new.open("localhost", "tests", "t3st3", 21) do |remote|
|
131
|
+
remote.create_dir("opalele")
|
132
|
+
remote.remove_dir("opalele")
|
133
|
+
end
|
134
|
+
File.directory?(File.join(ftp_root, "opalele")).should be_false
|
135
|
+
end
|
136
|
+
|
137
|
+
it "removes a dir recursively (a non empty dir)" do
|
138
|
+
NetFTP.new.open("localhost", "tests", "t3st3", 21) do |remote|
|
139
|
+
remote.create_dir("zaz/zumzum/goal")
|
140
|
+
remote.remove_dir("zaz/zumzum/goal")
|
141
|
+
end
|
142
|
+
File.directory?(File.join(ftp_root, "zaz/zumzum/goal")).should be_false
|
143
|
+
File.directory?(File.join(ftp_root, "zaz/zumzum")).should be_false
|
144
|
+
File.directory?(File.join(ftp_root, "zaz")).should be_false
|
145
|
+
end
|
146
|
+
|
147
|
+
it "overrides an existent dir" do
|
148
|
+
NetFTP.new.open("localhost", "tests", "t3st3", 21) do |remote|
|
149
|
+
lambda {
|
150
|
+
remote.create_dir("opalele")
|
151
|
+
remote.create_dir("opalele")
|
152
|
+
}.should_not raise_error
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
after do
|
157
|
+
ftp_cleanup
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
161
|
+
|
162
|
+
context "copying file" do
|
163
|
+
def file_content
|
164
|
+
"ula ula ula baboola"
|
165
|
+
end
|
166
|
+
|
167
|
+
def create_tmp_file
|
168
|
+
file = File.join(local_dir, "omg_filet.txt")
|
169
|
+
File.open(file, "w") { |f| f.write file_content }
|
170
|
+
file
|
171
|
+
end
|
172
|
+
|
173
|
+
before do
|
174
|
+
NetFTP.new.open("localhost", "tests", "t3st3", 21) do |remote|
|
175
|
+
remote.copy_file(create_tmp_file, "zufa")
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
it "copies the file" do
|
180
|
+
File.exists?(File.join(ftp_root, "zufa")).should be_true
|
181
|
+
end
|
182
|
+
|
183
|
+
it "copy with right content" do
|
184
|
+
IO.read(File.join(ftp_root, "zufa")).should == file_content
|
185
|
+
end
|
186
|
+
|
187
|
+
it "removes a file" do
|
188
|
+
NetFTP.new.open("localhost", "tests", "t3st3", 21) do |remote|
|
189
|
+
remote.copy_file(create_tmp_file, "zufa")
|
190
|
+
remote.remove_file("zufa")
|
191
|
+
end
|
192
|
+
File.exists?(File.join(ftp_root, "zufa")).should be_false
|
193
|
+
end
|
194
|
+
|
195
|
+
it "overrides existent file" do
|
196
|
+
NetFTP.new.open("localhost", "tests", "t3st3", 21) do |remote|
|
197
|
+
lambda {
|
198
|
+
remote.copy_file(create_tmp_file, "zufa")
|
199
|
+
remote.copy_file(create_tmp_file, "zufa")
|
200
|
+
}.should_not raise_error
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
end# copying file
|
205
|
+
|
206
|
+
after do
|
207
|
+
ftp_cleanup
|
208
|
+
end
|
209
|
+
|
210
|
+
end# ftp connection
|
211
|
+
end# #open
|
212
|
+
|
213
|
+
after do
|
214
|
+
FileUtils.rm_rf(spec_tmp)
|
215
|
+
end
|
216
|
+
|
217
|
+
end# NetFTP
|
218
|
+
end# Wrappers
|
219
|
+
end# Remote
|
220
|
+
end# Monster
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
|
3
|
+
$: << File.join(File.expand_path('../../', __FILE__), 'lib')
|
4
|
+
require 'monster_remote'
|
5
|
+
require 'fakefs/safe'
|
6
|
+
|
7
|
+
def spec_dir
|
8
|
+
File.expand_path("../", __FILE__)
|
9
|
+
end
|
10
|
+
|
11
|
+
def spec_tmp
|
12
|
+
File.join(spec_dir, "_tmp")
|
13
|
+
end
|
14
|
+
|
15
|
+
def local_dir
|
16
|
+
File.join(spec_tmp, "_ftp_")
|
17
|
+
end
|
18
|
+
|
19
|
+
def remote_dir
|
20
|
+
File.join("tmp", "_ftp_")
|
21
|
+
end
|
22
|
+
|
23
|
+
def ftp_root
|
24
|
+
"/Users/test"
|
25
|
+
end
|
26
|
+
|
27
|
+
def ftp_user
|
28
|
+
"tests"
|
29
|
+
end
|
30
|
+
|
31
|
+
def ftp_password
|
32
|
+
"t3st3"
|
33
|
+
end
|
34
|
+
|
35
|
+
def dir_structure
|
36
|
+
{
|
37
|
+
"site" => ["xpto.txt"],
|
38
|
+
"site/images" => ["img1", "img2", "img3"],
|
39
|
+
"site/borba" => ["file1", "file2"],
|
40
|
+
"site/borba/subdir" => ["entaro", "adum", "toredas"],
|
41
|
+
"site/borba/subdir/test" => ["go1", "go2", "go3"]
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
def create_dir_structure
|
46
|
+
dir_structure.each do |dir, files|
|
47
|
+
dir = File.join(local_dir, dir)
|
48
|
+
FileUtils.mkdir_p(dir)
|
49
|
+
files.each do |file|
|
50
|
+
File.open(File.join(dir, file), "w") do |f|
|
51
|
+
f.write(file)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: monster_remote
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-02-10 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70145766743680 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70145766743680
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: fakefs
|
27
|
-
requirement: &
|
27
|
+
requirement: &70145766743220 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,21 +32,36 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70145766743220
|
36
36
|
description: This gem allow you publish your jekyll static site via FTP, easy as pie.
|
37
37
|
email:
|
38
|
-
-
|
39
|
-
executables:
|
38
|
+
- ricardo.valeriano@gmail.com
|
39
|
+
executables:
|
40
|
+
- monster_remote
|
40
41
|
extensions: []
|
41
42
|
extra_rdoc_files: []
|
42
43
|
files:
|
43
|
-
-
|
44
|
-
- lib/monster/remote/sync.rb
|
45
|
-
- lib/monster/remote/version.rb
|
46
|
-
- lib/monster/remote/wrappers/net_ftp.rb
|
47
|
-
- lib/monster/remote.rb
|
44
|
+
- Gemfile
|
48
45
|
- LICENSE
|
49
46
|
- README.md
|
47
|
+
- Rakefile
|
48
|
+
- bin/monster_remote
|
49
|
+
- lib/monster/remote.rb
|
50
|
+
- lib/monster/remote/cli.rb
|
51
|
+
- lib/monster/remote/configuration.rb
|
52
|
+
- lib/monster/remote/filters/filter.rb
|
53
|
+
- lib/monster/remote/filters/name_based_filter.rb
|
54
|
+
- lib/monster/remote/sync.rb
|
55
|
+
- lib/monster/remote/wrappers/net_ftp.rb
|
56
|
+
- lib/monster_remote.rb
|
57
|
+
- monster_remote.gemspec
|
58
|
+
- spec/monster/remote/cli_spec.rb
|
59
|
+
- spec/monster/remote/configuration_spec.rb
|
60
|
+
- spec/monster/remote/filters/filter_spec.rb
|
61
|
+
- spec/monster/remote/filters/name_based_filter_spec.rb
|
62
|
+
- spec/monster/remote/sync_spec.rb
|
63
|
+
- spec/monster/remote/wrappers/net_ftp_spec.rb
|
64
|
+
- spec/spec_helper.rb
|
50
65
|
homepage: http://github.com/ricardovaleriano/monster_remote
|
51
66
|
licenses: []
|
52
67
|
post_install_message:
|
@@ -64,11 +79,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
79
|
requirements:
|
65
80
|
- - ! '>='
|
66
81
|
- !ruby/object:Gem::Version
|
67
|
-
version:
|
82
|
+
version: '0'
|
68
83
|
requirements: []
|
69
84
|
rubyforge_project:
|
70
|
-
rubygems_version: 1.8.
|
85
|
+
rubygems_version: 1.8.13
|
71
86
|
signing_key:
|
72
87
|
specification_version: 3
|
73
88
|
summary: Publish your jekyll blog via ftp easy as pie
|
74
|
-
test_files:
|
89
|
+
test_files:
|
90
|
+
- spec/monster/remote/cli_spec.rb
|
91
|
+
- spec/monster/remote/configuration_spec.rb
|
92
|
+
- spec/monster/remote/filters/filter_spec.rb
|
93
|
+
- spec/monster/remote/filters/name_based_filter_spec.rb
|
94
|
+
- spec/monster/remote/sync_spec.rb
|
95
|
+
- spec/monster/remote/wrappers/net_ftp_spec.rb
|
96
|
+
- spec/spec_helper.rb
|