Skip to content
Browse files

Start transitioning some of the features to cli specs.

  • Loading branch information...
1 parent aae5f5b commit 7e884a87fc36ea69f285b498b4acf5b33eb7899c @yfeldblum yfeldblum committed
Showing with 91 additions and 22 deletions.
  1. +0 −11 features/chef/cli/init.feature
  2. +0 −11 features/chef/cli/version.feature
  3. +36 −0 spec/functional/chef/cli_spec.rb
  4. +55 −0 spec/support/cli_macro.rb
View
11 features/chef/cli/init.feature
@@ -1,11 +0,0 @@
-Feature: cli/init
-
-
-
- Scenario: Initing a directory
- When I run `librarian-chef init`
- Then the exit status should be 0
- Then a file named "Cheffile" should exist
-
-
-
View
11 features/chef/cli/version.feature
@@ -1,11 +0,0 @@
-Feature: cli/version
-
-
-
- Scenario: Getting the version
- When I run `librarian-chef version`
- Then the exit status should be 0
- And the output should contain "librarian-"
-
-
-
View
36 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
View
55 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.
Something went wrong with that request. Please try again.