Sha256: b787bbd5e196a6786a109b36b76ca9aea0318deccbb0a0a69c42ff119582f6e7

Contents?: true

Size: 1.91 KB

Versions: 51

Compression:

Stored size: 1.91 KB

Contents

require 'spec_helper'

describe RightSupport::Net::AddressHelper do
  class AddressHelperTarget
    include RightSupport::Net::AddressHelper
  end

  before(:each) do
    @helper = AddressHelperTarget.new
  end

  describe :my_ipv4_addresses do

  end

  describe :my_ipv4_address do
    it 'consistently chooses the lowest-numbered address' do
      p = ['10.0.1.17', '192.168.7.5', '192.168.4.2', '127.0.0.1']
      flexmock(@helper).should_receive(:local_routable_address).with(Socket::AF_INET).and_return(p[0])
      flexmock(@helper).should_receive(:local_hostname_addresses).with(Socket::AF_INET).once.ordered.and_return([ p[3], p[2] ])
      flexmock(@helper).should_receive(:local_hostname_addresses).with(Socket::AF_INET).once.ordered.and_return([ p[1], p[2] ])

      one = @helper.my_ipv4_address(:private)
      two = @helper.my_ipv4_address(:private)
      one.should == p[0]
      two.should == p[0]
    end
  end

  describe :my_ipv4_addresses do
    before(:each) do
      routable_addr  = '67.2.204.5'
      hostname_addrs = ['127.0.0.1', '10.0.0.15', '67.2.204.5']
      flexmock(@helper).should_receive(:local_routable_address).with(Socket::AF_INET).and_return(routable_addr)
      flexmock(@helper).should_receive(:local_hostname_addresses).with(Socket::AF_INET).and_return(hostname_addrs)
      flexmock(@helper).should_receive(:local_hostname_addresses).with(Socket::AF_INET).and_return(hostname_addrs)
    end

    context 'with :loopback option' do
      it 'returns only loopback addresses' do
        @helper.my_ipv4_addresses(:loopback).should == ['127.0.0.1']
      end
    end

    context 'with :private option' do
      it 'returns only private addresses' do
        @helper.my_ipv4_addresses(:private).should == ['10.0.0.15']
      end
    end

    context 'with :public option' do
      it 'returns only public addresses' do
        @helper.my_ipv4_addresses(:public).should == ['67.2.204.5']
      end
    end
  end
end

Version data entries

51 entries across 51 versions & 1 rubygems

Version Path
right_support-2.11.3 spec/net/address_helper_spec.rb
right_support-2.11.2 spec/net/address_helper_spec.rb
right_support-2.10.1 spec/net/address_helper_spec.rb
right_support-2.9.6 spec/net/address_helper_spec.rb
right_support-2.9.5 spec/net/address_helper_spec.rb
right_support-2.9.4 spec/net/address_helper_spec.rb
right_support-2.9.3 spec/net/address_helper_spec.rb
right_support-2.9.2 spec/net/address_helper_spec.rb
right_support-2.9.1 spec/net/address_helper_spec.rb
right_support-2.8.46 spec/net/address_helper_spec.rb
right_support-2.8.45 spec/net/address_helper_spec.rb
right_support-2.8.44 spec/net/address_helper_spec.rb
right_support-2.8.43 spec/net/address_helper_spec.rb
right_support-2.8.42 spec/net/address_helper_spec.rb
right_support-2.8.41 spec/net/address_helper_spec.rb
right_support-2.8.40 spec/net/address_helper_spec.rb
right_support-2.8.39 spec/net/address_helper_spec.rb
right_support-2.8.38 spec/net/address_helper_spec.rb
right_support-2.8.37 spec/net/address_helper_spec.rb
right_support-2.8.36 spec/net/address_helper_spec.rb