File: guardfile_spec.rb

package info (click to toggle)
ruby-guard 2.18.1-5
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,380 kB
  • sloc: ruby: 9,256; makefile: 6
file content (95 lines) | stat: -rw-r--r-- 2,678 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
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
# frozen_string_literal: true

require "guard/config"

unless Guard::Config.new.strict?

  require "guard/deprecated/guardfile"

  RSpec.describe Guard::Deprecated::Guardfile do
    subject do
      module TestModule; end.tap { |mod| described_class.add_deprecated(mod) }
    end

    let(:generator) { instance_double("Guard::Guardfile::Generator") }

    before do
      allow(Guard::UI).to receive(:deprecation)
    end

    describe ".create_guardfile" do
      before do
        allow(File).to receive(:exist?).with("Guardfile").and_return(false)
        template = Guard::Guardfile::Generator::GUARDFILE_TEMPLATE
        allow(FileUtils).to receive(:cp).with(template, "Guardfile")

        allow(Guard::Guardfile::Generator).to receive(:new)
          .and_return(generator)

        allow(generator).to receive(:create_guardfile)
      end

      it "displays a deprecation warning to the user" do
        expect(Guard::UI).to receive(:deprecation)
          .with(Guard::Deprecated::Guardfile::ClassMethods::CREATE_GUARDFILE)

        subject.create_guardfile
      end

      it "delegates to Guard::Guardfile::Generator" do
        expect(Guard::Guardfile::Generator).to receive(:new)
          .with({ foo: "bar" }) { generator }

        expect(generator).to receive(:create_guardfile)

        subject.create_guardfile(foo: "bar")
      end
    end

    describe ".initialize_template" do
      before do
        expect(Guard::Guardfile::Generator).to receive(:new) do
          generator
        end

        allow(generator).to receive(:initialize_template)
      end

      it "displays a deprecation warning to the user" do
        expect(Guard::UI).to receive(:deprecation)
          .with(Guard::Deprecated::Guardfile::ClassMethods::INITIALIZE_TEMPLATE)

        subject.initialize_template("rspec")
      end

      it "delegates to Guard::Guardfile::Generator" do
        expect(generator).to receive(:initialize_template).with("rspec")

        subject.initialize_template("rspec")
      end
    end

    describe ".initialize_all_templates" do
      before do
        expect(Guard::Guardfile::Generator).to receive(:new) do
          generator
        end

        allow(generator).to receive(:initialize_all_templates)
      end

      it "displays a deprecation warning to the user" do
        expect(Guard::UI).to receive(:deprecation)
          .with(described_class::ClassMethods::INITIALIZE_ALL_TEMPLATES)

        subject.initialize_all_templates
      end

      it "delegates to Guard::Guardfile::Generator" do
        expect(generator).to receive(:initialize_all_templates)

        subject.initialize_all_templates
      end
    end
  end
end