Add spec for CLI

This commit is contained in:
Rémi Prévost 2012-01-21 13:47:44 -05:00
parent 192281392b
commit a43064e439
7 changed files with 66 additions and 3 deletions

View File

@ -5,6 +5,8 @@ module Teamocil
# This class handles interaction with the `tmux` utility. # This class handles interaction with the `tmux` utility.
class CLI class CLI
attr_accessor :layout
# Initialize a new run of `tmux` # Initialize a new run of `tmux`
# #
# @param argv [Hash] the command line parameters hash (usually `ARGV`). # @param argv [Hash] the command line parameters hash (usually `ARGV`).
@ -25,9 +27,9 @@ module Teamocil
else else
bail "There is no file \"#{file}\"" unless File.exists?(file) bail "There is no file \"#{file}\"" unless File.exists?(file)
parsed_layout = YAML.load_file(file) parsed_layout = YAML.load_file(file)
layout = Teamocil::Layout.new(parsed_layout, @options) @layout = Teamocil::Layout.new(parsed_layout, @options)
layout.compile! @layout.compile!
layout.execute_commands(layout.generate_commands) @layout.execute_commands(@layout.generate_commands)
end end
end # }}} end # }}}

View File

@ -2,6 +2,7 @@ module Teamocil
# This class act as a wrapper around a tmux YAML layout file # This class act as a wrapper around a tmux YAML layout file
class Layout class Layout
attr_reader :session
# This class represents a session within tmux # This class represents a session within tmux
class Session class Session

21
spec/cli_spec.rb Normal file
View File

@ -0,0 +1,21 @@
require File.join(File.dirname(__FILE__), "spec_helper.rb")
describe Teamocil::CLI do
context "executing" do
before do # {{{
@fake_env = { "TMUX" => 1, "HOME" => File.join(File.dirname(__FILE__), "fixtures") }
end # }}}
it "creates a layout" do # {{{
@cli = Teamocil::CLI.new(["sample"], @fake_env)
@cli.layout.session.name.should == "sample"
@cli.layout.session.windows.length.should == 2
@cli.layout.session.windows.first.name.should == "foo"
@cli.layout.session.windows.last.name.should == "bar"
end # }}}
end
end

10
spec/fixtures/.teamocil/sample-2.yml vendored Normal file
View File

@ -0,0 +1,10 @@
session:
name: sample-2
root: ~
windows:
- name: "foo"
splits:
- cmd: "pwd"
- name: "bar"
splits:
- cmd: "pwd"

10
spec/fixtures/.teamocil/sample.yml vendored Normal file
View File

@ -0,0 +1,10 @@
session:
name: sample
root: ~
windows:
- name: "foo"
splits:
- cmd: "pwd"
- name: "bar"
splits:
- cmd: "pwd"

18
spec/mock/layout.rb Normal file
View File

@ -0,0 +1,18 @@
module Teamocil
module Mock
module Layout
def self.included(base) # {{{
base.class_eval do
# Do not execute anything
def execute_commands(commands)
# Nothing
end
end
end # }}}
end
end
end
Teamocil::Layout.send :include, Teamocil::Mock::Layout

View File

@ -2,6 +2,7 @@ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
require 'yaml' require 'yaml'
require 'teamocil' require 'teamocil'
require File.join(File.dirname(__FILE__), "./mock/layout.rb")
module Helpers module Helpers