frank 1.0.9 → 1.0.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,143 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path('../../spec_helper.rb', __FILE__)
4
+ require 'frank/publish/ftptls'
5
+
6
+ describe Frank::Publish::FTPTLS do
7
+
8
+ let(:publisher) do
9
+ Frank::Publish::FTPTLS.new(Frank.publish) do |ftp|
10
+ ftp.username = 'my_username'
11
+ ftp.password = 'my_password'
12
+ ftp.hostname = 'ftp.example.com'
13
+ ftp.local_path = '/local/path'
14
+ ftp.remote_path = '/remote/path'
15
+ end
16
+ end
17
+
18
+ before(:all) do
19
+ Frank.bootstrap(File.join(File.dirname(__FILE__), 'template'))
20
+ end
21
+
22
+ describe '#initialize' do
23
+ it 'should set the correct values' do
24
+ publisher.username.should == 'my_username'
25
+ publisher.password.should == 'my_password'
26
+ publisher.hostname.should == 'ftp.example.com'
27
+ publisher.port.should == 21
28
+ publisher.local_path.should == '/local/path'
29
+ publisher.remote_path.should == 'remote/path'
30
+
31
+ end
32
+
33
+ it 'should remove any preceeding tilde and slash from the path' do
34
+ publisher = Frank::Publish::FTPTLS.new(Frank.publish) do |ftp|
35
+ ftp.remote_path = '~/my_backups/path'
36
+ end
37
+ publisher.remote_path.should == 'my_backups/path'
38
+ end
39
+
40
+ context 'when setting configuration defaults' do
41
+
42
+
43
+ end # context 'when setting configuration defaults'
44
+
45
+ end # describe '#initialize'
46
+
47
+ describe '#connection' do
48
+ let(:connection) { mock }
49
+
50
+ it 'should yield a connection to the remote server' do
51
+ Net::FTPTLS.expects(:open).with(
52
+ 'ftp.example.com', 'my_username', 'my_password'
53
+ ).yields(connection)
54
+
55
+ connection.expects(:passive=).with(true)
56
+
57
+ publisher.send(:connection) do |ftp|
58
+ ftp.should be(connection)
59
+ end
60
+ end
61
+
62
+ it 'should set the Net::FTP_PORT constant' do
63
+ publisher.port = 40
64
+ Net::FTPTLS.expects(:const_defined?).with(:FTP_PORT).returns(true)
65
+ Net::FTPTLS.expects(:send).with(:remove_const, :FTP_PORT)
66
+ Net::FTPTLS.expects(:send).with(:const_set, :FTP_PORT, 40)
67
+
68
+ Net::FTPTLS.expects(:open)
69
+ publisher.send(:connection)
70
+ end
71
+
72
+ end # describe '#connection'
73
+
74
+ describe '#transfer!' do
75
+ let(:connection) { mock }
76
+ let(:package) { mock }
77
+ let(:files) { ["file1", "file2", "subdir1/file3", "subdir2/file4"] }
78
+ let(:dirs) { ["subdir1", "subdir2"] }
79
+ let(:s) { sequence '' }
80
+
81
+ before do
82
+ publisher.stubs(:connection).yields(connection)
83
+ publisher.stubs(:files_to_transfer).returns(files)
84
+ publisher.stubs(:directories).returns(dirs)
85
+ end
86
+
87
+ it 'should transfer the files' do
88
+
89
+
90
+ # connection.expects(:chdir).in_sequence(s).with('remote/path')
91
+
92
+ #publisher.expects(:directories).in_sequence(s)
93
+
94
+ publisher.expects(:create_remote_path).in_sequence(s).with('remote/path/subdir1', connection)
95
+ publisher.expects(:create_remote_path).in_sequence(s).with('remote/path/subdir2', connection)
96
+
97
+ connection.expects(:put).in_sequence(s).with(
98
+ File.join('/local/path', 'file1'),
99
+ File.join('remote/path', 'file1')
100
+ )
101
+
102
+ connection.expects(:put).in_sequence(s).with(
103
+ File.join('/local/path', 'file2'),
104
+ File.join('remote/path', 'file2')
105
+ )
106
+
107
+ connection.expects(:put).in_sequence(s).with(
108
+ File.join('/local/path', 'subdir1/file3'),
109
+ File.join('remote/path', 'subdir1/file3')
110
+ )
111
+
112
+ connection.expects(:put).in_sequence(s).with(
113
+ File.join('/local/path', 'subdir2/file4'),
114
+ File.join('remote/path', 'subdir2/file4')
115
+ )
116
+
117
+ publisher.send(:transfer!)
118
+ end
119
+ end # describe '#transfer!'
120
+
121
+
122
+ describe '#create_remote_path' do
123
+ let(:connection) { mock }
124
+ let(:remote_path) { 'remote/folder/another_folder' }
125
+ let(:s) { sequence '' }
126
+
127
+ context 'while properly creating remote directories one by one' do
128
+ it 'should rescue any FTPPermErrors and continue' do
129
+ connection.expects(:mkdir).in_sequence(s).
130
+ with("remote").raises(Net::FTPPermError)
131
+ connection.expects(:mkdir).in_sequence(s).
132
+ with("remote/folder")
133
+ connection.expects(:mkdir).in_sequence(s).
134
+ with("remote/folder/another_folder")
135
+
136
+ expect do
137
+ publisher.send(:create_remote_path, remote_path, connection)
138
+ end.not_to raise_error
139
+ end
140
+ end
141
+ end
142
+
143
+ end
@@ -0,0 +1,62 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path('../../spec_helper.rb', __FILE__)
4
+ require 'frank/publish/scp'
5
+
6
+ describe Frank::Publish::SCP do
7
+
8
+ let(:publisher) do
9
+ Frank::Publish::SCP.new(Frank.publish) do |scp|
10
+ scp.username = 'my_username'
11
+ scp.password = 'my_password'
12
+ scp.hostname = 'scp.example.com'
13
+ scp.local_path = '/local/path'
14
+ scp.remote_path = '/remote/path'
15
+ end
16
+ end
17
+
18
+ before(:all) do
19
+ Frank.bootstrap(File.join(File.dirname(__FILE__), 'template'))
20
+ end
21
+
22
+ describe '#initialize' do
23
+ it 'should set the correct values' do
24
+ publisher.username.should == 'my_username'
25
+ publisher.password.should == 'my_password'
26
+ publisher.hostname.should == 'scp.example.com'
27
+ publisher.port.should == 22
28
+ publisher.local_path.should == '/local/path'
29
+ publisher.remote_path.should == '/remote/path'
30
+
31
+ end
32
+
33
+ end # describe '#initialize'
34
+
35
+ describe '#connection' do
36
+ let(:connection) { mock }
37
+
38
+ it 'should yield a connection to the remote server' do
39
+ Net::SCP.expects(:start).with('scp.example.com', 'my_username', :password => 'my_password').yields(connection)
40
+
41
+ publisher.send(:connection) do |scp|
42
+ scp.should be(connection)
43
+ end
44
+ end
45
+
46
+ end # describe '#connection'
47
+
48
+ describe '#transfer!' do
49
+ let(:connection) { mock }
50
+
51
+ before do
52
+ publisher.stubs(:connection).yields(connection)
53
+ end
54
+
55
+ it 'should transfer the local_path to remote_path using upload!' do
56
+ connection.expects(:upload!).with('/local/path', '/remote/path')
57
+
58
+ publisher.send(:transfer!)
59
+ end
60
+ end # describe '#transfer!'
61
+
62
+ end
@@ -0,0 +1,62 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path('../../spec_helper.rb', __FILE__)
4
+ require 'frank/publish/sftp'
5
+
6
+ describe Frank::Publish::SFTP do
7
+
8
+ let(:publisher) do
9
+ Frank::Publish::SFTP.new(Frank.publish) do |scp|
10
+ scp.username = 'my_username'
11
+ scp.password = 'my_password'
12
+ scp.hostname = 'scp.example.com'
13
+ scp.local_path = '/local/path'
14
+ scp.remote_path = '/remote/path'
15
+ end
16
+ end
17
+
18
+ before(:all) do
19
+ Frank.bootstrap(File.join(File.dirname(__FILE__), 'template'))
20
+ end
21
+
22
+ describe '#initialize' do
23
+ it 'should set the correct values' do
24
+ publisher.username.should == 'my_username'
25
+ publisher.password.should == 'my_password'
26
+ publisher.hostname.should == 'scp.example.com'
27
+ publisher.port.should == 22
28
+ publisher.local_path.should == '/local/path'
29
+ publisher.remote_path.should == '/remote/path'
30
+
31
+ end
32
+
33
+ end # describe '#initialize'
34
+
35
+ describe '#connection' do
36
+ let(:connection) { mock }
37
+
38
+ it 'should yield a connection to the remote server' do
39
+ Net::SFTP.expects(:start).with('scp.example.com', 'my_username', :password => 'my_password').yields(connection)
40
+
41
+ publisher.send(:connection) do |scp|
42
+ scp.should be(connection)
43
+ end
44
+ end
45
+
46
+ end # describe '#connection'
47
+
48
+ describe '#transfer!' do
49
+ let(:connection) { mock }
50
+
51
+ before do
52
+ publisher.stubs(:connection).yields(connection)
53
+ end
54
+
55
+ it 'should transfer the local_path to remote_path using upload!' do
56
+ connection.expects(:upload!).with('/local/path', '/remote/path')
57
+
58
+ publisher.send(:transfer!)
59
+ end
60
+ end # describe '#transfer!'
61
+
62
+ end
@@ -1,23 +1,73 @@
1
- require File.dirname(__FILE__) + '/helper'
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
2
3
 
