java_requirement: set cask attribute

Set `@cask` attribute for JavaRequirement, which is used by
`brew info` to track cask requirement for formulae and
`brew bundle dump` to sort the formulae and casks.

Before:
```
$ brew info --json languagetool | jq '.[0].requirements'
[
  {
    "name": "java",
    "cask": null,
    "download": null
  }
]
$ brew cask install adoptopenjdk; brew install languagetool
$ brew bundle dump
brew "languagetool"
cask "adoptopenjdk"
```

After:
```
$ brew info --json languagetool | jq '.[0].requirements'
[
  {
    "name": "java",
    "cask": "adoptopenjdk",
    "download": null
  }
]
$ brew cask install adoptopenjdk; brew install languagetool
$ brew bundle dump
cask "adoptopenjdk"
brew "languagetool"
```

Also added relevant test cases.
This commit is contained in:
Cheng XU 2019-06-10 10:37:09 +08:00
parent c95cf90e32
commit 2bd9b2774d
No known key found for this signature in database
GPG Key ID: B19F15830AB4E690
2 changed files with 22 additions and 0 deletions

View File

@ -30,6 +30,7 @@ class JavaRequirement < Requirement
def initialize(tags = [])
@version = tags.shift if /^\d/ =~ tags.first
super(tags)
@cask = suggestion.token
end
def message

View File

@ -105,4 +105,25 @@ describe JavaRequirement do
end
end
end
describe "#suggestion" do
context "without specific version" do
its(:suggestion) { is_expected.to match(/brew cask install adoptopenjdk/) }
its(:cask) { is_expected.to eq("adoptopenjdk") }
end
context "with version 1.8" do
subject { described_class.new(%w[1.8]) }
its(:suggestion) { is_expected.to match(%r{brew cask install homebrew/cask-versions/adoptopenjdk8}) }
its(:cask) { is_expected.to eq("homebrew/cask-versions/adoptopenjdk8") }
end
context "with version 1.8+" do
subject { described_class.new(%w[1.8+]) }
its(:suggestion) { is_expected.to match(/brew cask install adoptopenjdk/) }
its(:cask) { is_expected.to eq("adoptopenjdk") }
end
end
end