File: platform_detection_spec.rb

package info (click to toggle)
ruby-childprocess 5.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 260 kB
  • sloc: ruby: 1,285; makefile: 4
file content (86 lines) | stat: -rw-r--r-- 2,883 bytes parent folder | download | duplicates (4)
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
require File.expand_path('../spec_helper', __FILE__)

# Q: Should platform detection concern be extracted from ChildProcess?
describe ChildProcess do

  describe ".arch" do
    subject { described_class.arch }

    before(:each) { described_class.instance_variable_set(:@arch, nil) }

    after(:each) { described_class.instance_variable_set(:@arch, nil) }

    shared_examples 'expected_arch_for_host_cpu' do |host_cpu, expected_arch|
      context "when host_cpu is '#{host_cpu}'" do
        before :each do
          allow(RbConfig::CONFIG).
            to receive(:[]).
            with('host_cpu').
            and_return(expected_arch)
        end

        it { is_expected.to eq expected_arch }
      end
    end

    # Normal cases: not macosx - depends only on host_cpu
    context "when os is *not* 'macosx'" do
      before :each do
        allow(described_class).to receive(:os).and_return(:not_macosx)
      end

      [
        { host_cpu: 'i386',    expected_arch: 'i386'    },
        { host_cpu: 'i486',    expected_arch: 'i386'    },
        { host_cpu: 'i586',    expected_arch: 'i386'    },
        { host_cpu: 'i686',    expected_arch: 'i386'    },
        { host_cpu: 'amd64',   expected_arch: 'x86_64'  },
        { host_cpu: 'x86_64',  expected_arch: 'x86_64'  },
        { host_cpu: 'ppc',     expected_arch: 'powerpc' },
        { host_cpu: 'powerpc', expected_arch: 'powerpc' },
        { host_cpu: 'unknown', expected_arch: 'unknown' },
      ].each do |args|
        include_context 'expected_arch_for_host_cpu', args.values
      end
    end

    # Special cases: macosx - when host_cpu is i686, have to re-check
    context "when os is 'macosx'" do
      before :each do
        allow(described_class).to receive(:os).and_return(:macosx)
      end

      context "when host_cpu is 'i686' " do
        shared_examples 'expected_arch_on_macosx_i686' do |is_64, expected_arch|
          context "when Ruby is #{is_64 ? 64 : 32}-bit" do
            before :each do
              allow(described_class).
                to receive(:is_64_bit?).
                and_return(is_64)
            end

            include_context 'expected_arch_for_host_cpu', 'i686', expected_arch
          end
        end

        [
          { is_64: true,  expected_arch: 'x86_64' },
          { is_64: false, expected_arch: 'i386'   }
        ].each do |args|
          include_context 'expected_arch_on_macosx_i686', args.values
        end
      end

      [
        { host_cpu: 'amd64',   expected_arch: 'x86_64'  },
        { host_cpu: 'x86_64',  expected_arch: 'x86_64'  },
        { host_cpu: 'ppc',     expected_arch: 'powerpc' },
        { host_cpu: 'powerpc', expected_arch: 'powerpc' },
        { host_cpu: 'unknown', expected_arch: 'unknown' },
      ].each do |args|
        include_context 'expected_arch_for_host_cpu', args.values
      end
    end
  end

end