3
4
  describe Frank::Publish do
4
5
  include Rack::Test::Methods
5
6
  include Frank::Spec::Helpers
6
7
 
7
- let(:proj_dir) { File.join(File.dirname(__FILE__), 'template') }
8
+ let(:proj_dir) { File.join(File.dirname(__FILE__), 'template') }
9
+ let(:protocols) { [:ftp, :ftptls, :sftp, :scp] }
8
10
 
9
- before :all do
10
- Dir.chdir proj_dir do
11
- frank 'publish'
12
- end
11
+ before(:all) do
12
+ Frank.bootstrap(proj_dir)
13
+ end
14
+
15
+ describe '#exit_unless_configured' do
16
+
17
+ before do
18
+ Frank.publish.host = 'example.com'
19
+ Frank.publish.username = 'test'
13
20
  end
14
21
 
15
- it 'creates the published folder' do
16
- File.exist?("/tmp/frankexp-#{proj_dir.split('/').last}").should be_true
22
+ # How do I prohibit SystemExit from really exiting?
23
+ #
24
+ #it 'should exit if mandatory username param is missing' do
25
+ # Frank.publish.username= nil
26
+ #
27
+ # lambda {
28
+ # Frank::Publish.exit_unless_configured
29
+ # }.should raise_error(SystemExit)
30
+ #end
31
+ #
32
+ #it 'should exit if mandatory host param is missing' do
33
+ # Frank.publish.host= nil
34
+ #
35
+ # lambda {
36
+ # Frank::Publish.exit_unless_configured
37
+ # }.should raise_error(SystemExit)
38
+ #end
39
+
40
+ it 'should return the publish protocol to use' do
41
+ protocols.each do |p|
42
+ Frank.publish.mode = p
43
+
44
+ Frank::Publish.exit_unless_configured.should == p
45
+ end
46
+
17
47
  end
