rutty 2.1.0 → 2.1.1

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 CHANGED
@@ -21,3 +21,4 @@ doc
21
21
  .yardoc
22
22
 
23
23
  ## PROJECT::SPECIFIC
24
+ tmp
data/Gemfile CHANGED
@@ -1,6 +1,10 @@
1
1
  source :gemcutter
2
2
 
3
- gem "jeweler"
4
- gem "commander"
5
- gem "net-ssh"
6
- gem "net-scp"
3
+ gem "commander", '~> 4.0.3'
4
+ gem "net-ssh", '~> 2.0.23'
5
+ gem "net-scp", '~> 1.0.4'
6
+
7
+ group :development do
8
+ gem "jeweler", '~> 1.4.0'
9
+ gem "thoughtbot-shoulda"
10
+ end
@@ -17,12 +17,14 @@ GEM
17
17
  net-ssh (2.0.23)
18
18
  rubyforge (2.0.4)
19
19
  json_pure (>= 1.1.7)
20
+ thoughtbot-shoulda (2.11.1)
20
21
 
21
22
  PLATFORMS
22
23
  ruby
23
24
 
24
25
  DEPENDENCIES
25
- commander
26
- jeweler
27
- net-scp
28
- net-ssh
26
+ commander (~> 4.0.3)
27
+ jeweler (~> 1.4.0)
28
+ net-scp (~> 1.0.4)
29
+ net-ssh (~> 2.0.23)
30
+ thoughtbot-shoulda
data/Rakefile CHANGED
@@ -16,6 +16,7 @@ begin
16
16
  gem.authors = ["Josh Lindsey"]
17
17
  gem.add_development_dependency "bundler", ">= 1.0.0"
18
18
  gem.add_development_dependency "jeweler", ">= 1.4.0"
19
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
19
20
  gem.add_dependency "commander", ">= 4.0.3"
20
21
  gem.add_dependency "net-ssh", ">= 2.0.23"
21
22
  gem.add_dependency "net-scp", ">= 1.0.4"
@@ -24,3 +25,27 @@ begin
24
25
  rescue LoadError
25
26
  puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
