File: rbenv.bats

package info (click to toggle)
ruby-build 20220426-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,632 kB
  • sloc: sh: 1,863; ruby: 21; makefile: 11
file content (225 lines) | stat: -rw-r--r-- 4,897 bytes parent folder | download
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#!/usr/bin/env bats

load test_helper
export RBENV_ROOT="${TMP}/rbenv"

setup() {
  stub rbenv-hooks 'install : true'
  stub rbenv-rehash 'true'
}

stub_ruby_build() {
  stub ruby-build "--lib : $BATS_TEST_DIRNAME/../bin/ruby-build --lib" "$@"
}

@test "install proper" {
  stub_ruby_build 'echo ruby-build "$@"'

  run rbenv-install 2.1.2
  assert_success "ruby-build 2.1.2 ${RBENV_ROOT}/versions/2.1.2"

  unstub ruby-build
  unstub rbenv-hooks
  unstub rbenv-rehash
}

@test "install rbenv local version by default" {
  stub_ruby_build 'echo ruby-build "$1"'
  stub rbenv-local 'echo 2.1.2'

  run rbenv-install
  assert_success "ruby-build 2.1.2"

  unstub ruby-build
  unstub rbenv-local
}

@test "list available versions" {
  stub_ruby_build \
    "--definitions : echo 1.8.7 1.9.3-p0 1.9.3-p194 2.1.2 | tr ' ' $'\\n'"

  run rbenv-install --list-all
  assert_success
  assert_output <<OUT
1.8.7
1.9.3-p0
1.9.3-p194
2.1.2
OUT

  unstub ruby-build
}

@test "nonexistent version" {
  stub brew false
  stub_ruby_build 'echo ERROR >&2 && exit 2' \
    "--definitions : echo 1.8.7 1.9.3-p0 1.9.3-p194 2.1.2 | tr ' ' $'\\n'"

  run rbenv-install 1.9.3
  assert_failure
  (
    cat <<OUT
ERROR

The following versions contain \`1.9.3' in the name:
  1.9.3-p0
  1.9.3-p194

See all available versions with \`rbenv install --list'.

OUT
    here="${BATS_TEST_DIRNAME}/.."
    echo -n "If the version you need is missing, try upgrading ruby-build"
    if [ "$here" != "${here#$(brew --prefix 2>/dev/null)}" ]; then
      printf ":\n\n"
      echo "  brew update && brew upgrade ruby-build"
    elif [ -d "${here}/.git" ]; then
      printf ":\n\n"
      echo "  git -C ${here} pull"
    else
      printf ".\n"
    fi
  ) | assert_output

  unstub ruby-build
}

@test "Homebrew upgrade instructions" {
  stub brew "--prefix : echo '${BATS_TEST_DIRNAME%/*}'"
  stub_ruby_build 'echo ERROR >&2 && exit 2' \
    "--definitions : true"

  run rbenv-install 1.9.3
  assert_failure
  assert_output <<OUT
ERROR

See all available versions with \`rbenv install --list'.

If the version you need is missing, try upgrading ruby-build:

  brew update && brew upgrade ruby-build
OUT

  unstub brew
  unstub ruby-build
}

@test "no build definitions from plugins" {
  refute [ -e "${RBENV_ROOT}/plugins" ]
  stub_ruby_build 'echo $RUBY_BUILD_DEFINITIONS'

  run rbenv-install 2.1.2
  assert_success ""
}

@test "some build definitions from plugins" {
  mkdir -p "${RBENV_ROOT}/plugins/foo/share/ruby-build"
  mkdir -p "${RBENV_ROOT}/plugins/bar/share/ruby-build"
  stub_ruby_build "echo \$RUBY_BUILD_DEFINITIONS | tr ':' $'\\n'"

  run rbenv-install 2.1.2
  assert_success
  assert_output <<OUT

${RBENV_ROOT}/plugins/bar/share/ruby-build
${RBENV_ROOT}/plugins/foo/share/ruby-build
OUT
}

@test "list build definitions from plugins" {
  mkdir -p "${RBENV_ROOT}/plugins/foo/share/ruby-build"
  mkdir -p "${RBENV_ROOT}/plugins/bar/share/ruby-build"
  stub_ruby_build "--definitions : echo \$RUBY_BUILD_DEFINITIONS | tr ':' $'\\n'"

  run rbenv-install --list-all
  assert_success
  assert_output <<OUT

${RBENV_ROOT}/plugins/bar/share/ruby-build
${RBENV_ROOT}/plugins/foo/share/ruby-build
OUT
}

@test "completion results include build definitions from plugins" {
  mkdir -p "${RBENV_ROOT}/plugins/foo/share/ruby-build"
  mkdir -p "${RBENV_ROOT}/plugins/bar/share/ruby-build"
  stub ruby-build "--definitions : echo \$RUBY_BUILD_DEFINITIONS | tr ':' $'\\n'"

  run rbenv-install --complete
  assert_success
  assert_output <<OUT
--list
--list-all
--force
--skip-existing
--keep
--patch
--verbose
--version

${RBENV_ROOT}/plugins/bar/share/ruby-build
${RBENV_ROOT}/plugins/foo/share/ruby-build
OUT
}

@test "not enough arguments for rbenv-install" {
  stub_ruby_build
  stub rbenv-help 'install : true'

  run rbenv-install
  assert_failure
  unstub rbenv-help
}

@test "too many arguments for rbenv-install" {
  stub_ruby_build
  stub rbenv-help 'install : true'

  run rbenv-install 2.1.1 2.1.2
  assert_failure
  unstub rbenv-help
}

@test "show help for rbenv-install" {
  stub_ruby_build
  stub rbenv-help 'install : true'

  run rbenv-install -h
  assert_success
  unstub rbenv-help
}

@test "rbenv-install has usage help preface" {
  run head "$(which rbenv-install)"
  assert_output_contains 'Usage: rbenv install'
}

@test "not enough arguments rbenv-uninstall" {
  stub rbenv-help 'uninstall : true'

  run rbenv-uninstall
  assert_failure
  unstub rbenv-help
}

@test "too many arguments for rbenv-uninstall" {
  stub rbenv-help 'uninstall : true'

  run rbenv-uninstall 2.1.1 2.1.2
  assert_failure
  unstub rbenv-help
}

@test "show help for rbenv-uninstall" {
  stub rbenv-help 'uninstall : true'

  run rbenv-uninstall -h
  assert_success
  unstub rbenv-help
}

@test "rbenv-uninstall has usage help preface" {
  run head "$(which rbenv-uninstall)"
  assert_output_contains 'Usage: rbenv uninstall'
}