Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Sign In

guard / guard / 1459

12 Jan 2015 - 17:05 coverage decreased (-0.2%) to 95.448%
1459

Pull #724

travis-ci

4658fff974e40b29dae3a63001c30f70?size=18&default=identicontrayo
Fixed a typo
Pull Request #724: Fixed a typo

5200 of 5448 relevant lines covered (95.45%)

14.2 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.52
/spec/lib/guard/guardfile/evaluator_spec.rb
1
require "guard/guardfile/evaluator"
5×
2

3
# TODO: shouldn't be necessary
4
require "guard"
5×
5

6
RSpec.describe Guard::Guardfile::Evaluator do
5×
7
  let(:options) { {} }
11×
8
  subject { described_class.new(options) }
29×
9

10
  let!(:local_guardfile) { (Pathname.pwd + "Guardfile").to_s }
47×
11
  let!(:home_guardfile) { (Pathname("~").expand_path + ".Guardfile").to_s }
47×
12
  let!(:home_config) { (Pathname("~").expand_path + ".guard.rb").to_s }
47×
13

14
  let(:valid_guardfile_string) { "group :foo; do guard :bar; end; end; " }
5×
15

16
  let(:dsl) { instance_double("Guard::Dsl") }
47×
17

18
  let(:rel_guardfile) do
5×
19
    Pathname("../relative_path_to_Guardfile").expand_path.to_s
!
20
  end
21

22
  before do
5×
23
    allow(Guard::Interactor).to receive(:new).with(false)
all except jruby and rbx - 42×
24
    allow(Guard::Dsl).to receive(:new).and_return(dsl)
all except jruby and rbx - 42×
25
    allow(dsl).to receive(:instance_eval)
all except jruby and rbx - 42×
26
  end
27

28
  describe ".evaluate" do
5×
29
    describe "error cases" do
5×
30
      context "with an invalid Guardfile" do
5×
31
        let(:options) { { contents: "guard :foo Bad Guardfile" } }
8×
32

33
        it "displays an error message and raises original exception" do
5×
34
          stub_user_guard_rb
all except jruby and rbx - 3×
35

36
          allow(dsl).to receive(:evaluate).
all except jruby and rbx - 3×
37
            and_raise(Guard::Dsl::Error,
38
                      "Invalid Guardfile, original error is:")
39

40
          expect { subject.evaluate }.to raise_error(Guard::Dsl::Error)
all except jruby and rbx - 6×
41
        end
42
      end
43

44
      context "with no Guardfile at all" do
5×
45
        it "displays an error message and exits" do
5×
46
          stub_guardfile
all except jruby and rbx - 3×
47
          stub_user_guardfile
all except jruby and rbx - 3×
48
          stub_user_project_guardfile
all except jruby and rbx - 3×
49

50
          expect { subject.evaluate }.
all except jruby and rbx - 6×
51
            to raise_error(Guard::Guardfile::Evaluator::NoGuardfileError)
52
        end
53
      end
54

55
      context "with a problem reading a Guardfile" do
5×
56
        let(:path) { File.expand_path("Guardfile") }
5×
57

58
        before do
5×
59
          stub_user_project_guardfile
all except jruby and rbx - 3×
60
          stub_guardfile(" ") do
all except jruby and rbx - 3×
61
            fail Errno::EACCES.new("permission error")
all except jruby and rbx - 3×
62
          end
63
        end
64

65
        it "displays an error message and exits" do
5×
66
          expect(Guard::UI).to receive(:error).with(/^Error reading file/)
all except jruby and rbx - 3×
67
          expect { subject.evaluate }.to raise_error(SystemExit)
all except jruby and rbx - 6×
68
        end
69
      end
70

71
      context "with empty Guardfile content" do
5×
72
        let(:options) { { contents: "" } }
8×
73

74
        it "displays an error message about no plugins" do
5×
75
          stub_user_guard_rb
all except jruby and rbx - 3×
76
          stub_guardfile(" ")
all except jruby and rbx - 3×
77
          allow(dsl).to receive(:evaluate).with("", "", 1)
all except jruby and rbx - 3×
78

79
          expect { subject.evaluate }.
all except jruby and rbx - 6×
80
            to raise_error(Guard::Guardfile::Evaluator::NoPluginsError)
81
        end
82
      end
83

84
      context "when provided :contents is nil" do
5×
85
        before do
5×
86
          # Anything
87
          stub_guardfile("guard :foo")
all except jruby and rbx - 3×
88

89
          stub_user_guard_rb
all except jruby and rbx - 3×
90
          stub_user_project_guardfile
all except jruby and rbx - 3×
91
          stub_user_guardfile
all except jruby and rbx - 3×
92
        end
93

94
        it "does not raise error and skip it" do
5×
95
          allow(dsl).to receive(:evaluate).with("guard :foo", anything, 1)
all except jruby and rbx - 3×
96

97
          expect(Guard::UI).to_not receive(:error)
all except jruby and rbx - 3×
98
          expect do
