Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start transitioning some of the features to cli specs.
- Loading branch information
Jay Feldblum
committed
Aug 25, 2012
1 parent
aae5f5b
commit 7e884a8
Showing
4 changed files
with
91 additions
and
22 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,36 @@ | |||
require "securerandom" | |||
|
|||
require "support/cli_macro" | |||
|
|||
require "librarian/chef/cli" | |||
|
|||
module Librarian | |||
module Chef | |||
describe Cli do | |||
include CliMacro | |||
|
|||
describe "init" do | |||
|
|||
it "should create a file named Cheffile" do | |||
cli! "init" | |||
|
|||
Dir.new(pwd).should include "Cheffile" | |||
end | |||
|
|||
end | |||
|
|||
describe "version" do | |||
|
|||
it "should print the version" do | |||
cli! "version" | |||
|
|||
stdout.should == strip_heredoc(<<-STDOUT) | |||
librarian-#{VERSION} | |||
STDOUT | |||
end | |||
|
|||
end | |||
|
|||
end | |||
end | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,55 @@ | |||
require "thor" | |||
|
|||
require "librarian/helpers" | |||
|
|||
module CliMacro | |||
|
|||
class FakeShell < Thor::Shell::Basic | |||
def stdout | |||
@stdout ||= StringIO.new | |||
end | |||
def stderr | |||
@stderr ||= StringIO.new | |||
end | |||
def stdin | |||
raise "unsupported" | |||
end | |||
end | |||
|
|||
def self.included(base) | |||
base.instance_exec do | |||
let(:project_path) do | |||
project_path = Pathname.new(__FILE__).expand_path | |||
project_path = project_path.dirname until project_path.join("Rakefile").exist? | |||
project_path | |||
end | |||
let(:tmp) { project_path.join("tmp/spec/cli") } | |||
let(:pwd) { tmp + SecureRandom.hex(8) } | |||
let(:shell) { FakeShell.new } | |||
|
|||
before { tmp.mkpath } | |||
before { pwd.mkpath } | |||
|
|||
after { tmp.rmtree } | |||
end | |||
end | |||
|
|||
def cli!(*args) | |||
Dir.chdir(pwd) do | |||
described_class.start args, shell: shell | |||
end | |||
end | |||
|
|||
def write_file!(path, content) | |||
pwd.join(path).open("wb"){|f| f.write(content)} | |||
end | |||
|
|||
def strip_heredoc(text) | |||
Librarian::Helpers.strip_heredoc(text) | |||
end | |||
|
|||
def stdout | |||
shell.stdout.string | |||
end | |||
|
|||
end |