Permalink
Browse files

Add bin/lobot

Refactor rake tasks into Lobot::CLI.
Refactor YML loading into Lobot::Config.
Add guard dependency.
  • Loading branch information...
1 parent 8ed8223 commit 73b4239758e32a3e565ed3a778ffe9d6faaec5b0 Doc Ritezel and Matthew Kocher committed Oct 2, 2012
Showing with 168 additions and 10 deletions.
  1. +2 −1 Gemfile
  2. +10 −0 Guardfile
  3. +7 −0 bin/lobot
  4. +2 −2 lib/lobot.rb
  5. +27 −0 lib/lobot/cli.rb
  6. +22 −0 lib/lobot/config.rb
  7. +7 −2 lobot.gemspec
  8. +2 −2 spec/install_spec.rb
  9. +25 −0 spec/lib/lobot/cli_spec.rb
  10. +60 −0 spec/lib/lobot/config_spec.rb
  11. +4 −3 spec/spec_helper.rb
View
@@ -2,6 +2,7 @@ source "http://rubygems.org"
gem "builder", "~> 3.0.0" # Bundler goes into an infinite loop looking for this dep. Feel free to remove.
gem "rvm-capistrano", :group => :development, :require => false
-
+gem "terminal-notifier-guard", :group => :development
+gem "rb-fsevent", :group => :development
# Specify your gem's dependencies in lobot.gemspec
gemspec
View
@@ -0,0 +1,10 @@
+guard 'rspec' do
+ watch(%r{^spec/.+_spec\.rb$})
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
+ watch('spec/spec_helper.rb') { "spec" }
+end
+
+guard 'bundler' do
+ watch('Gemfile')
+end
+
View
@@ -0,0 +1,7 @@
+#!/usr/bin/env ruby
+$: << File.expand_path('../../lib', __FILE__)
+
+require "rubygems"
+require "lobot/cli"
+
+Lobot::CLI.start
View
@@ -1,4 +1,4 @@
-require File.expand_path('lobot/version', File.dirname(__FILE__))
+require File.expand_path("../lobot/version", __FILE__)
require 'headless'
module Lobot
@@ -12,4 +12,4 @@ def self.rails3?
end
end
-require File.expand_path(File.join('lobot', "railtie"), File.dirname(__FILE__)) if Lobot.rails3?
+require File.expand_path("../lobot/railtie", __FILE__) if Lobot.rails3?
View
@@ -0,0 +1,27 @@
+require "thor"
+require "lobot/config"
+
+module Lobot
+ class CLI < Thor
+ desc "ssh", "SSH into Lobot"
+ def ssh
+ exec("ssh -i #{lobot_config.server_ssh_key} ubuntu@#{lobot_config.master} -p #{lobot_config.ssh_port}")
+ end
+
+ desc "open", "Open a browser to Lobot"
+ def open
+ exec("open https://#{lobot_config.basic_auth_user}:#{lobot_config.basic_auth_password}@#{lobot_config.master}/")
+ end
+
+ no_tasks do
+ def lobot_config
+ @lobot_config ||= Lobot::Config.from_file(lobot_config_path)
+ end
+ end
+
+ private
+ def lobot_config_path
+ File.expand_path("config/lobot.yml", Dir.pwd)
+ end
+ end
+end
View
@@ -0,0 +1,22 @@
+require "hashie"
+
+module Lobot
+ class Config
+ attr_accessor :ssh_port, :master, :server_ssh_key, :basic_auth_user, :basic_auth_password
+
+ def initialize(config_hash = {})
+ config = Hashie::Mash.new(config_hash)
+ @ssh_port = config.ssh_port || 22
+ @master = config.master || "127.0.0.1"
+ @server_ssh_key = config.server_ssh_key || File.expand_path("~/.ssh/lobot_id_rsa")
+ @basic_auth_user = config.basic_auth_user || "ci"
+ @basic_auth_password = config.basic_auth_password
+ end
+
+ def self.from_file(yaml)
+ config = nil
+ File.open(yaml, "r") { |file| config = YAML::load(file) }
+ self.new(config)
+ end
+ end
+end
View
@@ -15,8 +15,8 @@ Gem::Specification.new do |s|
s.rubyforge_project = "lobot"
s.files = `git ls-files`.split("\n") + `cd chef/travis-cookbooks && git ls-files`.split("\n").map { |f| "chef/travis-cookbooks/#{f}" }
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.test_files = `git ls-files -- {test,spec,features}`.split("\n")
+ s.executables = `git ls-files -- bin`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
s.add_dependency('fog', '>=0.9.0')
@@ -27,9 +27,14 @@ Gem::Specification.new do |s|
s.add_dependency('nokogiri', '>=1.4.4')
s.add_dependency('ci_reporter', '>=1.7.0')
s.add_dependency('headless')
+ s.add_dependency('thor')
+ s.add_dependency('hashie')
+
s.add_development_dependency('cucumber')
s.add_development_dependency('rspec')
s.add_development_dependency('generator_spec')
s.add_development_dependency('rails')
s.add_development_dependency('jasmine')
+ s.add_development_dependency('guard-rspec')
+ s.add_development_dependency('guard-bundler')
end
View
@@ -55,13 +55,13 @@
prepare_destination
system("echo 'line 2' > #{destination_root}/Capfile")
run_generator
- assert_file "Capfile", "load 'lobot/recipes/ci'\nline 2\n"
+ assert_file "Capfile", "require 'lobot/recipes/ci'\nline 2\n"
end
end
context "Capfile doesn't exist" do
it "create a Capfile" do
- assert_file "Capfile", /load 'lobot\/recipes\/ci'/
+ assert_file "Capfile", /require 'lobot\/recipes\/ci'/
end
it "give you the capify (default) capfile, but commented out" do
View
@@ -0,0 +1,25 @@
+require "spec_helper"
+
+describe Lobot::CLI do
+ let(:lobot_config) { Lobot::Config.new }
+
+ before do
+ subject.stub(:lobot_config).and_return(lobot_config)
+ end
+
+ describe "#ssh" do
+ it "starts an ssh session to the lobot host" do
+ subject.should_receive(:exec).with("ssh -i #{subject.lobot_config.server_ssh_key} ubuntu@#{subject.lobot_config.master} -p #{subject.lobot_config.ssh_port}")
+ subject.ssh
+ end
+ end
+
+ describe "#open" do
+ let(:lobot_config) { Lobot::Config.new(basic_auth_user: "ci", basic_auth_password: "secret") }
+
+ it "opens a web browser with the lobot page" do
+ subject.should_receive(:exec).with("open https://#{subject.lobot_config.basic_auth_user}:#{subject.lobot_config.basic_auth_password}@#{subject.lobot_config.master}/")
+ subject.open
+ end
+ end
+end
@@ -0,0 +1,60 @@
+require "spec_helper"
+
+describe Lobot::Config do
+ describe ".from_file" do
+ let(:tempfile) { Tempfile.new('lobot-config') }
+
+ before do
+ tempfile.write(YAML.dump({ssh_port: 42}))
+ tempfile.close
+ end
+
+ after do
+ tempfile.unlink
+ end
+
+ it "should load from a yaml file" do
+ Lobot::Config.from_file(tempfile.path).ssh_port.should == 42
+ end
+ end
+
+ describe "#ssh_port" do
+ let(:config) { Lobot::Config.new(ssh_port: 33) }
+
+ it "should set the ssh_port" do
+ config.ssh_port.should == 33
+ end
+ end
+
+ describe "#master" do
+ let(:config) { Lobot::Config.new(master: "127.0.0.2") }
+
+ it "should set master" do
+ config.master.should == "127.0.0.2"
+ end
+ end
+
+ describe "#server_ssh_key" do
+ let(:config) { Lobot::Config.new(server_ssh_key: "~/.ssh/gorbypuff") }
+
+ it "should set the server_ssh_key" do
+ config.server_ssh_key.should == "~/.ssh/gorbypuff"
+ end
+ end
+
+ describe "#basic_auth_user" do
+ let(:config) { Lobot::Config.new(basic_auth_user: "tenderlove") }
+
+ it "should set the basic_auth_user" do
+ config.basic_auth_user.should == "tenderlove"
+ end
+ end
+
+ describe "#basic_auth_password" do
+ let(:config) { Lobot::Config.new(basic_auth_password: "gorbypuff") }
+
+ it "should set the basic_auth_password" do
+ config.basic_auth_password.should == "gorbypuff"
+ end
+ end
+end
View
@@ -1,11 +1,12 @@
+$: << File.expand_path("../../lib", __FILE__)
require "rubygems"
require 'rails/all'
require 'rails/generators'
-require File.expand_path('../lib/lobot', File.dirname(__FILE__))
+require "lobot"
+require "lobot/cli"
require 'generator_spec/test_case'
-
require 'generator_spec'
-require File.expand_path('../../lib/generators/lobot/install_generator.rb', __FILE__)
+require "generators/lobot/install_generator"

0 comments on commit 73b4239

Please sign in to comment.