26
27
  end
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ begin
37
+ require 'rcov/rcovtask'
38
+ Rcov::RcovTask.new do |test|
39
+ test.libs << 'test'
40
+ test.pattern = 'test/**/test_*.rb'
41
+ test.verbose = true
42
+ end
43
+ rescue LoadError
44
+ task :rcov do
45
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
46
+ end
47
+ end
48
+
49
+ task :test => :check_dependencies
50
+
51
+ task :default => :test
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.1.0
1
+ 2.1.1
data/bin/rutty CHANGED
@@ -18,20 +18,13 @@ add_filter_options = lambda { |c|
18
18
  # Commander config
19
19
  program :name, 'rutty'
20
20
  program :description, 'A DSH implementation in Ruby'
21
- program :version, $r.get_version
21
+ program :version, Rutty::Helpers.get_version
22
22
  program :help_formatter, Commander::HelpFormatter::TerminalCompact
23
23
 
24
24
  default_command :dsh
25
25
 
26
26
  global_option '-c', '--config DIR', 'Directory to load configs from, defaults to ~/.rutty' do |dir|
27
- begin
28
- $r.config File.join(dir, Rutty::Consts::GENERAL_CONF_FILE)
29
- $r.nodes File.join(dir, Rutty::Consts::NODES_CONF_FILE)
30
- rescue Errno::ENOENT => e
31
- if e.to_s =~ /No such file or directory - (.*)/
32
- raise Rutty::NotInstalledError.new "Unable to find #{$1}. Maybe run `rutty init #{dir}' first?"
33
- end
34
- end
27
+ $r.config_dir = dir
35
28
  end
36
29
 
37
30
  # Commander commands
@@ -9,19 +9,26 @@ require 'rutty/nodes'
9
9
 
10
10
  module Rutty
11
11
  class Runner
12
- attr_accessor :config
13
- attr_accessor :nodes
12
+ attr_writer :config_dir
14
13
 
15
14
  include Rutty::Consts
16
15
  include Rutty::Helpers
17
16
  include Rutty::Actions
18
17
 
19
- def config file = Rutty::Consts::GENERAL_CONF
20
- @config ||= Rutty::Config.load_config file
18
+ def initialize config_dir = nil
19
+ self.config_dir = config_dir
21
20
  end
22
21
 
23
- def nodes file = Rutty::Consts::NODES_CONF
24
- @nodes ||= Rutty::Nodes.load_config file
22
+ def config
23
+ @config ||= Rutty::Config.load_config self.config_dir
24
+ end
25
+
26
+ def nodes
27
+ @nodes ||= Rutty::Nodes.load_config self.config_dir
28
+ end
29
+
30
+ def config_dir
31
+ (@config_dir.nil? && Rutty::Consts::CONF_DIR) || @config_dir
25
32
  end
26
33
  end
27
- end
34
+ end
@@ -51,13 +51,13 @@ module Rutty
51
51
  hash[:tags] = options.tags unless options.tags.nil?
52
52
 
53
53
  self.nodes << Rutty::Node.new(hash, self.config.to_hash)
54
- self.nodes.write_config
54
+ self.nodes.write_config self.config_dir
55
55
  end
56
56
 
57
57
  def list_nodes args, options
58
58
  require 'pp'
59
59
 
60
- pp nodes.filter(options)
60
+ pp self.nodes.filter(options)
61
61
  end
62
62
 
63
63
  def dsh args, options
@@ -84,8 +84,7 @@ module Rutty
84
84
  ssh.open_channel do |channel|
85
85
  channel.exec(com_str) do |ch, success|
86
86
  unless success
87
- abort "FAILED: couldn't execute command (ssh.channel.exec
88
- failure)"
87
+ abort "FAILED: couldn't execute command (ssh.channel.exec failure)"
89
88
  end
90
89
 
91
90
  channel.on_data do |ch, data| # stdout
@@ -110,7 +109,7 @@ module Rutty
110
109
  ssh.loop
111
110
  }
112
111
 
113
- nodes.filter(options).each do |node|
112
+ self.nodes.filter(options).each do |node|
114
113
  @returns[node.host] = { :out => '' }
115
114
  begin
