• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

guard / guard / 1455

pending completion
1455

push

travis-ci

e2
Release 2.11.1

5188 of 5439 relevant lines covered (95.39%)

14.69 hits per line

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

98.73
/spec/lib/guard/dsl_spec.rb
1
require "guard/plugin"
5✔
2

3
require "guard/dsl"
5✔
4

5
RSpec.describe Guard::Dsl do
5✔
6

7
  let(:guardfile_evaluator) { instance_double(Guard::Guardfile::Evaluator) }
5✔
8
  let(:interactor) { instance_double(Guard::Interactor) }
144✔
9
  let(:listener) { instance_double("Listen::Listener") }
5✔
10

11
  let(:session) { instance_double("Guard::Internals::Session") }
144✔
12
  let(:plugins) { instance_double("Guard::Internals::Plugins") }
144✔
13
  let(:groups) { instance_double("Guard::Internals::Groups") }
144✔
14
  let(:state) { instance_double("Guard::Internals::State") }
144✔
15
  let(:scope) { instance_double("Guard::Internals::Scope") }
144✔
16

17
  let(:evaluator) do
5✔
18
    Proc.new do |contents|
132 all except jruby and rbx ✔
19
      Guard::Dsl.new.evaluate(contents, "", 1)
132 all except jruby and rbx ✔
20
    end
21
  end
22

23
  before do
5✔
24
    stub_user_guard_rb
139 all except rbx ✔
25
    stub_const "Guard::Foo", instance_double(Guard::Plugin)
139 all except rbx ✔
26
    stub_const "Guard::Bar", instance_double(Guard::Plugin)
139 all except rbx ✔
27
    stub_const "Guard::Baz", instance_double(Guard::Plugin)
139 all except rbx ✔
28
    allow(Guard::Notifier).to receive(:turn_on)
139 all except rbx ✔
29
    allow(Guard::Interactor).to receive(:new).and_return(interactor)
139 all except rbx ✔
30

31
    allow(state).to receive(:scope).and_return(scope)
139 all except rbx ✔
32
    allow(session).to receive(:plugins).and_return(plugins)
139 all except rbx ✔
33
    allow(session).to receive(:groups).and_return(groups)
139 all except rbx ✔
34
    allow(state).to receive(:session).and_return(session)
139 all except rbx ✔
35
    allow(Guard).to receive(:state).and_return(state)
139 all except rbx ✔
36

37
    # For backtrace cleanup
38
    allow(ENV).to receive(:[]).with("GEM_HOME").and_call_original
139 all except rbx ✔
39
    allow(ENV).to receive(:[]).with("GEM_PATH").and_call_original
139 all except rbx ✔
40
  end
41

42
  describe "#ignore" do
5✔
43
    context "with ignore regexps" do
5✔
44
      let(:contents) { "ignore %r{^foo}, /bar/" }
8✔
45

46
      it "adds ignored regexps to the listener" do
5✔
47
        expect(session).to receive(:guardfile_ignore=).with([/^foo/, /bar/])
3 all except jruby and rbx ✔
48
        evaluator.call(contents)
3 all except jruby and rbx ✔
49
      end
50
    end
51

52
    context "with multiple ignore calls" do
5✔
53
      let(:contents) { "ignore(/foo/); ignore(/bar/)" }
8✔
54

55
      it "adds all ignored regexps to the listener" do
5✔
56
        expect(session).to receive(:guardfile_ignore=).with([/foo/]).once
3 all except jruby and rbx ✔
57
        expect(session).to receive(:guardfile_ignore=).with([/bar/]).once
3 all except jruby and rbx ✔
58
        evaluator.call(contents)
3 all except jruby and rbx ✔
59
      end
60
    end
61
  end
62

63
  describe "#ignore!" do
5✔
64
    context "when ignoring only foo* and *bar*" do
5✔
65
      let(:contents) { "ignore! %r{^foo}, /bar/" }
8✔
66

67
      it "replaces listener regexps" do
5✔
68
        expect(session).to receive(:guardfile_ignore_bang=).
3 all except jruby and rbx ✔
69
          with([[/^foo/, /bar/]])
