File: dsl_reader_spec.rb

package info (click to toggle)
ruby-guard 2.18.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,344 kB
  • sloc: ruby: 9,256; makefile: 6
file content (60 lines) | stat: -rw-r--r-- 1,620 bytes parent folder | download | duplicates (4)
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
# frozen_string_literal: true

require "guard/dsl_reader"

RSpec.describe Guard::DslReader, exclude_stubs: [Guard::Dsl] do
  methods = %w[
    initialize guard notification interactor group watch callback
    ignore ignore! logger scope directories clearing
  ].map(&:to_sym)

  methods.each do |meth|
    describe "\##{meth} signature" do
      it "matches base signature" do
        expected = Guard::Dsl.instance_method(meth).arity
        expect(subject.method(meth).arity).to eq(expected)
      end
    end
  end

  describe "guard" do
    context "when it is a String" do
      let(:name) { "foo" }
      it "works without errors" do
        expect { subject.guard(name, bar: :baz) }.to_not raise_error
      end

      it "reports the name as a String" do
        subject.guard("foo", bar: :baz)
        expect(subject.plugin_names).to eq(%w[foo])
      end
    end

    context "when it is a Symbol" do
      let(:name) { :foo }
      it "works without errors" do
        expect { subject.guard(name, bar: :baz) }.to_not raise_error
      end

      it "reports the name as a String" do
        subject.guard(name, bar: :baz)
        expect(subject.plugin_names).to eq(%w[foo])
      end
    end
  end

  describe "plugin_names" do
    it "returns encountered names" do
      subject.guard("foo", bar: :baz)
      subject.guard("bar", bar: :baz)
      subject.guard("baz", bar: :baz)
      expect(subject.plugin_names).to eq(%w[foo bar baz])
    end
  end

  describe "notification" do
    it "handles arguments without errors" do
      expect { subject.notification(:off) }.to_not raise_error
    end
  end
end