File: compute_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,249 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 Compute
    def self.require(*_args); end
  end
end

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

    module Fog
      module TheRightWay
        extend Provider
        service(:compute, "Compute")
      end
    end

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

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

    module Fog
      module TheWrongWay
        extend Provider
        service(:compute, "Compute")
      end
    end

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

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

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

    module Fog
      module BothWays
        extend Provider
        service(:compute, "Compute")
      end
    end

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

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

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