Sha256: 4073448e0736fd7f295d8fb302a0fb372f82744c0dbe2da8e64504d5b3bf197d

Contents?: true

Size: 830 Bytes

Versions: 3

Compression:

Stored size: 830 Bytes

Contents

require 'spec_helper'

describe Fog::CurrentMachine do
  before do
    @was_mocking = Fog.mock?
    Fog.mock!

    @old_excon_defaults_mock = Excon.defaults[:mock]
    Excon.defaults[:mock] = true
  end

  after do
    Fog.unmock! unless @was_mocking

    Fog::CurrentMachine.ip_address = nil
    Excon.stubs.clear
    Excon.defaults[:mock] = @old_excon_defaults_mock
  end

  describe "ip_address" do
    it "should be thread safe" do
      Excon.stub({:method => :get, :path => "/"}, {:body => ""})

      (1..10).map {
        Thread.new { Fog::CurrentMachine.ip_address }
      }.each{ |t| t.join }
    end

    it "should remove trailing endline characters" do
      Excon.stub({:method => :get,  :path => "/"}, {:body => "192.168.0.1\n"})
      assert_equal "192.168.0.1", Fog::CurrentMachine.ip_address
    end
  end  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fog-core-1.24.0 spec/current_machine_spec.rb
fog-core-1.23.0 spec/current_machine_spec.rb
fog-core-1.22.0 spec/current_machine_spec.rb