70

71
        evaluator.call(contents)
3 all except jruby and rbx ✔
72
      end
73
    end
74

75
    context "when ignoring *.txt and *.zip and ignoring! only foo*" do
5✔
76
      let(:contents) { "ignore! %r{.txt$}, /.*\\.zip/\n ignore! %r{^foo}" }
8✔
77

78
      it "replaces listener ignores, but keeps ignore! ignores" do
5✔
79
        allow(session).to receive(:guardfile_ignore_bang=).
4 all except rbx ✔
80
          with([[/.txt$/, /.*\.zip/]])
81

82
        expect(session).to receive(:guardfile_ignore_bang=).
3 all except jruby and rbx ✔
83
          with([[/.txt$/, /.*\.zip/], [/^foo/]])
84

85
        evaluator.call(contents)
3 all except jruby and rbx ✔
86
      end
87
    end
88
  end
89

90
  # TODO: remove this hack (after deprecating filter)
91
  def method_for(klass, meth)
5✔
92
    klass.instance_method(meth)
12 all except jruby and rbx ✔
93
  end
94

95
  # TODO: deprecated #filter
96
  describe "#filter alias method" do
5✔
97
    subject { method_for(described_class, :filter) }
8✔
98
    it { is_expected.to eq(method_for(described_class, :ignore)) }
8✔
99
  end
100

101
  # TODO: deprecated #filter
102
  describe "#filter! alias method" do
5✔
103
    subject { method_for(described_class, :filter!) }
8✔
104
    it { is_expected.to eq(method_for(described_class, :ignore!)) }
8✔
105
  end
106

107
  describe "#notification" do
5✔
108
    context "when notification" do
5✔
109
      let(:contents) { "notification :growl" }
8✔
110

111
      it "adds a notification to the notifier" do
5✔
112
        expect(session).to receive(:guardfile_notification=).with(growl: {})
3 all except jruby and rbx ✔
113

114
        evaluator.call(contents)
3 all except jruby and rbx ✔
115
      end
116
    end
117

118
    context "with multiple notifications" do
5✔
119
      let(:contents) do
5✔
120
        "notification :growl\nnotification :ruby_gntp, host: '192.168.1.5'"
3 all except jruby and rbx ✔
121
      end
122

123
      it "adds multiple notifiers" do
5✔
124
        expect(session).to receive(:guardfile_notification=).with(growl: {})
3 all except jruby and rbx ✔
125
        expect(session).to receive(:guardfile_notification=).with(
3 all except jruby and rbx ✔
126
          ruby_gntp:  { host: "192.168.1.5" }
127
        )
128

129
        evaluator.call(contents)
3 all except jruby and rbx ✔
130
      end
131
    end
132
  end
133

134
  describe "#interactor" do
5✔
135
    context "with interactor :off" do
5✔
136
      let(:contents) { "interactor :off" }
8✔
137
      it "disables the interactions with :off" do
5✔
138
        expect(Guard::Interactor).to receive(:enabled=).with(false)
3 all except jruby and rbx ✔
139
        evaluator.call(contents)
3 all except jruby and rbx ✔
140
      end
141
    end
142

143
    context "with interactor options" do
5✔
144
      let(:contents) { 'interactor option1: \'a\', option2: 123' }
8✔
145
      it "passes the options to the interactor" do
5✔
146
        expect(Guard::Interactor).to receive(:options=).
3 all except jruby and rbx ✔
147
          with(option1: "a", option2: 123)
148

149
        evaluator.call(contents)
3 all except jruby and rbx ✔
150
      end
151
    end
152
  end
153

154
  describe "#group" do
5✔
155
    context "no plugins in group" do
5✔
156
      let(:contents) { "group :w" }
8✔
157

158
      it "displays an error" do
5✔
159
        expect(::Guard::UI).to receive(:error).
3 all except jruby and rbx ✔
160
          with("No Guard plugins found in the group 'w',"\
161
               " please add at least one.")
162

163
        evaluator.call(contents)
3 all except jruby and rbx ✔
164
      end
165
    end
166

167
    context "group named :all" do
