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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
# frozen_string_literal: true
require "guard/cli"
RSpec.describe Guard::CLI do
let(:valid_environment) { instance_double("Guard::Cli::Environments::Valid") }
let(:bare_environment) do
instance_double("Guard::Cli::Environments::EvaluateOnly")
end
let(:dsl_describer) { instance_double("Guard::DslDescriber") }
before do
@options = {}
allow(subject).to receive(:options).and_return(@options)
allow(::Guard::DslDescriber).to receive(:new).with(no_args)
.and_return(dsl_describer)
allow(Guard::Cli::Environments::EvaluateOnly).to receive(:new)
.and_return(bare_environment)
allow(Guard::Cli::Environments::Valid).to receive(:new)
.and_return(valid_environment)
end
describe "#start" do
before do
allow(valid_environment).to receive(:start_guard).and_return(0)
end
it "delegates to Guard::Environment.start" do
pending "needs JRuby support first" if defined?(JRUBY_VERSION)
expect(valid_environment).to receive(:start_guard).and_return(0)
begin
subject.start
rescue SystemExit
end
end
it "exits with given exit code" do
pending "needs JRuby support first" if defined?(JRUBY_VERSION)
allow(valid_environment).to receive(:start_guard).and_return(4)
expect { subject.start }.to raise_error(SystemExit) do |exception|
expect(exception.status).to eq(4)
exception
end
end
it "passes options" do
pending "needs JRuby support first" if defined?(JRUBY_VERSION)
expect(Guard::Cli::Environments::Valid).to receive(:new).with(@options)
.and_return(valid_environment)
begin
subject.start
rescue SystemExit
end
end
end
describe "#list" do
before do
allow(bare_environment).to receive(:evaluate)
allow(dsl_describer).to receive(:list)
subject.list
end
it "calls the evaluation" do
expect(bare_environment).to have_received(:evaluate)
end
it "outputs the Guard plugins list" do
expect(dsl_describer).to have_received(:list)
end
end
describe "#notifiers" do
before do
allow(bare_environment).to receive(:evaluate)
allow(dsl_describer).to receive(:notifiers)
subject.notifiers
end
it "calls the evaluation" do
expect(bare_environment).to have_received(:evaluate)
end
it "outputs the notifiers list" do
expect(dsl_describer).to have_received(:notifiers)
end
end
describe "#version" do
it "shows the current version" do
expect(STDOUT).to receive(:puts).with(/#{ ::Guard::VERSION }/)
subject.version
end
end
describe "#init" do
before do
allow(Guard::Cli::Environments::Valid).to receive(:new)
.and_return(valid_environment)
allow(valid_environment).to receive(:initialize_guardfile).and_return(0)
end
it "delegates to Guard::Environment.start" do
begin
subject.init
rescue SystemExit
end
end
it "exits with given exit code" do
allow(valid_environment).to receive(:initialize_guardfile).and_return(4)
expect { subject.init }.to raise_error(SystemExit) do |exception|
expect(exception.status).to eq(4)
end
end
it "passes options" do
expect(Guard::Cli::Environments::Valid).to receive(:new).with(@options)
.and_return(valid_environment)
begin
subject.init
rescue SystemExit
end
end
it "passes plugin names" do
plugins = [double("plugin1"), double("plugin2")]
expect(valid_environment).to receive(:initialize_guardfile).with(plugins)
begin
subject.init(*plugins)
rescue SystemExit
end
end
end
describe "#show" do
before do
allow(bare_environment).to receive(:evaluate)
allow(dsl_describer).to receive(:show)
subject.show
end
it "calls the evaluation" do
expect(bare_environment).to have_received(:evaluate)
end
it "outputs the Guard::DslDescriber.list result" do
expect(dsl_describer).to have_received(:show)
end
end
end
|