crane 0.1.9
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 +11 -0
- data/Gemfile +4 -0
- data/README.markdown +51 -0
- data/Rakefile +9 -0
- data/bin/crane +6 -0
- data/crane.gemspec +24 -0
- data/lib/crane.rb +3 -0
- data/lib/crane/commands/init.rb +42 -0
- data/lib/crane/commands/push.rb +151 -0
- data/lib/crane/commands/test.rb +59 -0
- data/lib/crane/config.rb +110 -0
- data/lib/crane/crane.rb +118 -0
- data/lib/crane/ftp.rb +142 -0
- data/lib/crane/shell_initializer.rb +55 -0
- data/lib/crane/version.rb +3 -0
- data/lib/shell/shell.rb +125 -0
- data/test/bin/test_crane.rb +22 -0
- data/test/lib/crane/commands/test_push.rb +46 -0
- data/test/lib/crane/commands/test_test.rb +37 -0
- data/test/lib/crane/test_config.rb +107 -0
- data/test/lib/crane/test_ftp.rb +68 -0
- data/test/lib/crane/test_shell_initializer.rb +52 -0
- data/test/lib/shell/test_parser.rb +26 -0
- data/test/resources/configurations/crane +5 -0
- data/test/resources/configurations/crane_wrong_remote_dir +5 -0
- data/test/resources/source_codes/today_file.rb +0 -0
- data/test/set_test_environment.rb +1 -0
- metadata +97 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
$:.unshift File.expand_path('../../../lib/', __FILE__)
|
3
|
+
require "crane/shell_initializer"
|
4
|
+
|
5
|
+
class TestCrane < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_push_listing_files
|
8
|
+
|
9
|
+
today_file = File.expand_path('../../resources/source_codes/today_file.rb', __FILE__)
|
10
|
+
`touch #{today_file}`
|
11
|
+
begin
|
12
|
+
output = `echo "n" | ruby bin/crane push today -list`
|
13
|
+
rescue SystemExit
|
14
|
+
end
|
15
|
+
|
16
|
+
assert output =~ /today_file/
|
17
|
+
assert output =~ /Push (.*) files to the server\? \[Y\/n\]/
|
18
|
+
|
19
|
+
`touch -mt 200002202020 #{today_file}`
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "crane/commands/push"
|
3
|
+
require File.expand_path("../../../../set_test_environment.rb", __FILE__)
|
4
|
+
|
5
|
+
class TestPushCommand < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
unless File.exists?(File.expand_path("../../../../.crane", __FILE__))
|
9
|
+
Config.PATH = File.expand_path("../../../resources/configurations/crane", __FILE__)
|
10
|
+
end
|
11
|
+
|
12
|
+
@lab_file = "test/resources/source_codes/today_file.rb"
|
13
|
+
@lab_file_absolute = File.expand_path("../../../../resources/source_codes/today_file.rb", __FILE__)
|
14
|
+
|
15
|
+
@obj = Crane::Commands::Push.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_get_todays_files
|
19
|
+
system "touch -mt " + Time.new.strftime("%Y%m%d%H%M") + " " + @lab_file_absolute
|
20
|
+
assert @obj.within_defined_interval?(@lab_file, "today")
|
21
|
+
assert !@obj.within_defined_interval?(@lab_file, "yesterday")
|
22
|
+
assert @obj.within_defined_interval?(@lab_file, "1h")
|
23
|
+
assert @obj.within_defined_interval?(@lab_file, "2h")
|
24
|
+
assert @obj.within_defined_interval?(@lab_file, "3h")
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_get_yesterdays_files
|
28
|
+
system "touch -mt " + (Time.new - (60 * 60 * 24)).strftime("%Y%m%d%H%M") + " " + @lab_file_absolute
|
29
|
+
|
30
|
+
assert @obj.within_defined_interval?(@lab_file, "yesterday")
|
31
|
+
assert !@obj.within_defined_interval?(@lab_file, "today")
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_list_has_today_file
|
35
|
+
system "touch -mt " + Time.new.strftime("%Y%m%d%H%M") + " " + @lab_file_absolute
|
36
|
+
list_of_files = @obj.get_files "today"
|
37
|
+
assert list_of_files.to_s =~ /resources\/source_codes\/today_file\.rb/
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_list_has_yesterdays_file
|
41
|
+
system "touch -mt " + (Time.new - (60 * 60 * 24)).strftime("%Y%m%d%H%M") + " " + @lab_file_absolute
|
42
|
+
list_of_files = @obj.get_files "yesterday"
|
43
|
+
assert list_of_files.to_s =~ /resources\/source_codes\/today_file\.rb/
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "crane/commands/test"
|
3
|
+
require File.expand_path("../../../../set_test_environment.rb", __FILE__)
|
4
|
+
|
5
|
+
class TestTestCommand < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
Config.PATH = File.expand_path("../../../resources/configurations/crane", __FILE__)
|
9
|
+
@obj = Crane::Commands::Test.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_remote_dir
|
13
|
+
@obj.ftp_remote_dir?
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_has_connection
|
17
|
+
Config.PATH = File.expand_path("../../../../resources/configurations/crane", __FILE__)
|
18
|
+
assert @obj.has_ftp_connection?
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_whole_test_process_right_ftp
|
22
|
+
Config.PATH = File.expand_path("../../../../resources/configurations/crane", __FILE__)
|
23
|
+
assert Config.has_config_file?
|
24
|
+
assert @obj.has_ftp_connection?
|
25
|
+
assert @obj.ftp_remote_dir?
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_whole_test_process_right_ftp_wrong_remote_dir
|
29
|
+
Config.PATH = File.expand_path("../../../../resources/configurations/crane_wrong_remote_dir", __FILE__)
|
30
|
+
assert Config.has_config_file?
|
31
|
+
assert @obj.has_ftp_connection?
|
32
|
+
assert !@obj.ftp_remote_dir?
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "crane/config"
|
3
|
+
|
4
|
+
class TestConfig < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
Config.PATH = File.expand_path("../../../resources/configurations/crane", __FILE__)
|
8
|
+
|
9
|
+
@config = {}
|
10
|
+
@config[:ftp] = {
|
11
|
+
:host => 'host_address',
|
12
|
+
:username => 'username',
|
13
|
+
:password => 'password',
|
14
|
+
:remote_root_dir => '/public_html'
|
15
|
+
}
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_ignore_files_as_array
|
20
|
+
assert_equal "Array", Config.IGNORE_FILES.class.to_s
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_has_ignore_files
|
24
|
+
assert Config.IGNORE_FILES.include? "crane"
|
25
|
+
assert Config.IGNORE_FILES.include? ".git"
|
26
|
+
assert Config.IGNORE_FILES.include? ".DS_Store"
|
27
|
+
assert Config.IGNORE_FILES.include? ".crane"
|
28
|
+
assert Config.IGNORE_FILES.include? ".crane_config"
|
29
|
+
assert Config.IGNORE_FILES.include? ".project"
|
30
|
+
assert Config.IGNORE_FILES.include? "nb_project"
|
31
|
+
assert Config.IGNORE_FILES.include? ".loadpath"
|
32
|
+
assert Config.IGNORE_FILES.include? ".gitignore"
|
33
|
+
assert Config.IGNORE_FILES.include? ".gitmodules"
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_get_ignored_files_plus_gitignore
|
37
|
+
files = Config.get_ignored_files
|
38
|
+
assert files.include? ".crane"
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_default_config_path
|
42
|
+
Config.PATH = "./"
|
43
|
+
assert_equal "./", Config.PATH
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_has_config_file
|
47
|
+
assert Config::has_config_file?
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_make_config
|
51
|
+
syntax = Config.make_config @config
|
52
|
+
assert syntax =~ /^\[ftp\]\n/
|
53
|
+
assert syntax =~ /^host = host_address\n/
|
54
|
+
assert syntax =~ /^username = username\n/
|
55
|
+
assert syntax =~ /^password = password\n/
|
56
|
+
assert syntax =~ /^remote_root_dir = \/public_html\n/
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_save_config
|
60
|
+
Config.PATH = File.expand_path("../../../resources/configurations/.crane_temp", __FILE__)
|
61
|
+
assert Config.save_config @config
|
62
|
+
assert_equal Config.CONFIG, @config
|
63
|
+
assert File.exists?(Config.PATH), "It seems the file was not saved"
|
64
|
+
|
65
|
+
config = File.open(Config.PATH, "r").read
|
66
|
+
assert config =~ /^\[ftp\]\n/
|
67
|
+
assert config =~ /^host = host_address\n/
|
68
|
+
assert config =~ /^username = username\n/
|
69
|
+
assert config =~ /^password = password\n/
|
70
|
+
assert config =~ /^remote_root_dir = \/public_html\n/
|
71
|
+
|
72
|
+
assert !(config =~ /^\[\[ftp\]\]\n/)
|
73
|
+
|
74
|
+
File.delete Config.PATH
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_load_config
|
78
|
+
Config.PATH = File.expand_path("../../../resources/configurations/.crane_temp", __FILE__)
|
79
|
+
assert Config.save_config @config
|
80
|
+
assert File.exists?(Config.PATH), "It seems the file was not saved"
|
81
|
+
|
82
|
+
config = Config.load_config
|
83
|
+
assert_equal Config.CONFIG, @config
|
84
|
+
assert_equal Config.CONFIG, config
|
85
|
+
assert_equal Hash, config.class
|
86
|
+
assert_equal :ftp, config.keys[0]
|
87
|
+
assert_equal "host_address", config[:ftp][:host]
|
88
|
+
assert_equal "username", config[:ftp][:username]
|
89
|
+
assert_equal "password", config[:ftp][:password]
|
90
|
+
assert_equal "/public_html", config[:ftp][:remote_root_dir]
|
91
|
+
|
92
|
+
File.delete Config.PATH
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_load_config
|
96
|
+
assert File.exists?(Config.PATH), "It seems the file doesn't exist"
|
97
|
+
|
98
|
+
config = Config.load_config
|
99
|
+
assert_equal Config.CONFIG, config
|
100
|
+
assert_equal Hash, config.class
|
101
|
+
assert_equal :ftp, config.keys[0]
|
102
|
+
assert_equal "ftp.secureftp-test.com", config[:ftp][:host]
|
103
|
+
assert_equal "test", config[:ftp][:username]
|
104
|
+
assert_equal "test", config[:ftp][:password]
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "crane/ftp"
|
3
|
+
require "crane/config"
|
4
|
+
|
5
|
+
class TestFtp < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def setup
|
8
|
+
Config.PATH = "./.inexistent_crane"
|
9
|
+
@obj = nil
|
10
|
+
@ftp_auth = {
|
11
|
+
:host => "ftp.secureftp-test.com",
|
12
|
+
:username => "test",
|
13
|
+
:password => "test"
|
14
|
+
}
|
15
|
+
@ftp_auth_wrong_password = {
|
16
|
+
:host => "ftp.secureftp-test.com",
|
17
|
+
:username => "wrong",
|
18
|
+
:password => "wrong"
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_new_ftp
|
23
|
+
@obj = Crane::Ftp.new
|
24
|
+
assert_equal Crane::Ftp, @obj.class
|
25
|
+
assert @obj.connection.nil?, @obj.connection.inspect
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_connect_on_instantiation
|
29
|
+
@obj = Crane::Ftp.new @ftp_auth
|
30
|
+
assert @obj.connection.kind_of?(Net::FTP)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_connect
|
34
|
+
@obj = Crane::Ftp.new
|
35
|
+
connection = @obj.connect(@ftp_auth)
|
36
|
+
assert connection
|
37
|
+
assert @obj.connection.kind_of?(Net::FTP)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_connect_autoloading_config_info
|
41
|
+
Config.PATH = File.expand_path("../../../resources/configurations/crane", __FILE__)
|
42
|
+
@obj = Crane::Ftp.new
|
43
|
+
connection = @obj.connection
|
44
|
+
assert connection
|
45
|
+
assert @obj.connection.kind_of?(Net::FTP)
|
46
|
+
|
47
|
+
assert @obj.connect(Config.load_config)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_connect_with_wrong_password
|
51
|
+
@obj = Crane::Ftp.new
|
52
|
+
assert !@obj.connect(@ftp_auth_wrong_password)
|
53
|
+
assert_equal @obj.connection_error, "Invalid username/password"
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_remote_dir
|
57
|
+
Config.PATH = File.expand_path("../../../resources/configurations/crane", __FILE__)
|
58
|
+
@obj = Crane::Ftp.new
|
59
|
+
assert @obj.remote_dir_exists?
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_inexistent_remote_dir
|
63
|
+
Config.PATH = File.expand_path("../../../resources/configurations/crane", __FILE__)
|
64
|
+
@obj = Crane::Ftp.new
|
65
|
+
assert !@obj.remote_dir_exists?("harhar")
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "crane/shell_initializer"
|
3
|
+
require File.expand_path("../../../set_test_environment.rb", __FILE__)
|
4
|
+
|
5
|
+
class TestShellInitializer < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_should_exit?
|
8
|
+
@obj = Shell::Initializer.new([])
|
9
|
+
assert @obj.should_exit?
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_get_command
|
13
|
+
@obj = Shell::Initializer.new(["my_command"])
|
14
|
+
assert !@obj.should_exit?
|
15
|
+
assert_equal "my_command", @obj.get_command
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_command_exist
|
19
|
+
@obj = Shell::Initializer.new([])
|
20
|
+
@obj.command = "init"
|
21
|
+
assert @obj.command_exist?
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_command_does_no_exist
|
25
|
+
@obj = Shell::Initializer.new(["zomg"])
|
26
|
+
assert !@obj.command_exist?
|
27
|
+
|
28
|
+
assert_equal Crane::Engine, @obj.run_command("zomg", []).class
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_command_file
|
33
|
+
@obj = Shell::Initializer.new([])
|
34
|
+
@obj.command = "init"
|
35
|
+
assert_equal(
|
36
|
+
File.expand_path("../../../../lib/crane/commands/init.rb", __FILE__),
|
37
|
+
@obj.get_command_file )
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_load_command
|
41
|
+
require File.expand_path("../../../../lib/crane/commands/init.rb", __FILE__)
|
42
|
+
@obj = Shell::Initializer.new([])
|
43
|
+
assert_equal Crane::Commands::Init, @obj.run_command("init", []).class
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_run
|
47
|
+
require File.expand_path("../../../../lib/crane/commands/init.rb", __FILE__)
|
48
|
+
@obj = Shell::Initializer.new([])
|
49
|
+
@obj.command = "init"
|
50
|
+
assert_equal Crane::Commands::Init, @obj.run.class
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "shell/shell"
|
3
|
+
|
4
|
+
class TestShellParser < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_get_command
|
7
|
+
assert_equal "push", Shell::Parser.get_command(["--test","push","--list", "other_pseudo_command"])
|
8
|
+
assert_equal "push", Shell::Parser.get_command(["push","-list", "other_pseudo_command"])
|
9
|
+
assert_equal "push", Shell::Parser.get_command(["-list","push", "other_pseudo_command"])
|
10
|
+
assert_equal false, Shell::Parser.get_command()
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_get_options
|
14
|
+
assert_equal ["test", "list"], Shell::Parser.get_options( ["push","--test","--list"] )
|
15
|
+
assert_equal ["test", "list", "test2"], Shell::Parser.get_options( ["--test", "-list", "push","--test2"] )
|
16
|
+
assert_equal ["test"], Shell::Parser.get_options( ["--test", "--test", "push"] )
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_is_option
|
20
|
+
assert Shell::Parser.is_option( "test", ["push","--test","--list"] )
|
21
|
+
assert Shell::Parser.is_option( "list", ["push","--test","--list"] )
|
22
|
+
assert !Shell::Parser.is_option( "push", ["push","--test","--list"] )
|
23
|
+
assert_equal false, Shell::Parser.is_option( "test" )
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
TESTING = true
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: crane
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.9
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Alexandre de Oliveira
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-05-21 00:00:00 Z
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: |-
|
17
|
+
This gem allows you to easily send files from your project to a remote
|
18
|
+
server via FTP. Designers and interface programmers can have great benefit
|
19
|
+
from this, for they can easily send all last modified files without needing
|
20
|
+
an specific application for that nor searching directories by hand.
|
21
|
+
email:
|
22
|
+
- chavedomundo@gmail.com
|
23
|
+
executables:
|
24
|
+
- crane
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files: []
|
28
|
+
|
29
|
+
files:
|
30
|
+
- .crane
|
31
|
+
- .gitignore
|
32
|
+
- Gemfile
|
33
|
+
- Gemfile.lock
|
34
|
+
- README.markdown
|
35
|
+
- Rakefile
|
36
|
+
- bin/crane
|
37
|
+
- crane.gemspec
|
38
|
+
- lib/crane.rb
|
39
|
+
- lib/crane/commands/init.rb
|
40
|
+
- lib/crane/commands/push.rb
|
41
|
+
- lib/crane/commands/test.rb
|
42
|
+
- lib/crane/config.rb
|
43
|
+
- lib/crane/crane.rb
|
44
|
+
- lib/crane/ftp.rb
|
45
|
+
- lib/crane/shell_initializer.rb
|
46
|
+
- lib/crane/version.rb
|
47
|
+
- lib/shell/shell.rb
|
48
|
+
- test/bin/test_crane.rb
|
49
|
+
- test/lib/crane/commands/test_push.rb
|
50
|
+
- test/lib/crane/commands/test_test.rb
|
51
|
+
- test/lib/crane/test_config.rb
|
52
|
+
- test/lib/crane/test_ftp.rb
|
53
|
+
- test/lib/crane/test_shell_initializer.rb
|
54
|
+
- test/lib/shell/test_parser.rb
|
55
|
+
- test/resources/configurations/crane
|
56
|
+
- test/resources/configurations/crane_wrong_remote_dir
|
57
|
+
- test/resources/source_codes/today_file.rb
|
58
|
+
- test/set_test_environment.rb
|
59
|
+
homepage: http://github.com/kurko/crane
|
60
|
+
licenses: []
|
61
|
+
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: "0"
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: "0"
|
79
|
+
requirements: []
|
80
|
+
|
81
|
+
rubyforge_project: crane
|
82
|
+
rubygems_version: 1.7.1
|
83
|
+
signing_key:
|
84
|
+
specification_version: 3
|
85
|
+
summary: Send files via FTP automatically.
|
86
|
+
test_files:
|
87
|
+
- test/bin/test_crane.rb
|
88
|
+
- test/lib/crane/commands/test_push.rb
|
89
|
+
- test/lib/crane/commands/test_test.rb
|
90
|
+
- test/lib/crane/test_config.rb
|
91
|
+
- test/lib/crane/test_ftp.rb
|
92
|
+
- test/lib/crane/test_shell_initializer.rb
|
93
|
+
- test/lib/shell/test_parser.rb
|
94
|
+
- test/resources/configurations/crane
|
95
|
+
- test/resources/configurations/crane_wrong_remote_dir
|
96
|
+
- test/resources/source_codes/today_file.rb
|
97
|
+
- test/set_test_environment.rb
|