summaryrefslogtreecommitdiff
path: root/test/rubygems/test_gem_version_option.rb
blob: d6035ab80030a03e3080c885effd6045a3c806d4 (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
require 'rubygems/test_case'
require 'rubygems/command'
require 'rubygems/version_option'

class TestGemVersionOption < Gem::TestCase

  def setup
    super

    @cmd = Gem::Command.new 'dummy', 'dummy'
    @cmd.extend Gem::VersionOption
  end

  def test_add_platform_option
    @cmd.add_platform_option

    assert @cmd.handles?(%w[--platform x86-darwin])
  end

  def test_add_version_option
    @cmd.add_version_option

    assert @cmd.handles?(%w[--version >1])
  end

  def test_enables_prerelease
    @cmd.add_version_option

    @cmd.handle_options %w[mygem -v 0.2.0.a]
    assert @cmd.options[:prerelease]

    @cmd.handle_options %w[mygem -v 0.2.0]
    refute @cmd.options[:prerelease]

    @cmd.handle_options %w[mygem]
    refute @cmd.options[:prerelease]
  end

  def test_platform_option
    @cmd.add_platform_option

    @cmd.handle_options %w[--platform x86-freebsd6 --platform x86-freebsd7]

    expected = [
      Gem::Platform::RUBY,
      Gem::Platform.new('x86-freebsd6'),
      Gem::Platform.new('x86-freebsd7'),
    ]

    assert_equal expected, Gem.platforms
  end

  def test_platform_option_ruby
    @cmd.add_platform_option

    @cmd.handle_options %w[--platform ruby]

    expected = [
      Gem::Platform::RUBY
    ]

    assert_equal expected, Gem.platforms
  end

  def test_platform_option_twice
    @cmd.add_platform_option

    @cmd.handle_options %w[--platform x86-freebsd6 --platform x86-freebsd-6]

    expected = [
      Gem::Platform::RUBY,
      Gem::Platform.new('x86-freebsd6'),
    ]

    assert_equal expected, Gem.platforms
  end

  def test_version_option
    @cmd.add_version_option

    @cmd.handle_options %w[--version >1]

    expected = {
      :args => [],
      :explicit_prerelease => false,
      :prerelease => false,
      :version => Gem::Requirement.new('> 1'),
    }

    assert_equal expected, @cmd.options
  end

  def test_version_option_compound
    @cmd.add_version_option

    @cmd.handle_options ['--version', '< 1, > 0.9']

    expected = {
      :args => [],
      :explicit_prerelease => false,
      :prerelease => false,
      :version => Gem::Requirement.new('< 1', '> 0.9'),
    }

    assert_equal expected, @cmd.options
  end

  def test_version_option_explicit_prerelease
    @cmd.add_prerelease_option
    @cmd.add_version_option

    @cmd.handle_options %w[--pre --version >1]

    expected = {
      :args => [],
      :explicit_prerelease => true,
      :prerelease => true,
      :version => Gem::Requirement.new('> 1'),
    }

    assert_equal expected, @cmd.options
  end

  def test_version_option_twice
    @cmd.add_version_option

    @cmd.handle_options %w[--version >1.a]

    expected = {
      :args => [],
      :explicit_prerelease => false,
      :prerelease => true,
      :version => Gem::Requirement.new('> 1.a'),
    }

    assert_equal expected, @cmd.options

    @cmd.handle_options %w[--version >1]

    expected = {
      :args => [],
      :explicit_prerelease => false,
      :prerelease => false,
      :version => Gem::Requirement.new('> 1'),
    }

    assert_equal expected, @cmd.options
  end

end