diff --git a/lib/teamocil/cli.rb b/lib/teamocil/cli.rb index 11fb6d7..15df582 100644 --- a/lib/teamocil/cli.rb +++ b/lib/teamocil/cli.rb @@ -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 # }}} diff --git a/lib/teamocil/layout.rb b/lib/teamocil/layout.rb index aab73c6..a9be37a 100644 --- a/lib/teamocil/layout.rb +++ b/lib/teamocil/layout.rb @@ -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 diff --git a/spec/cli_spec.rb b/spec/cli_spec.rb new file mode 100644 index 0000000..bc7354c --- /dev/null +++ b/spec/cli_spec.rb @@ -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 diff --git a/spec/fixtures/.teamocil/sample-2.yml b/spec/fixtures/.teamocil/sample-2.yml new file mode 100644 index 0000000..c2d91a8 --- /dev/null +++ b/spec/fixtures/.teamocil/sample-2.yml @@ -0,0 +1,10 @@ +session: + name: sample-2 + root: ~ + windows: + - name: "foo" + splits: + - cmd: "pwd" + - name: "bar" + splits: + - cmd: "pwd" diff --git a/spec/fixtures/.teamocil/sample.yml b/spec/fixtures/.teamocil/sample.yml new file mode 100644 index 0000000..4106b86 --- /dev/null +++ b/spec/fixtures/.teamocil/sample.yml @@ -0,0 +1,10 @@ +session: + name: sample + root: ~ + windows: + - name: "foo" + splits: + - cmd: "pwd" + - name: "bar" + splits: + - cmd: "pwd" diff --git a/spec/mock/layout.rb b/spec/mock/layout.rb new file mode 100644 index 0000000..c9ca5ce --- /dev/null +++ b/spec/mock/layout.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c5968e0..95d35e4 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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