Add spec for CLI
This commit is contained in:
parent
192281392b
commit
a43064e439
@ -5,6 +5,8 @@ module Teamocil
|
||||
# This class handles interaction with the `tmux` utility.
|
||||
class CLI
|
||||
|
||||
attr_accessor :layout
|
||||
|
||||
# Initialize a new run of `tmux`
|
||||
#
|
||||
# @param argv [Hash] the command line parameters hash (usually `ARGV`).
|
||||
@ -25,9 +27,9 @@ module Teamocil
|
||||
else
|
||||
bail "There is no file \"#{file}\"" unless File.exists?(file)
|
||||
parsed_layout = YAML.load_file(file)
|
||||
layout = Teamocil::Layout.new(parsed_layout, @options)
|
||||
layout.compile!
|
||||
layout.execute_commands(layout.generate_commands)
|
||||
@layout = Teamocil::Layout.new(parsed_layout, @options)
|
||||
@layout.compile!
|
||||
@layout.execute_commands(@layout.generate_commands)
|
||||
end
|
||||
end # }}}
|
||||
|
||||
|
@ -2,6 +2,7 @@ module Teamocil
|
||||
|
||||
# This class act as a wrapper around a tmux YAML layout file
|
||||
class Layout
|
||||
attr_reader :session
|
||||
|
||||
# This class represents a session within tmux
|
||||
class Session
|
||||
|
21
spec/cli_spec.rb
Normal file
21
spec/cli_spec.rb
Normal 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
10
spec/fixtures/.teamocil/sample-2.yml
vendored
Normal 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
10
spec/fixtures/.teamocil/sample.yml
vendored
Normal 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
18
spec/mock/layout.rb
Normal 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
|
@ -2,6 +2,7 @@ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
|
||||
|
||||
require 'yaml'
|
||||
require 'teamocil'
|
||||
require File.join(File.dirname(__FILE__), "./mock/layout.rb")
|
||||
|
||||
module Helpers
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user