116
115
  connections << Net::SSH.start(node.host, node.user, :port => node.port, :paranoid => false,
@@ -155,7 +154,7 @@ module Rutty
155
154
  remote_path = args.pop
156
155
  local_path = args.pop
157
156
 
158
- nodes.filter(options).each do |node|
157
+ self.nodes.filter(options).each do |node|
159
158
  begin
160
159
  connections << Net::SSH.start(node.host, node.user, :port => node.port, :paranoid => false,
161
160
  :user_known_hosts_file => '/dev/null', :keys => [node.keypath],
@@ -2,10 +2,10 @@
2
2
  module Rutty
3
3
  class Config
4
4
  class << self
5
- def load_config file
5
+ def load_config dir
6
6
  require 'yaml'
7
7
 
8
- data = YAML.load(File.open(file).read)
8
+ data = YAML.load(File.open(File.join(dir, Rutty::Consts::GENERAL_CONF_FILE)).read)
9
9
  Rutty::Config.new data
10
10
  end
11
11
  end
@@ -5,13 +5,13 @@ require 'rutty/version'
5
5
  module Rutty
6
6
  module Helpers
7
7
  def check_installed!
8
- unless File.exists? Rutty::Consts::CONF_DIR
9
- raise Rutty::NotInstalledError.new %Q(Can't find conf directory at #{Rutty::Consts::CONF_DIR}.
8
+ unless File.exists? self.config_dir
9
+ raise Rutty::NotInstalledError.new %Q(Can't find conf directory at #{self.config_dir}.
10
10
  Run `rutty init' first. (Or rutty --help for usage))
11
11
  end
12
12
  end
13
13
 
14
- def get_version
14
+ def self.get_version
15
15
  Rutty::Version::STRING
16
16
  end
17
17
  end
@@ -15,5 +15,13 @@ module Rutty
15
15
  def <=> other
16
16
  self.host <=> other.host
17
17
  end
18
+
19
+ def == other
20
+ self.host == other.host and
21
+ self.port == other.port and
22
+ self.user == other.user and
23
+ self.keypath == other.keypath and
24
+ self.tags == other.tags
25
+ end
18
26
  end
19
27
  end
@@ -4,9 +4,9 @@ require 'rutty/consts'
4
4
  module Rutty
5
5
  class Nodes < Array
6
6
  class << self
7
- def load_config file
7
+ def load_config dir
8
8
  require 'yaml'
9
- Rutty::Nodes.new YAML.load(File.open(file).read)
9
+ Rutty::Nodes.new YAML.load(File.open(File.join(dir, Rutty::Consts::NODES_CONF_FILE)).read)
10
10
  end
11
11
  end
12
12
 
@@ -15,16 +15,16 @@ module Rutty
15
15
 
16
16
  ary = Array.new self
17
17
 
18
- ary.reject! { |n| n.keypath == opts[:keypath] } unless opts[:keypath].nil?
19
- ary.reject! { |n| n.user == opts[:user] } unless opts[:user].nil?
20
- ary.reject! { |n| n.port == opts[:port] } unless opts[:port].nil?
21
- ary.reject! { |n| !(n.tags & opts[:tags]).empty? } unless opts[:tags].nil?
18
+ ary.reject! { |n| n.keypath != opts[:keypath] } unless opts[:keypath].nil?
19
+ ary.reject! { |n| n.user != opts[:user] } unless opts[:user].nil?
20
+ ary.reject! { |n| n.port != opts[:port] } unless opts[:port].nil?
21
+ ary.reject! { |n| (n.tags & opts[:tags]).empty? } unless opts[:tags].nil?
22
22
 
23
23
  ary
24
24
  end
25
25
 
26
- def write_config
27
- File.open(Rutty::Consts::NODES_CONF, 'w') do |f|
26
+ def write_config dir
27
+ File.open(File.join(dir, Rutty::Consts::NODES_CONF_FILE), 'w') do |f|
28
28
  YAML.dump(self, f)
29
29
  end
30
30
  end
@@ -2,7 +2,7 @@ module Rutty
2
2
  module Version
3
3
  MAJOR = 2
4
4
  MINOR = 1
5
- PATCH = 0
5
+ PATCH = 1
6
6
  BUILD = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rutty}
8
- s.version = "2.1.0"
8
+ s.version = "2.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Josh Lindsey"]
12
- s.date = %q{2010-11-03}
12
+ s.date = %q{2010-11-05}
13
13
  s.default_executable = %q{rutty}
14
14
  s.description = %q{
15
15
  RuTTY is a DSH (distributed / dancer's shell) written in Ruby. It's used to run commands
@@ -40,13 +40,35 @@ Gem::Specification.new do |s|
40
40
  "lib/rutty/node.rb",
41
41
  "lib/rutty/nodes.rb",
42
42
  "lib/rutty/version.rb",
43
- "rutty.gemspec"
43
+ "rutty.gemspec",
44
+ "test/helper.rb",
45
+ "test/test_action_add_node.rb",
46
+ "test/test_action_init.rb",
47
+ "test/test_actions.rb",
48
+ "test/test_config.rb",
49
+ "test/test_consts.rb",
50
+ "test/test_helpers.rb",
51
+ "test/test_node.rb",
52
+ "test/test_nodes.rb",
53
+ "test/test_runner.rb"
44
54
  ]
45
55
  s.homepage = %q{http://github.com/jlindsey/rutty}
46
56
  s.rdoc_options = ["--charset=UTF-8"]
47
57
  s.require_paths = ["lib"]
48
58
  s.rubygems_version = %q{1.3.7}
49
59
  s.summary = %q{A DSH implementation in Ruby}
60
+ s.test_files = [
61
+ "test/helper.rb",
62
+ "test/test_action_add_node.rb",
63
+ "test/test_action_init.rb",
64
+ "test/test_actions.rb",
65
+ "test/test_config.rb",
66
+ "test/test_consts.rb",
67
+ "test/test_helpers.rb",
68
+ "test/test_node.rb",
69
+ "test/test_nodes.rb",
70
+ "test/test_runner.rb"
71
+ ]
50
72
 
51
73
  if s.respond_to? :specification_version then
52
74
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
@@ -55,12 +77,14 @@ Gem::Specification.new do |s|
55
77
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
56
78
  s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
57
79
  s.add_development_dependency(%q<jeweler>, [">= 1.4.0"])
80
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
58
81
  s.add_runtime_dependency(%q<commander>, [">= 4.0.3"])
59
82
  s.add_runtime_dependency(%q<net-ssh>, [">= 2.0.23"])
60
83
  s.add_runtime_dependency(%q<net-scp>, [">= 1.0.4"])
61
84
  else
62
85
  s.add_dependency(%q<bundler>, [">= 1.0.0"])
63
86
  s.add_dependency(%q<jeweler>, [">= 1.4.0"])
87
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
64
88
  s.add_dependency(%q<commander>, [">= 4.0.3"])
65
89
  s.add_dependency(%q<net-ssh>, [">= 2.0.23"])
66
90
  s.add_dependency(%q<net-scp>, [">= 1.0.4"])
@@ -68,6 +92,7 @@ Gem::Specification.new do |s|
68
92
  else
69
93
  s.add_dependency(%q<bundler>, [">= 1.0.0"])
70
94
  s.add_dependency(%q<jeweler>, [">= 1.4.0"])
95
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
71
96
  s.add_dependency(%q<commander>, [">= 4.0.3"])
72
97
  s.add_dependency(%q<net-ssh>, [">= 2.0.23"])
73
98
  s.add_dependency(%q<net-scp>, [">= 1.0.4"])
@@ -0,0 +1,40 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'rutty'
8
+
9
+ class Test::Unit::TestCase
10
+ TEST_CONF_DIR = File.join(File.dirname(__FILE__), '..', 'tmp')
11
+ TEST_GENERAL_CONF = File.join(TEST_CONF_DIR, 'defaults.yaml')
12
+ TEST_NODES_CONF = File.join(TEST_CONF_DIR, 'nodes.yaml')
13
+
14
+ RUTTY_BIN = File.join File.dirname(__FILE__), '..', 'bin', 'rutty'
15
+
16
+ def call_init
17
+ unless File.exists? TEST_CONF_DIR
18
+ %x(#{RUTTY_BIN} init #{TEST_CONF_DIR})
19
+ end
20
+ end
21
+
22
+ def clean_test_config!
23
+ %x(rm -rf #{TEST_CONF_DIR}) if File.exists? TEST_CONF_DIR
24
+ end
25
+
26
+ def seed_nodes
27
+ %x(#{RUTTY_BIN} add_node localhost -c #{TEST_CONF_DIR} -k ~/.ssh/id_rsa.pem -u root --tags localhost,test -p 22)
28
+ end
29
+
30
+ def ensure_fresh_config!
31
+ clean_test_config!
32
+ call_init
33
+ end
34
+
35
+ def assert_file_exists path
36
+ assert_block "#{path} does not exist" do
37
+ File.exists? path
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,25 @@
1
+ require 'helper'
2
+
3
+ class TestActionAddNode < Test::Unit::TestCase
4
+ context "The `rutty add_node' action" do
5
+ setup { ensure_fresh_config! }
6
+ teardown { clean_test_config! }
7
+
8
+ should "properly create a new node entry when called" do
9
+ require 'yaml'
10
+
11
+ %x(#{RUTTY_BIN} add_node -c #{TEST_CONF_DIR} example.com -k /home/user/.ssh/id_rsa -u root -p 22333 --tags example,testing)
12
+
13
+ nodes = YAML.load(File.open(TEST_NODES_CONF).read)
14
+
15
+ assert_equal 1, nodes.length
16
+
17
+ node = nodes.pop
18
+ assert_equal 'example.com', node.host
19
+ assert_equal '/home/user/.ssh/id_rsa', node.keypath
20
+ assert_equal 22333, node.port
21
+ assert_equal 'root', node.user
22
+ assert_equal %w(example testing), node.tags
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,34 @@
1
+ require 'helper'
2
+
3
+ class TestActionInit < Test::Unit::TestCase
4
+ context "The `rutty init' action" do
5
+ setup { clean_test_config! }
6
+ teardown { clean_test_config! }
7
+
8
+ should "create the file structure if it doesn't exist" do
9
+ out = %x(#{RUTTY_BIN} init #{TEST_CONF_DIR})
10
+
11
+ assert_file_exists TEST_CONF_DIR
12
+ assert_file_exists TEST_GENERAL_CONF
13
+ assert_file_exists TEST_NODES_CONF
14
+ end
15
+
16
+ should "report that the file structure already exists if it does" do
17
+ ensure_fresh_config!
18
+
19
+ out = %x(#{RUTTY_BIN} init #{TEST_CONF_DIR})
20
+
21
+ assert_match /^\s+exists\s+#{TEST_CONF_DIR}$/, out
22
+ assert_match /^\s+exists\s+#{TEST_GENERAL_CONF}$/, out
23
+ assert_match /^\s+exists\s+#{TEST_NODES_CONF}$/, out
24
+ end
25
+
26
+ should "report that it has created the file structure if it doesn't exist" do
27
+ out = %x(#{RUTTY_BIN} init #{TEST_CONF_DIR})
28
+
29
+ assert_match /^\s+create\s+#{TEST_CONF_DIR}$/, out
30
+ assert_match /^\s+create\s+#{TEST_GENERAL_CONF}$/, out
31
+ assert_match /^\s+create\s+#{TEST_NODES_CONF}$/, out
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,15 @@
1
+ require 'helper'
2
+
3
+ class TestActions < Test::Unit::TestCase
4
+ context "The Rutty::Actions module" do
5
+ should "mix in its methods" do
6
+ r = Rutty::Runner.new
7
+
8
+ assert_respond_to r, :init
9
+ assert_respond_to r, :add_node
10
+ assert_respond_to r, :list_nodes
11
+ assert_respond_to r, :dsh
12
+ assert_respond_to r, :scp
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,54 @@
1
+ require 'helper'
2
+
3
+ class TestConfig < Test::Unit::TestCase
4
+ context "The Rutty::Config class" do
5
+ setup { ensure_fresh_config! }
6
+ teardown { clean_test_config! }
7
+
8
+ should "respond to #load_config" do
9
+ assert_respond_to Rutty::Config, :load_config
10
+ end
11
+
12
+ should "properly load the general config file" do
13
+ require 'yaml'
14
+
15
+ assert_equal YAML.load(File.open(TEST_GENERAL_CONF).read), Rutty::Config.load_config(TEST_CONF_DIR).to_hash
16
+ end
17
+ end
18
+
19
+ context "A Rutty::Config instance" do
20
+ setup {
21
+ @config = Rutty::Config.new
22
+ @hash = { :foo => "bar", :baz => "widget" }
23
+ }
24
+
25
+ should "respond to the proper instance methods" do
26
+ assert_respond_to @config, :update!
27
+ assert_respond_to @config, :[]
28
+ assert_respond_to @config, :[]=
29
+ assert_respond_to @config, :to_hash
30
+ assert_respond_to @config, :method_missing
31
+ end
32
+
33
+ should "properly update and return its data variable" do
34
+ @config.update! @hash
35
+
36
+ assert_equal @config.to_hash, @hash
37
+ end
38
+
39
+ should "properly instantiate with data" do
40
+ config = Rutty::Config.new @hash
41
+ assert_equal @hash, config.to_hash
42
+ end
43
+
44
+ should "properly get and set with hash operators" do
45
+ @config[:foo] = "bar"
46
+ assert_equal "bar", @config[:foo]
47
+ end
48
+
49
+ should "properly get and set with object operators" do
50
+ @config.foo = "bar"
51
+ assert_equal "bar", @config.foo
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,20 @@
1
+ require 'helper'
2
+
3
+ class TestConsts < Test::Unit::TestCase
4
+ context "The Rutty::Consts module" do
5
+ should "have all the constants set" do
6
+ assert_not_nil Rutty::Consts::CONF_DIR
7
+ assert_not_nil Rutty::Consts::GENERAL_CONF
8
+ assert_not_nil Rutty::Consts::NODES_CONF
9
+ end
10
+
11
+ should "have the constants be the proper values" do
12
+ assert_equal Rutty::Consts::GENERAL_CONF_FILE, 'defaults.yaml'
13
+ assert_equal Rutty::Consts::NODES_CONF_FILE, 'nodes.yaml'
14
+
15
+ assert_equal Rutty::Consts::CONF_DIR, File.join(ENV['HOME'], '.rutty')
16
+ assert_equal Rutty::Consts::GENERAL_CONF, File.join(Rutty::Consts::CONF_DIR, 'defaults.yaml')
17
+ assert_equal Rutty::Consts::NODES_CONF, File.join(Rutty::Consts::CONF_DIR, 'nodes.yaml')
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,32 @@
1
+ require 'helper'
2
+
3
+ class TestHelpers < Test::Unit::TestCase
4
+ context "The Rutty::Helpers module" do
5
+ setup do
6
+ ensure_fresh_config!
7
+ @obj = Rutty::Runner.new TEST_CONF_DIR
8
+ end
9
+
10
+ teardown { clean_test_config! }
11
+
12
+ should "mixin its helper methods" do
13
+ assert_respond_to @obj, :check_installed!
14
+ end
15
+
16
+ should "respond to its static methods" do
17
+ assert_respond_to Rutty::Helpers, :get_version
18
+ end
19
+
20
+ should "get the correct version" do
21
+ assert_equal Rutty::Helpers.get_version, Rutty::Version::STRING
22
+ end
23
+
24
+ should "correctly check the installation status" do
25
+ clean_test_config!
26
+
27
+ assert_raise Rutty::NotInstalledError do
28
+ @obj.check_installed!
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,38 @@
1
+ require 'helper'
2
+
3
+ class TestNode < Test::Unit::TestCase
4
+ context "A Rutty::Node instance" do
5
+ setup do
6
+ hash = { :foo => "blah", :test => "hello" }
7
+ @defaults = { :foo => "bar", :baz => "widget" }
8
+ @node = Rutty::Node.new hash, @defaults
9
+ end
10
+
11
+ should "respond to its methods" do
12
+ node = Rutty::Node.new Hash.new, @defaults
13
+
14
+ assert_respond_to node, :has_tag?
15
+ assert_respond_to node, :<=>
16
+ end
17
+
18
+ should "properly merge data on initialization" do
19
+ hash = { :foo => "blah", :test => "hello", :baz => "widget" }
20
+ assert_equal hash, @node.to_hash
21
+ end
22
+
23
+ should "report whether it has a tag" do
24
+ @node.tags = %w(foo bar baz)
25
+ assert @node.has_tag?('foo')
26
+ assert !@node.has_tag?('widget')
27
+ end
28
+
29
+ should "properly determine its sorting order relative to other Nodes" do
30
+ hash1 = { :host => 'google.com' }
31
+ hash2 = { :host => 'yahoo.com' }
32
+ node1 = Rutty::Node.new hash1, @defaults
33
+ node2 = Rutty::Node.new hash2, @defaults
34
+
35
+ assert_equal node1 <=> node2, -1
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,67 @@
1
+ require 'helper'
2
+
3
+ class TestNodes < Test::Unit::TestCase
4
+ context "The Rutty::Nodes class" do
5
+ setup do
6
+ ensure_fresh_config!
7
+ seed_nodes
8
+
9
+ @nodes = Rutty::Nodes.load_config TEST_CONF_DIR
10
+ end
11
+
12
+ teardown { clean_test_config! }
13
+
14
+ should "return an instance of itself on #load_config" do
15
+ assert_instance_of Rutty::Nodes, @nodes
16
+ end
17
+
18
+ should "load the nodes from the config file correctly" do
19
+ assert_equal 1, @nodes.length
20
+
21
+ node = @nodes.pop
22
+
23
+ assert_equal 'root', node.user
24
+ assert_equal 22, node.port
25
+ assert_equal "#{ENV['HOME']}/.ssh/id_rsa.pem", node.keypath
26
+ assert_equal %w(localhost test), node.tags
27
+ end
28
+ end
29
+
30
+ context "A Rutty::Nodes instance" do
31
+ setup do
32
+ @node1 = Rutty::Node.new :host => 'localhost',
33
+ :port => 22,
34
+ :user => 'root',
35
+ :keypath => '/dev/null',
36
+ :tags => %w(localhost test)
37
+ @node2 = Rutty::Node.new :host => 'google.com',
38
+ :port => 22,
39
+ :user => 'google',
40
+ :keypath => '/home/user/.ssh/id_rsa',
41
+ :tags => %w(google fake test)
42
+ @nodes = Rutty::Nodes.new [@node1, @node2]
43
+ end
44
+
45
+ teardown { clean_test_config! }
46
+
47
+ should "correctly instantiate when passed an array" do
48
+ assert_contains @nodes, @node1, @node2
49
+ end
50
+
51
+ should "filter out nodes matching provided criteria" do
52
+ assert_equal [@node1], @nodes.filter(:tags => %w(localhost))
53
+ assert_equal [@node1, @node2], @nodes.filter(:port => 22)
54
+ assert_equal [@node2], @nodes.filter(:user => 'google')
55
+ assert_equal [@node2], @nodes.filter(:keypath => '/home/user/.ssh/id_rsa')
56
+ end
57
+
58
+ should "correctly write out a node config" do
59
+ ensure_fresh_config!
60
+
61
+ @nodes.write_config TEST_CONF_DIR
62
+ new_nodes = Rutty::Nodes.load_config TEST_CONF_DIR
63
+
64
+ assert_contains new_nodes, @node1, @node2
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,36 @@
1
+ require 'helper'
2
+
3
+ class TestRunner < Test::Unit::TestCase
4
+ context "A Runner instance" do
5
+ setup do
6
+ ensure_fresh_config!
7
+ @r = Rutty::Runner.new TEST_CONF_DIR
8
+ end
9
+
10
+ teardown { clean_test_config! }
11
+
12
+ should "respond to its methods" do
13
+ assert_respond_to @r, :config
14
+ assert_respond_to @r, :nodes
15
+ assert_respond_to @r, :config_dir
16
+ assert_respond_to @r, :config_dir=
17
+ end
18
+
19
+ should "return the correct object type for #config" do
20
+ assert_instance_of Rutty::Config, @r.config
21
+ end
22
+
23
+ should "return the correct object type for #nodes" do
24
+ assert_instance_of Rutty::Nodes, @r.nodes
25
+ end
26
+
27
+ should "correctly initialize with a supplied configuration directory" do
28
+ assert_equal @r.config_dir, TEST_CONF_DIR
29
+ end
30
+
31
+ should "correctly fall back to default configuration directory" do
32
+ r = Rutty::Runner.new
33
+ assert_equal r.config_dir, Rutty::Consts::CONF_DIR
34
+ end
35
+ end
36
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rutty
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 9
5
5
  prerelease: false
6
6
  segments:
7
7
  - 2
8
8
  - 1
9
- - 0
10
- version: 2.1.0
9
+ - 1
10
+ version: 2.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Josh Lindsey
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-03 00:00:00 -04:00
18
+ date: 2010-11-05 00:00:00 -04:00
19
19
  default_executable: rutty
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -51,9 +51,23 @@ dependencies:
51
51
  type: :development
52
52
  version_requirements: *id002
53
53
  - !ruby/object:Gem::Dependency
54
- name: commander
54
+ name: thoughtbot-shoulda
55
55
  prerelease: false
56
56
  requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ type: :development
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ name: commander
69
+ prerelease: false
70
+ requirement: &id004 !ruby/object:Gem::Requirement
57
71
  none: false
58
72
  requirements:
59
73
  - - ">="
@@ -65,11 +79,11 @@ dependencies:
65
79
  - 3
66
80
  version: 4.0.3
67
81
  type: :runtime
68
- version_requirements: *id003
82
+ version_requirements: *id004
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: net-ssh
71
85
  prerelease: false
72
- requirement: &id004 !ruby/object:Gem::Requirement
86
+ requirement: &id005 !ruby/object:Gem::Requirement
73
87
  none: false
74
88
  requirements:
75
89
  - - ">="
@@ -81,11 +95,11 @@ dependencies:
81
95
  - 23
82
96
  version: 2.0.23
83
97
  type: :runtime
84
- version_requirements: *id004
98
+ version_requirements: *id005
85
99
  - !ruby/object:Gem::Dependency
86
100
  name: net-scp
87
101
  prerelease: false
88
- requirement: &id005 !ruby/object:Gem::Requirement
102
+ requirement: &id006 !ruby/object:Gem::Requirement
89
103
  none: false
90
104
  requirements:
91
105
  - - ">="
@@ -97,7 +111,7 @@ dependencies:
97
111
  - 4
98
112
  version: 1.0.4
99
113
  type: :runtime
100
- version_requirements: *id005
114
+ version_requirements: *id006
101
115
  description: "\n RuTTY is a DSH (distributed / dancer's shell) written in Ruby. It's used to run commands \n on multiple remote servers at once, based on a tagging system. Also allows for multiple\n SCP-style uploads.\n "
102
116
  email: josh@cloudspace.com
103
117
  executables:
@@ -126,6 +140,16 @@ files:
126
140
  - lib/rutty/nodes.rb
127
141
  - lib/rutty/version.rb
128
142
  - rutty.gemspec
143
+ - test/helper.rb
144
+ - test/test_action_add_node.rb
145
+ - test/test_action_init.rb
146
+ - test/test_actions.rb
147
+ - test/test_config.rb
148
+ - test/test_consts.rb
149
+ - test/test_helpers.rb
150
+ - test/test_node.rb
151
+ - test/test_nodes.rb
152
+ - test/test_runner.rb
129
153
  has_rdoc: true
130
154
  homepage: http://github.com/jlindsey/rutty
131
155
  licenses: []
@@ -160,5 +184,14 @@ rubygems_version: 1.3.7
160
184
  signing_key:
161
185
  specification_version: 3
162
186
  summary: A DSH implementation in Ruby
163
- test_files: []
164
-
187
+ test_files:
188
+ - test/helper.rb
189
+ - test/test_action_add_node.rb
190
+ - test/test_action_init.rb
191
+ - test/test_actions.rb
192
+ - test/test_config.rb
193
+ - test/test_consts.rb
194
+ - test/test_helpers.rb
195
+ - test/test_node.rb
196
+ - test/test_nodes.rb
197
+ - test/test_runner.rb