taketo 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +13 -0
- data/VERSION +1 -1
- data/bin/taketo +37 -21
- data/features/commands.feature +3 -3
- data/features/connect_to_server.feature +5 -5
- data/features/help.feature +71 -0
- data/lib/taketo/config_printer.rb +84 -0
- data/lib/taketo/constructs/command.rb +1 -1
- data/lib/taketo/destination_resolver.rb +9 -0
- data/lib/taketo/dsl.rb +5 -3
- data/lib/taketo.rb +1 -0
- data/spec/integration/dsl_integration_spec.rb +3 -2
- data/spec/lib/taketo/config_printer_spec.rb +115 -0
- data/spec/lib/taketo/constructs/command_spec.rb +5 -0
- data/spec/lib/taketo/destination_resolver_spec.rb +21 -0
- data/spec/lib/taketo/dsl_spec.rb +30 -14
- metadata +4 -1
data/README.md
CHANGED
@@ -6,6 +6,12 @@ Take Me To
|
|
6
6
|
|
7
7
|
A tiny helper utility to make access to servers easier for different projects and environments.
|
8
8
|
|
9
|
+
Taketo is known to work on:
|
10
|
+
|
11
|
+
* ree 1.8.7
|
12
|
+
* MRI 1.9.2
|
13
|
+
* MRI 1.9.3
|
14
|
+
|
9
15
|
Important note:
|
10
16
|
---------------
|
11
17
|
|
@@ -30,6 +36,7 @@ puts a config into ```~/.taketo.rc.rb```:
|
|
30
36
|
env :TERM => "xterm-256color"
|
31
37
|
command :console do
|
32
38
|
execute "rails c"
|
39
|
+
desc "Run rails console"
|
33
40
|
end
|
34
41
|
end
|
35
42
|
end
|
@@ -39,6 +46,8 @@ puts a config into ```~/.taketo.rc.rb```:
|
|
39
46
|
Then execute ```taketo my_project:staging:server -c console``` to execute the "rails c" with corresponding environment variables set on desired server
|
40
47
|
or just ```taketo my_project:staging:server``` to open bash
|
41
48
|
|
49
|
+
To have a brief overview of the config run ```taketo [destination] --view```
|
50
|
+
|
42
51
|
Destination resolving works intelligently. Given the following config:
|
43
52
|
|
44
53
|
```ruby
|
@@ -81,6 +90,10 @@ To-Do:
|
|
81
90
|
The Changelog:
|
82
91
|
--------------
|
83
92
|
|
93
|
+
### v0.0.4 (22.07.2012) ###
|
94
|
+
* Add --view option. Now you can view your config quickly: ```taketo my_project:environment:server --view``` or just ```taketo --view```
|
95
|
+
* Now commands can have description
|
96
|
+
|
84
97
|
### v0.0.3 (22.07.2012) ###
|
85
98
|
* Add default_destination config option
|
86
99
|
* Add intelligent destination resolving
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/bin/taketo
CHANGED
@@ -24,20 +24,34 @@ end
|
|
24
24
|
|
25
25
|
include Taketo
|
26
26
|
|
27
|
+
DEFAULT_CONFIG_FILE = File.join(ENV['HOME'], ".taketo.rc.rb")
|
28
|
+
|
27
29
|
def parse_options
|
28
|
-
options = { :config =>
|
30
|
+
options = { :config => DEFAULT_CONFIG_FILE }
|
29
31
|
|
30
32
|
OptionParser.new do |opts|
|
31
|
-
opts.banner =
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
opts.banner = "Usage: taketo [destination] [options]"
|
34
|
+
opts.version = VERSION
|
35
|
+
opts.separator ""
|
36
|
+
opts.separator "Common options:"
|
35
37
|
|
36
|
-
opts.on("-f CONFIG", "--config") do |c|
|
38
|
+
opts.on("-f CONFIG", "--config", "Use custom config file (default: #{DEFAULT_CONFIG_FILE})") do |c|
|
37
39
|
options[:config] = c
|
38
40
|
end
|
39
41
|
|
40
|
-
opts.on("
|
42
|
+
opts.on("-c COMMAND", "--command", "Command to execute on destination server",
|
43
|
+
" (COMMAND either declared in config or passed as an argument)") do |c|
|
44
|
+
raise OptionParser::MissingArgument if String(c).strip.empty?
|
45
|
+
options[:command] = c
|
46
|
+
end
|
47
|
+
|
48
|
+
opts.on("-v", "--view", "Show config contents and exit") do |v|
|
49
|
+
options[:view] = v
|
50
|
+
end
|
51
|
+
|
52
|
+
opts.separator "Special options:"
|
53
|
+
|
54
|
+
opts.on("--dry-run", "Print out what would be run") do |v|
|
41
55
|
options[:dry_run] = v
|
42
56
|
end
|
43
57
|
|
@@ -45,10 +59,6 @@ eaiser for different projects and environments.
|
|
45
59
|
options[:debug] = d
|
46
60
|
end
|
47
61
|
|
48
|
-
opts.on("-c COMMAND", "--command") do |c|
|
49
|
-
raise OptionParser::MissingArgument if String(c).strip.empty?
|
50
|
-
options[:command] = c
|
51
|
-
end
|
52
62
|
end.parse!
|
53
63
|
|
54
64
|
options
|
@@ -72,19 +82,25 @@ def default_command(options)
|
|
72
82
|
end
|
73
83
|
|
74
84
|
begin
|
75
|
-
options
|
76
|
-
config
|
77
|
-
|
85
|
+
options = parse_options
|
86
|
+
config = parse_config(options[:config])
|
78
87
|
destination_path = ARGV.shift.to_s
|
79
|
-
|
88
|
+
resolver = DestinationResolver.new(config, destination_path)
|
80
89
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
if options[:dry_run]
|
85
|
-
puts command_to_execute
|
90
|
+
if options[:view]
|
91
|
+
node = resolver.get_node
|
92
|
+
puts ConfigPrinter.new.render(node).chomp
|
86
93
|
else
|
87
|
-
|
94
|
+
server = resolver.resolve
|
95
|
+
|
96
|
+
server_command = remote_command(server, options)
|
97
|
+
command_to_execute = Commands::SSHCommand.new(server).render(server_command)
|
98
|
+
|
99
|
+
if options[:dry_run]
|
100
|
+
puts command_to_execute
|
101
|
+
else
|
102
|
+
system command_to_execute
|
103
|
+
end
|
88
104
|
end
|
89
105
|
rescue SystemExit
|
90
106
|
# Do nothing
|
data/features/commands.feature
CHANGED
@@ -9,7 +9,7 @@ Feature:
|
|
9
9
|
"""
|
10
10
|
project :slots do
|
11
11
|
environment :staging do
|
12
|
-
server
|
12
|
+
server do
|
13
13
|
host "1.2.3.4"
|
14
14
|
location "/var/apps/slots"
|
15
15
|
end
|
@@ -27,7 +27,7 @@ Feature:
|
|
27
27
|
"""
|
28
28
|
project :slots do
|
29
29
|
environment :staging do
|
30
|
-
server
|
30
|
+
server do
|
31
31
|
host "1.2.3.4"
|
32
32
|
location "/var/apps/slots"
|
33
33
|
command :console do
|
@@ -37,7 +37,7 @@ Feature:
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
"""
|
40
|
-
And I successfully run `taketo --config=/tmp/taketo_test_cfg.rb --dry-run --command console slots:staging
|
40
|
+
And I successfully run `taketo --config=/tmp/taketo_test_cfg.rb --dry-run --command console slots:staging`
|
41
41
|
Then the output should contain
|
42
42
|
"""
|
43
43
|
ssh -t 1.2.3.4 "cd /var/apps/slots; RAILS_ENV=staging rails c"
|
@@ -33,7 +33,7 @@ Feature:
|
|
33
33
|
"""
|
34
34
|
project :slots do
|
35
35
|
environment :staging do
|
36
|
-
server
|
36
|
+
server do
|
37
37
|
host "1.2.3.4"
|
38
38
|
location "/var/apps/slots"
|
39
39
|
end
|
@@ -51,7 +51,7 @@ Feature:
|
|
51
51
|
"""
|
52
52
|
project :slots do
|
53
53
|
environment :staging do
|
54
|
-
server
|
54
|
+
server do
|
55
55
|
host "1.2.3.4"
|
56
56
|
location "/var/apps/slots"
|
57
57
|
env :FOO => "the value"
|
@@ -74,7 +74,7 @@ Feature:
|
|
74
74
|
"""
|
75
75
|
project :slots do
|
76
76
|
environment :staging do
|
77
|
-
server
|
77
|
+
server do
|
78
78
|
host "1.2.3.4"
|
79
79
|
end
|
80
80
|
end
|
@@ -82,13 +82,13 @@ Feature:
|
|
82
82
|
|
83
83
|
project :slots do
|
84
84
|
environment :staging do
|
85
|
-
server
|
85
|
+
server do
|
86
86
|
env :FOO => "bar"
|
87
87
|
end
|
88
88
|
end
|
89
89
|
end
|
90
90
|
"""
|
91
|
-
And I successfully run `taketo --config=/tmp/taketo_test_cfg.rb slots:staging
|
91
|
+
And I successfully run `taketo --config=/tmp/taketo_test_cfg.rb slots:staging --dry-run`
|
92
92
|
Then the output should match /ssh -t 1\.2\.3\.4 "(RAILS_ENV=staging FOO=bar|FOO=bar RAILS_ENV=staging) bash"/
|
93
93
|
|
94
94
|
Scenario: Default destination
|
@@ -0,0 +1,71 @@
|
|
1
|
+
Feature:
|
2
|
+
In order to be able to use the tool effectively
|
3
|
+
As a user
|
4
|
+
I want to view what's set up in config quickly
|
5
|
+
|
6
|
+
Background:
|
7
|
+
When I have the following config in "/tmp/taketo_test_cfg.rb"
|
8
|
+
"""
|
9
|
+
project :foo do
|
10
|
+
environment :bar do
|
11
|
+
server do
|
12
|
+
host "1.2.3.4"
|
13
|
+
port 5678
|
14
|
+
user "pivo"
|
15
|
+
location "/var/apps/vodka"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
project :baz do
|
21
|
+
environment :qux do
|
22
|
+
server :bart do
|
23
|
+
host "2.3.4.5"
|
24
|
+
command :console do
|
25
|
+
execute "something_to_execute"
|
26
|
+
end
|
27
|
+
command :killall do
|
28
|
+
execute "killall humans"
|
29
|
+
desc "Kill ALL humans"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
"""
|
35
|
+
|
36
|
+
Scenario: View full config
|
37
|
+
When I run `taketo --config=/tmp/taketo_test_cfg.rb --view`
|
38
|
+
Then the output should contain exactly:
|
39
|
+
"""
|
40
|
+
Project: foo
|
41
|
+
Environment: bar
|
42
|
+
Server: default
|
43
|
+
Host: 1.2.3.4
|
44
|
+
Port: 5678
|
45
|
+
User: pivo
|
46
|
+
Default location: /var/apps/vodka
|
47
|
+
Environment: RAILS_ENV=bar
|
48
|
+
|
49
|
+
Project: baz
|
50
|
+
Environment: qux
|
51
|
+
Server: bart
|
52
|
+
Host: 2.3.4.5
|
53
|
+
Environment: RAILS_ENV=qux
|
54
|
+
Commands:
|
55
|
+
console
|
56
|
+
killall - Kill ALL humans
|
57
|
+
|
58
|
+
"""
|
59
|
+
|
60
|
+
Scenario: View particular server
|
61
|
+
When I run `taketo --config=/tmp/taketo_test_cfg.rb --view foo:bar:default`
|
62
|
+
Then the output should contain exactly:
|
63
|
+
"""
|
64
|
+
Server: default
|
65
|
+
Host: 1.2.3.4
|
66
|
+
Port: 5678
|
67
|
+
User: pivo
|
68
|
+
Default location: /var/apps/vodka
|
69
|
+
Environment: RAILS_ENV=bar
|
70
|
+
|
71
|
+
"""
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module Taketo
|
2
|
+
class ConfigPrinter
|
3
|
+
def initialize
|
4
|
+
@indent_level = 0
|
5
|
+
@result = ""
|
6
|
+
end
|
7
|
+
|
8
|
+
def result
|
9
|
+
@result.chomp
|
10
|
+
end
|
11
|
+
|
12
|
+
def render(object)
|
13
|
+
method = "render_#{object.class.name.gsub(/[\w:]*::/, '').downcase}"
|
14
|
+
send(method, object)
|
15
|
+
end
|
16
|
+
|
17
|
+
def render_command(command)
|
18
|
+
put command.name.to_s + (" - " + command.description if command.description).to_s
|
19
|
+
result
|
20
|
+
end
|
21
|
+
|
22
|
+
def render_server(server)
|
23
|
+
section("Server: #{server.name}") do
|
24
|
+
put "Host: #{server.host}"
|
25
|
+
put "Port: #{server.port}" if server.port
|
26
|
+
put "User: #{server.username}" if server.username
|
27
|
+
put "Default location: #{server.default_location}" if server.default_location
|
28
|
+
put "Environment: " + server.environment_variables.map { |n, v| "#{n}=#{v}" }.join(" ")
|
29
|
+
unless server.commands.empty?
|
30
|
+
section("Commands:") do
|
31
|
+
server.commands.each { |c| render_command(c) }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
result
|
36
|
+
end
|
37
|
+
|
38
|
+
def render_environment(environment)
|
39
|
+
section("Environment: #{environment.name}", ("(No servers)" if environment.servers.empty?)) do
|
40
|
+
if environment.servers.any?
|
41
|
+
environment.servers.each { |s| render_server(s) }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
result
|
45
|
+
end
|
46
|
+
|
47
|
+
def render_project(project)
|
48
|
+
section("Project: #{project.name}", ("(No environments)" if project.environments.empty?)) do
|
49
|
+
if project.environments.any?
|
50
|
+
project.environments.each { |e| render_environment(e) }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
put
|
54
|
+
result
|
55
|
+
end
|
56
|
+
|
57
|
+
def render_config(config)
|
58
|
+
if config.projects.any?
|
59
|
+
config.projects.each { |p| render_project(p) }
|
60
|
+
|
61
|
+
put
|
62
|
+
put "Default destination: #{config.default_destination}" if config.default_destination
|
63
|
+
else
|
64
|
+
put "There are no projects yet..."
|
65
|
+
end
|
66
|
+
result
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
|
72
|
+
def section(title = nil, note = nil)
|
73
|
+
put [title, note].compact.join(" ") if title
|
74
|
+
@indent_level += 1
|
75
|
+
yield
|
76
|
+
@indent_level -= 1
|
77
|
+
end
|
78
|
+
|
79
|
+
def put(str = nil)
|
80
|
+
@result += " " * @indent_level + str.to_s.chomp + "\n"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
@@ -18,6 +18,15 @@ module Taketo
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
+
def get_node
|
22
|
+
case @path.size
|
23
|
+
when 3 then get_server(*@path)
|
24
|
+
when 2 then get_project_and_environment(*@path).last
|
25
|
+
when 1 then get_project(*@path)
|
26
|
+
when 0 then @config
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
21
30
|
private
|
22
31
|
|
23
32
|
def set_destination(path)
|
data/lib/taketo/dsl.rb
CHANGED
@@ -5,12 +5,13 @@ module Taketo
|
|
5
5
|
class ScopeError < StandardError; end
|
6
6
|
|
7
7
|
class << self
|
8
|
-
def define_scope(scope, parent_scope)
|
9
|
-
define_method scope do
|
8
|
+
def define_scope(scope, parent_scope, options = {})
|
9
|
+
define_method scope do |*args, &block|
|
10
10
|
unless current_scope?(parent_scope)
|
11
11
|
raise ScopeError,
|
12
12
|
"#{scope} can't be defined in #{current_scope} scope"
|
13
13
|
end
|
14
|
+
name = args.shift || options[:default_name] or raise(ArgumentError, "Name not specified")
|
14
15
|
scope_object = current_scope_object.find(scope, name) { @factory.create(scope, name) }
|
15
16
|
in_scope(scope, scope_object) do
|
16
17
|
block.call
|
@@ -52,7 +53,7 @@ module Taketo
|
|
52
53
|
|
53
54
|
define_scope :project, :config
|
54
55
|
define_scope :environment, :project
|
55
|
-
define_scope :server, :environment
|
56
|
+
define_scope :server, :environment, :default_name => :default
|
56
57
|
define_scope :command, :server
|
57
58
|
|
58
59
|
define_attribute(:default_destination, :config) { |destination| current_scope_object.default_destination = destination }
|
@@ -62,6 +63,7 @@ module Taketo
|
|
62
63
|
define_attribute(:location, :server) { |path| current_scope_object.default_location = path }
|
63
64
|
define_attribute(:env, :server) { |env| current_scope_object.env(env) }
|
64
65
|
define_attribute(:execute, :command) { |command| current_scope_object.command = command }
|
66
|
+
define_attribute(:desc, :command) { |description| current_scope_object.description = description }
|
65
67
|
|
66
68
|
private
|
67
69
|
|
data/lib/taketo.rb
CHANGED
@@ -7,7 +7,7 @@ describe "Taketo DSL" do
|
|
7
7
|
config = Taketo::DSL.new(factory).configure do
|
8
8
|
project :slots do
|
9
9
|
environment :staging do
|
10
|
-
server
|
10
|
+
server do
|
11
11
|
host "127.0.0.2"
|
12
12
|
user "deployer"
|
13
13
|
location "/var/app"
|
@@ -40,7 +40,8 @@ describe "Taketo DSL" do
|
|
40
40
|
staging = project.environments[:staging]
|
41
41
|
|
42
42
|
staging.servers.length.should == 1
|
43
|
-
staging_server = staging.servers[:
|
43
|
+
staging_server = staging.servers[:default]
|
44
|
+
staging_server.name.should == :default
|
44
45
|
staging_server.host.should == "127.0.0.2"
|
45
46
|
staging_server.username.should == "deployer"
|
46
47
|
staging_server.default_location.should == "/var/app"
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
require 'taketo/config_printer'
|
3
|
+
|
4
|
+
include Taketo
|
5
|
+
|
6
|
+
describe "ConfigPrinter" do
|
7
|
+
describe "#render" do
|
8
|
+
it "should render based on node class name" do
|
9
|
+
printer.should_receive(:render_fixnum)
|
10
|
+
printer.render(1)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#render_command" do
|
15
|
+
let(:command) { stub(:Command, :name => :foo, :description => nil) }
|
16
|
+
|
17
|
+
it "should render command name" do
|
18
|
+
printer.render_command(command).should == "foo"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should also render description if available" do
|
22
|
+
command.stub(:description => "The description")
|
23
|
+
printer.render_command(command).should == "foo - The description"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#render_server" do
|
28
|
+
let(:server) do
|
29
|
+
stub(:Server,
|
30
|
+
:name => :sponge,
|
31
|
+
:host => "1.2.3.4",
|
32
|
+
:port => 8000,
|
33
|
+
:username => "bob",
|
34
|
+
:default_location => "/var/app",
|
35
|
+
:environment_variables => { :FOO => "bar", :BOO => "baz" })
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should render available server info and commands" do
|
39
|
+
server.stub(:commands => [:the_command])
|
40
|
+
printer.should_receive(:render_command).with(:the_command)
|
41
|
+
printer.render_server(server).should =~
|
42
|
+
%r[Server: sponge
|
43
|
+
Host: 1\.2\.3\.4
|
44
|
+
Port: 8000
|
45
|
+
User: bob
|
46
|
+
Default location: /var/app
|
47
|
+
Environment: (FOO=bar BOO=baz|BOO=baz FOO=bar)
|
48
|
+
Commands:]
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should not render commands if there are none" do
|
52
|
+
server.stub(:commands => [])
|
53
|
+
printer.render_server(server).should_not include("Commands:")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#render_environment" do
|
58
|
+
let(:environment) do
|
59
|
+
stub(:Environment,
|
60
|
+
:name => :foo)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should render environment info and servers" do
|
64
|
+
environment.stub(:servers => [:the_server])
|
65
|
+
printer.should_receive(:render_server).with(:the_server)
|
66
|
+
printer.render_environment(environment).should == "Environment: foo"
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should render appropriate message if there are no servers" do
|
70
|
+
environment.stub(:servers => [])
|
71
|
+
printer.render_environment(environment).should == "Environment: foo (No servers)"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "#render_project" do
|
76
|
+
let(:project) do
|
77
|
+
stub(:Project,
|
78
|
+
:name => :quux)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should render project info and it's environments" do
|
82
|
+
project.stub(:environments => [:the_environment])
|
83
|
+
printer.should_receive(:render_environment).with(:the_environment)
|
84
|
+
printer.render_project(project).should == "Project: quux\n"
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should render appropriate message if there are no environments for project" do
|
88
|
+
project.stub(:environments => [])
|
89
|
+
printer.render_project(project).should == "Project: quux (No environments)\n"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "#render_config" do
|
94
|
+
let(:config) do
|
95
|
+
stub(:Config,
|
96
|
+
:default_destination => "hello:bye")
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should render default destination and all projects" do
|
100
|
+
config.stub(:projects => [:the_project])
|
101
|
+
printer.should_receive(:render_project).with(:the_project)
|
102
|
+
printer.render_config(config).should == "\nDefault destination: hello:bye"
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should render appropriate message if there are no projects" do
|
106
|
+
config.stub(:projects => [])
|
107
|
+
printer.render_config(config).should == "There are no projects yet..."
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def printer
|
112
|
+
@printer ||= ConfigPrinter.new
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
@@ -11,6 +11,11 @@ describe "Command" do
|
|
11
11
|
cmd.command.should == "rails c"
|
12
12
|
end
|
13
13
|
|
14
|
+
specify "#description= should set command description" do
|
15
|
+
cmd.description= "Run rails console"
|
16
|
+
cmd.description.should == "Run rails console"
|
17
|
+
end
|
18
|
+
|
14
19
|
describe "#render" do
|
15
20
|
it "should pick up server's environment variables and location" do
|
16
21
|
server = mock(:Server, :environment_variables => { :FOO => "bar baz" }, :default_location => "/var/apps/the app")
|
@@ -157,6 +157,27 @@ describe "DestinationResolver" do
|
|
157
157
|
end
|
158
158
|
end
|
159
159
|
|
160
|
+
describe "#get_node" do
|
161
|
+
it "should return server when path has 3 segments and is correct" do
|
162
|
+
resolver(config, "foo:bar:s1").get_node.should == server1
|
163
|
+
end
|
164
|
+
|
165
|
+
it "should return environment when path has 2 segments and is correct" do
|
166
|
+
resolver(config, "foo:bar").get_node.name.should == :bar
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should return project when path has 1 segment and is correct" do
|
170
|
+
resolver(config, "foo").get_node.name.should == :foo
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should return the config if path has is empty" do
|
174
|
+
resolver(config, "").get_node.should == config
|
175
|
+
end
|
176
|
+
|
177
|
+
it "should raise NonExistentDestinationError when path is not correct" do
|
178
|
+
expect { resolver(config, "i").get_node }.to raise_error(NonExistentDestinationError)
|
179
|
+
end
|
180
|
+
end
|
160
181
|
|
161
182
|
def resolver(*args)
|
162
183
|
DestinationResolver.new(*args)
|
data/spec/lib/taketo/dsl_spec.rb
CHANGED
@@ -20,29 +20,27 @@ describe "DSL" do
|
|
20
20
|
|
21
21
|
it "should create a #{scope_name} and set it as current scope object" do # it "should create project and set it as current scope object"
|
22
22
|
dsl(parent_scope, factory.create(parent_scope_name)) do |c| # dsl([:config], factory.create(:config)) do |c|
|
23
|
-
c
|
24
|
-
and_yield.and_return(:bacon) # and_yield.and_return(:bacon)
|
25
|
-
factory.should_receive(:create).with(scope_name, :bar) # factory.should_receive(:create).with(:project, :bar)
|
23
|
+
stub_find_or_create_scope_object(c, scope_name, :bar) # stub_find_or_create_scope_object(c, :project, :bar)
|
26
24
|
c.send(scope_name, :bar) do # c.project(:bar) do
|
27
25
|
c.current_scope_object.should_not be_nil # c.current_scope_object.should_not be_nil
|
28
|
-
c.current_scope_object.should ==
|
26
|
+
c.current_scope_object.should == factory.send(scope_name) # c.current_scope_object.should == factory.project
|
29
27
|
end # end
|
30
28
|
end # end
|
31
29
|
end # end
|
32
30
|
|
33
|
-
it "should not leak #{scope_name} as current scope object" do
|
34
|
-
dsl(parent_scope, factory.create(parent_scope_name)) do |c|
|
35
|
-
c
|
36
|
-
c.send(scope_name, :bar) do
|
37
|
-
c.current_scope_object.should == factory.send(scope_name)
|
38
|
-
end
|
39
|
-
c.current_scope_object.should_not == factory.send(scope_name)
|
40
|
-
end
|
41
|
-
end
|
31
|
+
it "should not leak #{scope_name} as current scope object" do # it "should not leak project as current scope object"
|
32
|
+
dsl(parent_scope, factory.create(parent_scope_name)) do |c| # dsl([:config], factory.create(:config)) do |c|
|
33
|
+
stub_find_or_create_scope_object(c, scope_name, :bar) # stub_find_or_create_scope_object(c, :project, :bar)
|
34
|
+
c.send(scope_name, :bar) do # c.project(:bar) do
|
35
|
+
c.current_scope_object.should == factory.send(scope_name) # c.current_scope_object.should == factory.project
|
36
|
+
end # end
|
37
|
+
c.current_scope_object.should_not == factory.send(scope_name) # c.current_scope_object.should_not == factory.project
|
38
|
+
end # end
|
39
|
+
end # end
|
42
40
|
|
43
41
|
it "should add a #{scope_name} to the #{parent_scope_name}'s #{scope_name}s collection" do # it "should add a project to the config's projects collection" do
|
44
42
|
dsl(parent_scope, factory.create(parent_scope_name)) do |c| # dsl([:config], factory.create(:config)) do |c|
|
45
|
-
c
|
43
|
+
stub_find_or_create_scope_object(c, scope_name, :bar) # stub_find_or_create_scope_object(c, :project, :bar)
|
46
44
|
c.current_scope_object.should_receive("append_#{scope_name}"). # c.current_scope_object.should_receive(:append_project).
|
47
45
|
with(factory.send(scope_name)) # with(factory.project)
|
48
46
|
c.send(scope_name, :bar) {} # c.project(:bar) {}
|
@@ -80,6 +78,15 @@ describe "DSL" do
|
|
80
78
|
describe "#server" do
|
81
79
|
it_behaves_like "a scope", :server, :environment
|
82
80
|
|
81
|
+
it "should have name optional" do
|
82
|
+
dsl(scopes[:environment], factory.create(:environment, :foo)) do |c|
|
83
|
+
stub_find_or_create_scope_object(c, :server, :default)
|
84
|
+
c.server do
|
85
|
+
c.current_scope_object.name.should == :default
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
83
90
|
describe "#host" do
|
84
91
|
it_behaves_like "an attribute", :host, :server, :host=, "127.0.0.2"
|
85
92
|
end
|
@@ -106,6 +113,10 @@ describe "DSL" do
|
|
106
113
|
describe "#execute" do
|
107
114
|
it_behaves_like "an attribute", :execute, :command, :command=, "rails c"
|
108
115
|
end
|
116
|
+
|
117
|
+
describe "#desc" do
|
118
|
+
it_behaves_like "an attribute", :desc, :command, :description=, "Run rails console"
|
119
|
+
end
|
109
120
|
end
|
110
121
|
end
|
111
122
|
end
|
@@ -154,5 +165,10 @@ describe "DSL" do
|
|
154
165
|
|
155
166
|
it "should raise meaningful error if config parse failed"
|
156
167
|
end
|
168
|
+
|
169
|
+
def stub_find_or_create_scope_object(scope_object, scope, name)
|
170
|
+
scope_object.current_scope_object.should_receive(:find).and_yield.and_return(factory.create(scope, name))
|
171
|
+
factory.should_receive(:create).with(scope, name)
|
172
|
+
end
|
157
173
|
end
|
158
174
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: taketo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- bin/taketo
|
86
86
|
- lib/taketo/commands/ssh_command.rb
|
87
87
|
- lib/taketo/commands.rb
|
88
|
+
- lib/taketo/config_printer.rb
|
88
89
|
- lib/taketo/config_validator.rb
|
89
90
|
- lib/taketo/constructs/base_construct.rb
|
90
91
|
- lib/taketo/constructs/command.rb
|
@@ -103,6 +104,7 @@ files:
|
|
103
104
|
- lib/taketo.rb
|
104
105
|
- spec/integration/dsl_integration_spec.rb
|
105
106
|
- spec/lib/taketo/commands/ssh_command_spec.rb
|
107
|
+
- spec/lib/taketo/config_printer_spec.rb
|
106
108
|
- spec/lib/taketo/config_validator_spec.rb
|
107
109
|
- spec/lib/taketo/constructs/base_construct_spec.rb
|
108
110
|
- spec/lib/taketo/constructs/command_spec.rb
|
@@ -122,6 +124,7 @@ files:
|
|
122
124
|
- features/commands.feature
|
123
125
|
- features/config_validation.feature
|
124
126
|
- features/connect_to_server.feature
|
127
|
+
- features/help.feature
|
125
128
|
- features/step_definitions/main_steps.rb
|
126
129
|
- features/support/env.rb
|
127
130
|
- Gemfile
|