summaryrefslogtreecommitdiff
path: root/spec/plugins/api.rb
blob: 8fd5689227a89da098b7e404c1aa7f81b9c1cc17 (plain)
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
# frozen_string_literal: true
require "spec_helper"

require "bundler/plugin"

describe Bundler::Plugin::Api do
  context "plugin declarations" do
    before do
      stub_const "UserPluginClass", Class.new(Bundler::Plugin::Api)
    end

    it "declares a command plugin with same class as handler" do
      success = false
      allow(Bundler::Plugin).to receive(:add_command).with("meh", UserPluginClass) { success = true }

      UserPluginClass.command "meh"

      expect(success).to be true
    end

    it "accepts another class as argument that handles the command" do
      success = false
      stub_const "NewClass", Class.new
      allow(Bundler::Plugin).to receive(:add_command).with("meh", NewClass) { success = true }

      UserPluginClass.command "meh", NewClass
      expect(success).to be true
    end
  end

  context "bundler interfaces provided" do
    before do
      stub_const "UserPluginClass", Class.new(Bundler::Plugin::Api)
    end

    subject(:api) { UserPluginClass.new }

    # A test of delegation
    it "provides the bundler settings" do
      expect(api.settings).to eq(Bundler.settings)
    end
  end
end