5✔
168
      let(:contents) { "group :all" }
8✔
169

170
      it "raises an error" do
5✔
171
        expect { evaluator.call(contents) }.
6 all except jruby and rbx ✔
172
          to raise_error(
173
            Guard::Dsl::Error,
174
            /'all' is not an allowed group name!/)
175
      end
176
    end
177

178
    context 'group named "all"' do
5✔
179
      let(:contents) { "group 'all'" }
8✔
180

181
      it "raises an error" do
5✔
182
        expect { evaluator.call(contents) }.
6 all except jruby and rbx ✔
183
          to raise_error(
184
            Guard::Dsl::Error,
185
            /'all' is not an allowed group name!/)
186
      end
187
    end
188

189
    context "with a valid guardfile" do
5✔
190
      let(:contents) { valid_guardfile_string }
8✔
191

192
      it "evaluates all groups" do
5✔
193
        expect(groups).to receive(:add).with(:w, {})
3 all except jruby and rbx ✔
194
        expect(groups).to receive(:add).with(:y, {})
3 all except jruby and rbx ✔
195
        expect(groups).to receive(:add).with(:x, halt_on_fail: true)
3 all except jruby and rbx ✔
196

197
        expect(plugins).to receive(:add).
3 all except jruby and rbx ✔
198
          with(:pow, watchers: [], callbacks: [], group: :default)
199

200
        expect(plugins).to receive(:add).
3 all except jruby and rbx ✔
201
          with(:test, watchers: [], callbacks: [], group: :w)
202

203
        expect(plugins).to receive(:add).
3 all except jruby and rbx ✔
204
          with(:rspec, watchers: [], callbacks: [], group: :x).twice
205

206
        expect(plugins).to receive(:add).
3 all except jruby and rbx ✔
207
          with(:less, watchers: [], callbacks: [], group: :y)
208

209
        expect(session).to receive(:guardfile_notification=).with(growl: {})
3 all except jruby and rbx ✔
210
        evaluator.call(contents)
3 all except jruby and rbx ✔
211
      end
212
    end
213

214
    context "with multiple names" do
5✔
215
      let(:contents) { "group :foo, :bar do; end" }
8✔
216
      it "adds all given groups" do
5✔
217
        expect(groups).to receive(:add).with(:foo, {})
3 all except jruby and rbx ✔
218
        expect(groups).to receive(:add).with(:bar, {})
3 all except jruby and rbx ✔
219

220
        evaluator.call(contents)
3 all except jruby and rbx ✔
221
      end
222
    end
223
  end
224

225
  describe "#guard" do
5✔
226
    context "with single-quoted name" do
5✔
227
      let(:contents) { 'guard \'test\'' }
8✔
228

229
      it "loads a guard specified as a quoted string from the DSL" do
5✔
230
        expect(plugins).to receive(:add).
3 all except jruby and rbx ✔
231
          with("test",  watchers: [], callbacks: [], group: :default)
232

233
        evaluator.call(contents)
3 all except jruby and rbx ✔
234
      end
235
    end
236

237
    context "with double-quoted name" do
5✔
238
      let(:contents) { 'guard "test"' }
8✔
239

240
      it "loads a guard specified as a double quoted string from the DSL" do
5✔
241
        expect(plugins).to receive(:add).
3 all except jruby and rbx ✔
242
          with("test",  watchers: [], callbacks: [], group: :default)
243

244
        evaluator.call(contents)
3 all except jruby and rbx ✔
245
      end
246
    end
247

248
    context "with symbol for name" do
5✔
249
      let(:contents) { "guard :test" }
8✔
250

251
      it "loads a guard specified as a symbol from the DSL" do
5✔
252
        expect(plugins).to receive(:add).
3 all except jruby and rbx ✔
253
          with(:test,  watchers: [], callbacks: [], group: :default)
254

255
        evaluator.call(contents)
3 all except jruby and rbx ✔
256
      end
257
    end
258

259
    context "with name as symbol in parens" do
5✔
260
      let(:contents) { "guard(:test)" }
8✔
261

262
      it "adds the plugin" do