18
48
 
19
- after(:all) do
20
- #FileUtils.rm_r File.join(File.dirname(__FILE__), 'template/output')
49
+ end
50
+
51
+ describe '#execute!' do
52
+
53
+ let(:publisher) { mock }
54
+
55
+ it 'should instatiate and call perform! on the appropriate class' do
56
+ protocols.each do |proto|
57
+ Frank.publish.mode = proto
58
+
59
+ require "frank/publish/#{proto}"
60
+
61
+ clazz = Frank::Publish.const_get(proto.to_s.upcase)
62
+ clazz.stubs(:new).with(Frank.publish).returns(publisher)
63
+ publisher.expects(:perform!)
64
+
65
+ Frank::Publish.execute!
66
+
67
+ end
68
+
21
69
  end
70
+ end
71
+
22
72
 
23
73
  end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/helper'
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
3
  describe Frank::Render do
4
4
  include Rack::Test::Methods
@@ -56,7 +56,7 @@ describe Frank::Render do
56
56
  template = @app.render('partial_locals_test.haml')
57
57
  template.should == "\n<div id='p'>/partial_locals_test</div>\n<div id='layout'>\n <h1>hello worlds</h1>\n <h2>/partial_locals_test</h2>\n <p>hello from local</p>\n</div>\n"
