jackett 0.22.1382
[Homebrew/homebrew-core.git] / Formula / r / rbenv.rb
blobdeb831851563989492bf1799fab2a86e0d8c6bb2
1 class Rbenv < Formula
2   desc "Ruby version manager"
3   homepage "https://rbenv.org"
4   url "https://github.com/rbenv/rbenv/archive/refs/tags/v1.3.2.tar.gz"
5   sha256 "e2104f6472d7a8477409c46d4de39562b4d01899148a3dbed73c1d99a0b4bb2a"
6   license "MIT"
7   head "https://github.com/rbenv/rbenv.git", branch: "master"
9   bottle do
10     sha256 cellar: :any_skip_relocation, all: "8158fb1f059c1316523b2cc9074c5c041b3944828dc3b76cb032f893e754f013"
11   end
13   depends_on "ruby-build"
15   uses_from_macos "ruby" => :test
17   def install
18     # Build an `:all` bottle.
19     inreplace "libexec/rbenv", "/usr/local", HOMEBREW_PREFIX
21     if build.head?
22       # Record exact git revision for `rbenv --version` output
23       git_revision = Utils.git_short_head
24       inreplace "libexec/rbenv---version", /^(version=)"([^"]+)"/,
25                                            %Q(\\1"\\2-g#{git_revision}")
26     end
28     zsh_completion.install "completions/_rbenv" => "_rbenv"
29     prefix.install ["bin", "completions", "libexec", "rbenv.d"]
30     man1.install "share/man/man1/rbenv.1"
31   end
33   test do
34     # Create a fake ruby version and executable.
35     rbenv_root = Pathname(shell_output("#{bin}/rbenv root").strip)
36     ruby_bin = rbenv_root/"versions/1.2.3/bin"
37     foo_script = ruby_bin/"foo"
38     foo_script.write "echo hello"
39     chmod "+x", foo_script
41     # Test versions. The second `rbenv` call is a shell function; do not add a `bin` prefix.
42     versions = shell_output("eval \"$(#{bin}/rbenv init -)\" && rbenv versions").split("\n")
43     assert_equal 2, versions.length
44     assert_match(/\* system/, versions[0])
45     assert_equal("  1.2.3", versions[1])
47     # Test rehash.
48     system bin/"rbenv", "rehash"
49     refute_match "Cellar", (rbenv_root/"shims/foo").read
50     # The second `rbenv` call is a shell function; do not add a `bin` prefix.
51     assert_equal "hello", shell_output("eval \"$(#{bin}/rbenv init -)\" && rbenv shell 1.2.3 && foo").chomp
52   end
53 end