File: internet_connection_spec.rb

package info (click to toggle)
ruby-vcr 6.0.0%2Breally5.0.0-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,320 kB
  • sloc: ruby: 8,456; sh: 177; makefile: 7
file content (37 lines) | stat: -rw-r--r-- 1,134 bytes parent folder | download | duplicates (3)
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
require 'spec_helper'

describe VCR::InternetConnection do
  describe '.available?' do
    before(:each) do
      described_class.send(:remove_instance_variable, :@available) if described_class.instance_variable_defined?(:@available)
    end

    def stub_pingecho_with(value)
      allow(VCR::Ping).to receive(:pingecho).with("example.com", anything, anything).and_return(value)
    end

    context 'when pinging example.com succeeds' do
      it 'returns true' do
        stub_pingecho_with(true)
        expect(described_class).to be_available
      end

      it 'memoizes the value so no extra pings are made' do
        expect(VCR::Ping).to receive(:pingecho).once.and_return(true)
        3.times { described_class.available? }
      end
    end

    context 'when pinging example.com fails' do
      it 'returns false' do
        stub_pingecho_with(false)
        expect(described_class).not_to be_available
      end

      it 'memoizes the value so no extra pings are made' do
        expect(VCR::Ping).to receive(:pingecho).once.and_return(false)
        3.times { described_class.available? }
      end
    end
  end
end