58
58
  end
59
-
59
+
60
60
  it 'renders less template' do
61
61
  template = @app.render('stylesheets/less.less')
62
62
  template.should include("#hello-worlds { background: red; }")
@@ -1,23 +1,24 @@
1
1
  testdir = File.dirname(__FILE__)
2
2
  $:.unshift testdir unless $LOAD_PATH.include?(testdir)
3
3
 
4
- require 'bundler'
5
- Bundler.setup
4
+ require 'rubygems' if RUBY_VERSION < '1.9'
5
+ require 'bundler/setup'
6
6
 
7
7
  require 'stringio'
8
8
  require 'rack/test'
9
9
  require 'template/helpers'
10
10
  require 'frank'
11
+ require 'frank/publish/base'
11
12
 
12
13
  module Kernel
13
- def capture_stdout
14
- out = StringIO.new
15
- $stdout = out
16
- yield
17
- return out
18
- ensure
19
- $stdout = STDOUT
20
- end
14
+ def capture_stdout
15
+ out = StringIO.new
16
+ $stdout = out
17
+ yield
18
+ return out
19
+ ensure
20
+ $stdout = STDOUT
21
+ end
21
22
  end
22
23
 
23
24
  module Frank
@@ -37,3 +38,20 @@ module Frank
37
38
  end
38
39
  end
39
40
  end
41
+
42
+ module Frank
43
+ module Publish
44
+ def self.ok_message str, prefix = "";
45
+ end
46
+
47
+ def self.err_message str, prefix = "";
48
+ end
49
+ end
50
+ end
51
+
52
+ RSpec.configure do |config|
53
+ ##
54
+ # Use Mocha to mock with RSpec
55
+ config.mock_with :mocha
56
+
57
+ end
@@ -1,4 +1,5 @@
1
1
  Frank.environment = :test
2
- Frank.publish.path = '/tmp'
3
- Frank.publish.host = 'linda'
4
- Frank.publish.user = 'badmin'
2
+ Frank.publish.path = '/remote/path'
3
+ Frank.publish.host = 'example.com'
4
+ Frank.publish.user = 'test'
5
+ Frank.publish.password = 'secret'
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/helper'
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
2
 
3
3
  describe Frank::TemplateHelpers do
4
4
  include Rack::Test::Methods
@@ -27,12 +27,12 @@ describe Frank::TemplateHelpers do
27
27
  template = @app.render('refresh.haml')
28
28
  template.should include("<script type=\"text/javascript\">\n (function(){")
29
29
  end
30
-
30
+
31
31
  it 'renders content_for haml in the layout' do
32
32
  template = @app.render('content_for_haml.haml')
33
33
  template.should == "<meta foo='content' />\n<div id='p'>/content_for_haml</div>\n<div id='layout'>\n \n</div>\n"
34
34
  end
35
-
35
+
36
36
  it 'renders content_for erb in the layout' do
37
37
  template = @app.render('content_for_erb.erb')
38
38
  template.should == " <meta foo='content' />\n<div id='p'>/content_for_erb</div>\n<div id='layout'>\n \n</div>\n"
@@ -84,7 +84,7 @@ describe Frank::TemplateHelpers do
84
84
  it 'render image url using imager' do
85
85
  template = @app.render('lorem_test.haml')
86
86
  reg1 = /<img src='http:\/\/placehold\.it\/400x300' \/>/
87
- reg2 = /<img src='http:\/\/placehold\.it\/400x300\/[a-z0-9]{6}\/[a-z0-9]{6}' \/>/
87
+ reg2 = /<img src='http:\/\/placehold\.it\/400x300\/[a-z0-9]{6}\/[a-z0-9]{6}' \/>/
88
88
  reg3 = /<img src='http:\/\/placehold\.it\/400x300\/444\/eee' \/>/
89
89
  reg4 = /<img src='http:\/\/placehold\.it\/400x300\/ccc\/aaa' \/>/
90
90
  reg5 = /<img src='http:\/\/placehold\.it\/400x300\/444(&amp;|&)text=blah' \/>/