5✔
263
        expect(plugins).to receive(:add).
3 all except jruby and rbx ✔
264
          with(:test,  watchers: [], callbacks: [], group: :default)
265
        evaluator.call(contents)
3 all except jruby and rbx ✔
266
      end
267
    end
268

269
    context "with options" do
5✔
270
      let(:contents) { 'guard \'test\', opt_a: 1, opt_b: \'fancy\'' }
8✔
271

272
      it "passes options to plugin" do
5✔
273
        options = {
3 all except jruby and rbx ✔
274
          watchers: [],
275
          callbacks: [],
276
          opt_a: 1,
277
          opt_b: "fancy",
278
          group: :default
279
        }
280

281
        expect(plugins).to receive(:add).with("test",  options)
3 all except jruby and rbx ✔
282
        evaluator.call(contents)
3 all except jruby and rbx ✔
283
      end
284
    end
285

286
    context "with groups" do
5✔
287
      let(:contents) { "group :foo do; group :bar do; guard :test; end; end" }
8✔
288

289
      it "adds plugin with group info" do
5✔
290
        expect(groups).to receive(:add).with(:foo, {})
3 all except jruby and rbx ✔
291
        expect(groups).to receive(:add).with(:bar, {})
3 all except jruby and rbx ✔
292
        expect(plugins).to receive(:add).
3 all except jruby and rbx ✔
293
          with(:test,  watchers: [], callbacks: [], group: :bar)
294

295
        evaluator.call(contents)
3 all except jruby and rbx ✔
296
      end
297
    end
298

299
    context "with plugins in custom and default groups" do
5✔
300
      let(:contents) do
5✔
301
        "group :foo do; group :bar do; guard :test; end; end; guard :rspec"
3 all except jruby and rbx ✔
302
      end
303

304
      it "assigns plugins to correct groups" do
5✔
305
        expect(groups).to receive(:add).with(:foo, {})
3 all except jruby and rbx ✔
306
        expect(groups).to receive(:add).with(:bar, {})
3 all except jruby and rbx ✔
307

308
        expect(plugins).to receive(:add).
3 all except jruby and rbx ✔
309
          with(:test,  watchers: [], callbacks: [], group: :bar)
310

311
        expect(plugins).to receive(:add).
3 all except jruby and rbx ✔
312
          with(:rspec,  watchers: [], callbacks: [], group: :default)
313

314
        evaluator.call(contents)
3 all except jruby and rbx ✔
315
      end
316
    end
317
  end
318

319
  describe "#watch" do
5✔
320
    # TODO: this is testing too much
321
    context "with watchers" do
5✔
322
      let(:watcher_a) do
5✔
323
        instance_double("Guard::Watcher", pattern: "a", action: proc { "b" })
6 all except jruby and rbx ✔
324
      end
325

326
      let(:watcher_c) do
5✔
327
        instance_double("Guard::Watcher", pattern: "c", action: nil)
3 all except jruby and rbx ✔
328
      end
329

330
      let(:contents) do
5✔
331
        '
×
332
        guard :dummy do
