aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorMarkus Reiter2016-10-09 18:03:15 +0200
committerMarkus Reiter2016-10-15 17:13:38 +0200
commitef70677e881855f1e7b51f158752e1ee78b27a96 (patch)
tree035a38e8cd7940d2621af54df3d26fa404cfbbbd /Library
parent198bf4d3bdeaf3047f9af80788ea18cd192541af (diff)
downloadbrew-ef70677e881855f1e7b51f158752e1ee78b27a96.tar.bz2
Add test for `Formatter.columns`.
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/cask/spec/formatter_spec.rb56
1 files changed, 56 insertions, 0 deletions
diff --git a/Library/Homebrew/cask/spec/formatter_spec.rb b/Library/Homebrew/cask/spec/formatter_spec.rb
new file mode 100644
index 000000000..7e143d933
--- /dev/null
+++ b/Library/Homebrew/cask/spec/formatter_spec.rb
@@ -0,0 +1,56 @@
+require "spec_helper"
+require "utils/formatter"
+require "utils/tty"
+
+describe Formatter do
+ describe "::columns" do
+ let(:input) {
+ [
+ 'aa',
+ 'bbb',
+ 'ccc',
+ 'dd'
+ ]
+ }
+ subject { described_class.columns(input) }
+
+ it "doesn't output columns if $stdout is not a TTY." do
+ allow_any_instance_of(IO).to receive(:tty?).and_return(false)
+ allow(Tty).to receive(:width).and_return(10)
+
+ expect(subject).to eq(
+ "aa\n" \
+ "bbb\n" \
+ "ccc\n" \
+ "dd\n"
+ )
+ end
+
+ describe "$stdout is a TTY" do
+ it "outputs columns" do
+ allow_any_instance_of(IO).to receive(:tty?).and_return(true)
+ allow(Tty).to receive(:width).and_return(10)
+
+ expect(subject).to eq(
+ "aa ccc\n" \
+ "bbb dd\n"
+ )
+ end
+
+ it "outputs only one line if everything fits" do
+ allow_any_instance_of(IO).to receive(:tty?).and_return(true)
+ allow(Tty).to receive(:width).and_return(20)
+
+ expect(subject).to eq(
+ "aa bbb ccc dd\n"
+ )
+ end
+ end
+
+ describe "with empty input" do
+ let(:input) { [] }
+
+ it { is_expected.to eq("\n") }
+ end
+ end
+end