File: identity_spec.rb

package info (click to toggle)
ruby-fog-core 2.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 676 kB
  • sloc: ruby: 4,719; makefile: 5
file content (95 lines) | stat: -rw-r--r-- 2,284 bytes parent folder | download | duplicates (2)
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
require "spec_helper"

module Fog
  module Identity
    def self.require(*_args); end
  end
end

describe "Fog::Identity" do
  describe "#new" do
    module Fog
      module TheRightWay
        class Identity
          def initialize(_args); end
        end
      end
    end

    module Fog
      module TheRightWay
        extend Provider
        service(:identity, "Identity")
      end
    end

    it "instantiates an instance of Fog::Identity::<Provider> from the :provider keyword arg" do
      identity = Fog::Identity.new(:provider => :therightway)
      assert_instance_of(Fog::TheRightWay::Identity, identity)
    end

    module Fog
      module Identity
        class TheWrongWay
          def initialize(_args); end
        end
      end
    end

    module Fog
      module TheWrongWay
        extend Provider
        service(:identity, "Identity")
      end
    end

    it "instantiates an instance of Fog::<Provider>::Identity from the :provider keyword arg" do
      identity = Fog::Identity.new(:provider => :thewrongway)
      assert_instance_of(Fog::Identity::TheWrongWay, identity)
    end

    module Fog
      module BothWays
        class Identity
          attr_reader :args
          def initialize(args)
            @args = args
          end
        end
      end
    end

    module Fog
      module Identity
        class BothWays
          def initialize(_args); end
        end
      end
    end

    module Fog
      module BothWays
        extend Provider
        service(:identity, "Identity")
      end
    end

    describe "when both Fog::Identity::<Provider> and Fog::<Provider>::Identity exist" do
      it "prefers Fog::Identity::<Provider>" do
        identity = Fog::Identity.new(:provider => :bothways)
        assert_instance_of(Fog::BothWays::Identity, identity)
      end
    end

    it "passes the supplied keyword args less :provider to Fog::Identity::<Provider>#new" do
      identity = Fog::Identity.new(:provider => :bothways, :extra => :stuff)
      assert_equal({ :extra => :stuff }, identity.args)
    end

    it "raises ArgumentError when given a :provider where a Fog::Identity::Provider that does not exist" do
      assert_raises(ArgumentError) do
        Fog::Identity.new(:provider => :wat)
      end
    end
  end
end