all except jruby and rbx - 3×
99
            described_class.new(contents: nil).evaluate
all except jruby and rbx - 3×
100
          end.to_not raise_error
101
        end
102
      end
103

104
      context "with a non-existing Guardfile given" do
5×
105
        let(:non_existing_path) { "/non/existing/path/to/Guardfile" }
8×
106
        let(:options) { { guardfile: non_existing_path } }
8×
107

108
        before do
5×
109
          stub_file(non_existing_path)
all except jruby and rbx - 3×
110
        end
111

112
        it "raises error" do
5×
113
          expect { subject.evaluate }.
all except jruby and rbx - 6×
114
            to raise_error(Guard::Guardfile::Evaluator::NoCustomGuardfile)
115
        end
116
      end
117
    end
118

119
    describe "selection of the Guardfile data contents" do
5×
120

121
      context "with a valid :contents option" do
5×
122
        before do
5×
123
          stub_user_guard_rb
all except jruby and rbx - 3×
124
          allow(dsl).to receive(:evaluate)
all except jruby and rbx - 3×
125
        end
126

127
        context "with inline content and other Guardfiles available" do
5×
128
          let(:inline_code) { "guard :foo" }
8×
129
          let(:options) do
5×
UNCOV
130
            {
!
131
              contents: inline_code,
132
              guardfile: "/abc/Guardfile"
133
            }
all except jruby and rbx - 3×
134
          end
135

136
          before do
5×
137
            stub_file("/abc/Guardfile", "guard :bar")
all except jruby and rbx - 3×
138
            stub_guardfile("guard :baz")
all except jruby and rbx - 3×
139
            stub_user_guardfile("guard :buz")
all except jruby and rbx - 3×
140
          end
141

142
          it "gives ultimate precedence to inline content" do
5×
143
            expect(dsl).to receive(:evaluate).with(inline_code, "", 1)
all except jruby and rbx - 3×
144
            subject.evaluate
all except jruby and rbx - 3×
145
          end
146
        end
147
      end
148

149
      context "with the :guardfile option" do
5×
150
        let(:options) { { guardfile: "../relative_path_to_Guardfile" } }
5×
151

152
        before do
5×
153
          stub_file(File.expand_path("../relative_path_to_Guardfile"),
!
154
                    valid_guardfile_string)
155
          allow(dsl).to receive(:evaluate).
!
156
            with(valid_guardfile_string, anything, 1)
157
        end
158
      end
159
    end
160
  end
161

162
  describe "#inline?" do
5×
163
    before do
5×
164
      allow(dsl).to receive(:evaluate)
all except jruby and rbx - 6×
165
      stub_guardfile("guard :bar")
all except jruby and rbx - 6×
166
      stub_user_guard_rb
all except jruby and rbx - 6×
167
      subject.evaluate
all except jruby and rbx - 6×
168
    end
169

170
    context "when content is provided" do
5×
171
      let(:options) { { guardfile_contents: "guard :foo" } }
8×
172
      it { is_expected.to be_inline }
8×
173
    end
174

175
    context "when no content is provided" do
5×
176
      let(:options) { {} }
8×
177
      it { is_expected.to_not be_inline }
8×
178
    end
179
  end
180

181
  describe ".guardfile_include?" do
5×
182
    subject do
5×
183
      evaluator = described_class.new(options)
all except jruby and rbx - 15×
184
      evaluator.evaluate
all except jruby and rbx - 15×
185
      evaluator.guardfile_include?("test")
all except jruby and rbx - 15×
186
    end
187

188
    before do
5×
189
      allow(dsl).to receive(:evaluate)
all except jruby and rbx - 15×
190
      stub_user_guard_rb
all except jruby and rbx - 15×
191
    end
192

193
    context "with a double quoted string" do
5×
194
      let(:options) { { contents: 'guard "test" {watch("c")}' } }
8×
195
      it { is_expected.to be_truthy }
8×
196
    end
197

198
    context "with a single quoted string" do
5×
199
      let(:options) { { contents: 'guard \'test\' {watch("c")}' } }
8×
200
      it { is_expected.to be_truthy }
8×
201
    end
202

203
    context "with a symbol" do
5×
204
      let(:options) { { contents: 'guard :test {watch("c")}' } }
8×
205
      it { is_expected.to be_truthy }
8×
206
    end
207

208
    context "with parentheses" do
5×
209
      let(:options) { { contents: 'guard("test") {watch("c")}' } }
8×
210
      it { is_expected.to be_truthy }
8×
211
    end
212

213
    context "when in group and with preceding space" do
5×
214
      let(:content) { "group :foo do\n  guard :test do\n end\nend\n" }
8×
215
      let(:options) { { contents: content } }
8×
216
      it { is_expected.to be_truthy }
8×
217
    end
218
  end
219
end
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
BLOG · TWITTER · Legal & Privacy · Supported CI Services · What's a CI service? · Automated Testing

© 2022 Coveralls, Inc