333
           watch(\'a\') { \'b\' }
334
           watch(\'c\')
335
        end'
3 all except jruby and rbx ✔
336
      end
337

338
      it "should receive watchers when specified" do
5✔
339
        call_params = {
3 all except jruby and rbx ✔
340
          watchers: [anything, anything],
341
          callbacks: [],
342
          group: :default
343
        }
344

345
        expect(plugins).to receive(:add).
3 all except jruby and rbx ✔
346
          with(:dummy, call_params) do |_, options|
347
          expect(options[:watchers].size).to eq 2
3 all except jruby and rbx ✔
348
          expect(options[:watchers][0].pattern).to eq "a"
3 all except jruby and rbx ✔
349
          expect(options[:watchers][0].action.call).to eq proc { "b" }.call
6 all except jruby and rbx ✔
350
          expect(options[:watchers][1].pattern).to eq "c"
3 all except jruby and rbx ✔
351
          expect(options[:watchers][1].action).to be_nil
3 all except jruby and rbx ✔
352
        end
353

354
        allow(Guard::Watcher).to receive(:new).with("a", anything).
3 all except jruby and rbx ✔
355
          and_return(watcher_a)
356

357
        allow(Guard::Watcher).to receive(:new).with("c", nil).
3 all except jruby and rbx ✔
358
          and_return(watcher_c)
359

360
        evaluator.call(contents)
3 all except jruby and rbx ✔
361
      end
362
    end
363

364
    context "with watch in main scope" do
5✔
365
      let(:contents) { 'watch(\'a\')' }
8✔
366
      let(:watcher) do
5✔
367
        instance_double("Guard::Watcher", pattern: "a", action: nil)
3 all except jruby and rbx ✔
368
      end
369

370
      it "should create an implicit no-op guard when outside a guard block" do
5✔
371
        plugin_options = {
3 all except jruby and rbx ✔
372
          watchers: [anything],
373
          callbacks: [],
374
          group: :default
375
        }
376

377
        expect(plugins).to receive(:add).
3 all except jruby and rbx ✔
378
          with(:plugin, plugin_options) do |_, options|
379

380
          expect(options[:watchers].size).to eq 1
3 all except jruby and rbx ✔
381
          expect(options[:watchers][0].pattern).to eq "a"
3 all except jruby and rbx ✔
382
          expect(options[:watchers][0].action).to be_nil
3 all except jruby and rbx ✔
383
        end
384

385
        allow(Guard::Watcher).to receive(:new).with("a", nil).
3 all except jruby and rbx ✔
386
          and_return(watcher)
387

388
        evaluator.call(contents)
3 all except jruby and rbx ✔
389
      end
390
    end
391
  end
392

393
  describe "#callback" do
5✔
394
    context "with " do
5✔
395
      let(:contents) do
5✔
396
        '
×
397
        guard :rspec do
398

399
          callback(:start_end) do |plugin, event, args|
400
            "#{plugin.title} executed \'#{event}\' hook with #{args}!"
401
          end
402

403
          callback(MyCustomCallback, [:start_begin, :run_all_begin])
404
        end'
3 all except jruby and rbx ✔
405
      end
406

407
      it "creates callbacks for the guard" do
5✔
408
        class MyCustomCallback
3 all except jruby and rbx ✔
409
          def self.call(_plugin, _event, _args)
3 all except jruby and rbx ✔
410
            # do nothing
411
          end
412
        end
413

414
        params = {
3 all except jruby and rbx ✔
415
          watchers: [],
416
          callbacks: [anything, anything],
417
          group: :default
418
        }
419

420
        expect(plugins).to receive(:add).with(:rspec, params) do |_, opt|
3 all except jruby and rbx ✔
421
          # TODO: this whole block is too verbose, tests too many things at
422
          # once and needs refactoring
423

424
          expect(opt[:callbacks].size).to eq 2
3 all except jruby and rbx ✔
425

426
          callback_0 = opt[:callbacks][0]
3 all except jruby and rbx ✔
427

428
          expect(callback_0[:events]).to eq :start_end
3 all except jruby and rbx ✔
429

430
          plugin = instance_double("Guard::Plugin", title: "RSpec")
3 all except jruby and rbx ✔
431
          result = callback_0[:listener].call(plugin, :start_end, "foo")
3 all except jruby and rbx ✔
432

433
          expect(result).to eq 'RSpec executed \'start_end\' hook'\
3 all except jruby and rbx ✔
434
            " with foo!"
435

436
          callback_1 = opt[:callbacks][1]
3 all except jruby and rbx ✔
437
          expect(callback_1[:events]).to eq [:start_begin, :run_all_begin]
3 all except jruby and rbx ✔
438
          expect(callback_1[:listener]).to eq MyCustomCallback
3 all except jruby and rbx ✔
439
        end
440

441
        evaluator.call(contents)
3 all except jruby and rbx ✔
442
      end
443
    end
444

445
    context "without a guard block" do
5✔
446
      let(:contents) do
5✔
447
        '
×
448
        callback(:start_end) do |plugin, event, args|
449
          "#{plugin} executed \'#{event}\' hook with #{args}!"
450
        end
451

452
        callback(MyCustomCallback, [:start_begin, :run_all_begin])'
3 all except jruby and rbx ✔
453
      end
454

455
      it "fails" do
5✔
456
        expect { evaluator.call(contents) }.to raise_error(/guard block/i)
6 all except jruby and rbx ✔
457
      end
458
    end
459
  end
460

461
  describe "#logger" do
5✔
462
    after do
5✔
463
      Guard::UI.options = {
42 all except jruby and rbx ✔
464
        level: :info,
465
        template: ":time - :severity - :message",
466
        time_format: "%H:%M:%S"
467
      }
468
    end
469

470
    describe "options" do
5✔
471
      let(:contents) { "" }
5✔
472

473
      before do
5✔
474
        evaluator.call(contents)
30 all except jruby and rbx ✔
475
      end
476

477
      subject { Guard::UI.options }
35✔
478

479
      context "with logger level :errror" do
5✔
480
        let(:contents) { "logger level: :error" }
8✔
481
        it { is_expected.to include("level" => :error) }
8✔
482
      end
483

484
      context "with logger level 'errror'" do
5✔
485
        let(:contents) { 'logger level: \'error\'' }
8✔
486
        it { is_expected.to include("level" => :error) }
8✔
487
      end
488

489
      context "with logger template" do
5✔
490
        let(:contents) { 'logger template: \':message - :severity\'' }
8✔
491
        it { is_expected.to include("template" => ":message - :severity") }
8✔
492
      end
493

494
      context "with a logger time format" do
5✔
495
        let(:contents) { 'logger time_format: \'%Y\'' }
8✔
496
        it { is_expected.to include("time_format" => "%Y") }
8✔
497
      end
498

499
      context "with a logger only filter from a symbol" do
5✔
500
        let(:contents) { "logger only: :cucumber" }
8✔
501
        it { is_expected.to include("only" => /cucumber/i) }
8✔
502
      end
503

504
      context "with logger only filter from a string" do
5✔
505
        let(:contents) { 'logger only: \'jasmine\'' }
8✔
506
        it { is_expected.to include("only" => /jasmine/i) }
8✔
507
      end
508

509
      context "with logger only filter from an array of symbols and string" do
5✔
510
        let(:contents) { 'logger only: [:rspec, \'cucumber\']' }
8✔
511
        it { is_expected.to include("only" => /rspec|cucumber/i) }
8✔
512
      end
513

514
      context "with logger except filter from a symbol" do
5✔
515
        let(:contents) { "logger except: :jasmine" }
8✔
516
        it { is_expected.to include("except" => /jasmine/i) }
8✔
517
      end
518

519
      context "with logger except filter from a string" do
5✔
520
        let(:contents) { 'logger except: \'jasmine\'' }
8✔
521
        it { is_expected.to include("except" => /jasmine/i) }
8✔
522
      end
523

524
      context "with logger except filter from array of symbols and string" do
5✔
525
        let(:contents) { 'logger except: [:rspec, \'cucumber\', :jasmine]' }
8✔
526
        it { is_expected.to include("except" => /rspec|cucumber|jasmine/i) }
8✔
527
      end
528
    end
529

530
    context "with invalid options" do
5✔
531
      context "for the log level" do
5✔
532
        let(:contents) { "logger level: :baz" }
11✔
533

534
        it "shows a warning" do
5✔
535
          expect(Guard::UI).to receive(:warning).
3 all except jruby and rbx ✔
536
            with "Invalid log level `baz` ignored."\
537
            " Please use either :debug, :info, :warn or :error."
538

539
          evaluator.call(contents)
3 all except jruby and rbx ✔
540
        end
541

542
        it "does not set the invalid value" do
5✔
543
          evaluator.call(contents)
3 all except jruby and rbx ✔
544
          expect(Guard::UI.options).to include("level" => :info)
3 all except jruby and rbx ✔
545
        end
546
      end
547

548
      context "when having both the :only and :except options" do
5✔
549
        let(:contents) { "logger only: :jasmine, except: :rspec" }
11✔
550

551
        it "shows a warning" do
5✔
552
          expect(Guard::UI).to receive(:warning).
3 all except jruby and rbx ✔
553
            with "You cannot specify the logger options"\
554
            " :only and :except at the same time."
555
          evaluator.call(contents)
3 all except jruby and rbx ✔
556
        end
557

558
        it "removes the options" do
5✔
559
          evaluator.call(contents)
3 all except jruby and rbx ✔
560
          expect(Guard::UI.options[:only]).to be_nil
3 all except jruby and rbx ✔
561
          expect(Guard::UI.options[:except]).to be_nil
3 all except jruby and rbx ✔
562
        end
563
      end
564

565
    end
566
  end
567

568
  describe "#scope" do
5✔
569
    context "with any parameters" do
5✔
570
      let(:contents) { "scope plugins: [:foo, :bar]" }
8✔
571

572
      it "sets the guardfile's default scope" do
5✔
573
        expect(session).to receive(:guardfile_scope).with(plugins: [:foo, :bar])
3 all except jruby and rbx ✔
574
        evaluator.call(contents)
3 all except jruby and rbx ✔
575
      end
576
    end
577
  end
578

579
  describe "#directories" do
5✔
580
    context "with valid directories" do
5✔
581
      let(:contents) { "directories %w(foo bar)" }
8✔
582
      before do
5✔
583
        allow(Dir).to receive(:exist?).with("foo").and_return(true)
3 all except jruby and rbx ✔
584
        allow(Dir).to receive(:exist?).with("bar").and_return(true)
3 all except jruby and rbx ✔
585
      end
586

587
      it "sets the watchdirs to given values" do
5✔
588
        expect(session).to receive(:watchdirs=).with(%w(foo bar))
3 all except jruby and rbx ✔
589
        evaluator.call(contents)
3 all except jruby and rbx ✔
590
      end
591
    end
592

593
    context "with no parameters" do
5✔
594
      let(:contents) { "directories []" }
8✔
595

596
      it "sets the watchdirs to empty" do
5✔
597
        expect(session).to receive(:watchdirs=).with([])
3 all except jruby and rbx ✔
598
        evaluator.call(contents)
3 all except jruby and rbx ✔
599
      end
600
    end
601

602
    context "with non-existing directory" do
5✔
603
      let(:contents) { "directories ['foo']" }
8✔
604

605
      before do
5✔
606
        allow(Dir).to receive(:exist?).with("foo").and_return(false)
3 all except jruby and rbx ✔
607
      end
608

609
      it "fails with an error" do
5✔
610
        expect(session).to_not receive(:watchdirs=)
3 all except jruby and rbx ✔
611
        expect do
3 all except jruby and rbx ✔
612
          evaluator.call(contents)
3 all except jruby and rbx ✔
613
        end.to raise_error(Guard::Dsl::Error, /Directory "foo" does not exist!/)
614
      end
615
    end
616
  end
617

618
  describe "#clear" do
5✔
619
    context "with clear :off" do
5✔
620
      let(:contents) { "clearing :off" }
8✔
621
      it "disables clearing the screen after every task" do
5✔
622
        expect(session).to receive(:clearing).with(false)
3 all except jruby and rbx ✔
623
        evaluator.call(contents)
3 all except jruby and rbx ✔
624
      end
625
    end
626

627
    context "with clear :on" do
5✔
628
      let(:contents) { "clearing :on" }
8✔
629
      it "enabled clearing the screen after every task" do
5✔
630
        expect(session).to receive(:clearing).with(true)
3 all except jruby and rbx ✔
631
        evaluator.call(contents)
3 all except jruby and rbx ✔
632
      end
633
    end
634
  end
635

636
  private
5✔
637

638
  def valid_guardfile_string
5✔
639
    '
×
640
    notification :growl
641

642
    guard :pow
643

644
    group :w do
645
      guard :test
646
    end
647

648
    group :x, halt_on_fail: true do
649
      guard :rspec
650
      guard :rspec
651
    end
652

653
    group :y do
654
      guard :less
655
    end
656
    '
3 all except jruby and rbx ✔
657
  end
658
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2023 Coveralls, Inc