File: shell_spec.rb

package info (click to toggle)
ruby-thor 0.19.1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 792 kB
  • ctags: 564
  • sloc: ruby: 7,315; makefile: 2; sh: 1
file content (47 lines) | stat: -rw-r--r-- 1,250 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require "helper"

describe Thor::Shell do
  def shell
    @shell ||= Thor::Base.shell.new
  end

  describe "#initialize" do
    it "sets shell value" do
      base = MyCounter.new [1, 2], {}, :shell => shell
      expect(base.shell).to eq(shell)
    end

    it "sets the base value on the shell if an accessor is available" do
      base = MyCounter.new [1, 2], {}, :shell => shell
      expect(shell.base).to eq(base)
    end
  end

  describe "#shell" do
    it "returns the shell in use" do
      expect(MyCounter.new([1, 2]).shell).to be_kind_of(Thor::Base.shell)
    end

    it "uses $THOR_SHELL" do
      class Thor::Shell::TestShell < Thor::Shell::Basic; end

      expect(Thor::Base.shell).to eq(shell.class)
      ENV["THOR_SHELL"] = "TestShell"
      Thor::Base.shell = nil
      expect(Thor::Base.shell).to eq(Thor::Shell::TestShell)
      ENV["THOR_SHELL"] = ""
      Thor::Base.shell = shell.class
      expect(Thor::Base.shell).to eq(shell.class)
    end
  end

  describe "with_padding" do
    it "uses padding for inside block outputs" do
      base = MyCounter.new([1, 2])
      base.with_padding do
        expect(capture(:stdout) { base.say_status :padding, "cool" }.strip).to eq("padding    cool")
      end
    end
  end

end