summaryrefslogtreecommitdiff
path: root/spec/bundler/other/ext_spec.rb
blob: 4d954b474f5833e3ad11793fd09c99daff2301a5 (plain)
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
# frozen_string_literal: true

RSpec.describe "Gem::Specification#match_platform" do
  it "does not match platforms other than the gem platform" do
    darwin = gem "lol", "1.0", "platform_specific-1.0-x86-darwin-10"
    expect(darwin.match_platform(pl("java"))).to eq(false)
  end

  context "when platform is a string" do
    it "matches when platform is a string" do
      lazy_spec = Bundler::LazySpecification.new("lol", "1.0", "universal-mingw32")
      expect(lazy_spec.match_platform(pl("x86-mingw32"))).to eq(true)
      expect(lazy_spec.match_platform(pl("x64-mingw32"))).to eq(true)
    end
  end
end

RSpec.describe "Bundler::GemHelpers#generic" do
  include Bundler::GemHelpers

  it "converts non-windows platforms into ruby" do
    expect(generic(pl("x86-darwin-10"))).to eq(pl("ruby"))
    expect(generic(pl("ruby"))).to eq(pl("ruby"))
  end

  it "converts java platform variants into java" do
    expect(generic(pl("universal-java-17"))).to eq(pl("java"))
    expect(generic(pl("java"))).to eq(pl("java"))
  end

  it "converts mswin platform variants into x86-mswin32" do
    expect(generic(pl("mswin32"))).to eq(pl("x86-mswin32"))
    expect(generic(pl("i386-mswin32"))).to eq(pl("x86-mswin32"))
    expect(generic(pl("x86-mswin32"))).to eq(pl("x86-mswin32"))
  end

  it "converts 32-bit mingw platform variants into x86-mingw32" do
    expect(generic(pl("mingw32"))).to eq(pl("x86-mingw32"))
    expect(generic(pl("i386-mingw32"))).to eq(pl("x86-mingw32"))
    expect(generic(pl("x86-mingw32"))).to eq(pl("x86-mingw32"))
  end

  it "converts 64-bit mingw platform variants into x64-mingw32" do
    expect(generic(pl("x64-mingw32"))).to eq(pl("x64-mingw32"))
    expect(generic(pl("x86_64-mingw32"))).to eq(pl("x64-mingw32"))
  end

  it "converts 64-bit mingw UCRT platform variants into x64-mingw-ucrt" do
    expect(generic(pl("x64-mingw-ucrt"))).to eq(pl("x64-mingw-ucrt"))
  end
end

RSpec.describe "Gem::SourceIndex#refresh!" do
  before do
    install_gemfile <<-G
      source "#{file_uri_for(gem_repo1)}"
      gem "rack"
    G
  end

  it "does not explode when called" do
    run "Gem.source_index.refresh!", raise_on_error: false
    run "Gem::SourceIndex.new([]).refresh!", raise_on_error: false
  end
end

RSpec.describe "Gem::NameTuple" do
  describe "#initialize" do
    it "creates a Gem::NameTuple with equality regardless of platform type" do
      gem_platform = Gem::NameTuple.new "a", v("1"), pl("x86_64-linux")
      str_platform = Gem::NameTuple.new "a", v("1"), "x86_64-linux"
      expect(gem_platform).to eq(str_platform)
      expect(gem_platform.hash).to eq(str_platform.hash)
      expect(gem_platform.to_a).to eq(str_platform.to_a)
    end
  end

  describe "#lock_name" do
    it "returns the lock name" do
      expect(Gem::NameTuple.new("a", v("1.0.0"), pl("x86_64-linux")).lock_name).to eq("a (1.0.0-x86_64-linux)")
      expect(Gem::NameTuple.new("a", v("1.0.0"), "ruby").lock_name).to eq("a (1.0.0)")
      expect(Gem::NameTuple.new("a", v("1.0.0")).lock_name).to eq("a (1.0.0)")
    end
  end
end