Skip to content

Commit

Permalink
Start transitioning some of the features to cli specs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jay Feldblum committed Aug 25, 2012
1 parent aae5f5b commit 7e884a8
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 22 deletions.
11 changes: 0 additions & 11 deletions features/chef/cli/init.feature

This file was deleted.

11 changes: 0 additions & 11 deletions features/chef/cli/version.feature

This file was deleted.

36 changes: 36 additions & 0 deletions spec/functional/chef/cli_spec.rb
@@ -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
55 changes: 55 additions & 0 deletions spec/support/cli_macro.rb
@@ -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

0 comments on commit 7e884a8

Please sign in to comment.