Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
brew
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
KMSCAKKSCFKA AKFACAMADCAS
brew
Commits
a8fea5cc
Commit
a8fea5cc
authored
8 years ago
by
Markus Reiter
Committed by
GitHub
8 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #2096 from reitermarkus/spec-java_requirement
Convert JavaRequirement test to spec.
parents
0a3b7b3f
f7151e58
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Library/Homebrew/test/java_requirement_spec.rb
+107
-0
107 additions, 0 deletions
Library/Homebrew/test/java_requirement_spec.rb
Library/Homebrew/test/java_requirement_test.rb
+0
-50
0 additions, 50 deletions
Library/Homebrew/test/java_requirement_test.rb
with
107 additions
and
50 deletions
Library/Homebrew/test/java_requirement_spec.rb
0 → 100644
+
107
−
0
View file @
a8fea5cc
require
"requirements/java_requirement"
describe
JavaRequirement
do
subject
{
described_class
.
new
([])
}
before
(
:each
)
do
ENV
[
"JAVA_HOME"
]
=
nil
end
describe
"#message"
do
its
(
:message
)
{
is_expected
.
to
match
(
/Java is required to install this formula./
)
}
end
describe
"#inspect"
do
subject
{
described_class
.
new
(
%w[1.7+]
)
}
its
(
:inspect
)
{
is_expected
.
to
eq
(
'#<JavaRequirement: "java" [] version="1.7+">'
)
}
end
describe
"#display_s"
do
context
"without specific version"
do
its
(
:display_s
)
{
is_expected
.
to
eq
(
"java"
)
}
end
context
"with version 1.8"
do
subject
{
described_class
.
new
(
%w[1.8]
)
}
its
(
:display_s
)
{
is_expected
.
to
eq
(
"java = 1.8"
)
}
end
context
"with version 1.8+"
do
subject
{
described_class
.
new
(
%w[1.8+]
)
}
its
(
:display_s
)
{
is_expected
.
to
eq
(
"java >= 1.8"
)
}
end
end
describe
"#satisfied?"
do
subject
{
described_class
.
new
(
%w[1.8]
)
}
it
"returns false if no `java` executable can be found"
do
allow
(
File
).
to
receive
(
:executable?
).
and_return
(
false
)
expect
(
subject
).
not_to
be_satisfied
end
it
"returns true if #preferred_java returns a path"
do
allow
(
subject
).
to
receive
(
:preferred_java
).
and_return
(
Pathname
.
new
(
"/usr/bin/java"
))
expect
(
subject
).
to
be_satisfied
end
context
"when #possible_javas contains paths"
do
let
(
:path
)
{
Pathname
.
new
(
Dir
.
mktmpdir
)
}
let
(
:java
)
{
path
/
"java"
}
def
setup_java_with_version
(
version
)
IO
.
write
java
,
<<-
EOS
.
undent
#!/bin/sh
echo 'java version "
#{
version
}
"'
EOS
FileUtils
.
chmod
"+x"
,
java
end
before
(
:each
)
do
allow
(
subject
).
to
receive
(
:possible_javas
).
and_return
([
java
])
end
after
(
:each
)
do
path
.
rmtree
end
context
"and 1.7 is required"
do
subject
{
described_class
.
new
(
%w[1.7]
)
}
it
"returns false if all are lower"
do
setup_java_with_version
"1.6.0_5"
expect
(
subject
).
not_to
be_satisfied
end
it
"returns true if one is equal"
do
setup_java_with_version
"1.7.0_5"
expect
(
subject
).
to
be_satisfied
end
it
"returns false if all are higher"
do
setup_java_with_version
"1.8.0_5"
expect
(
subject
).
not_to
be_satisfied
end
end
context
"and 1.7+ is required"
do
subject
{
described_class
.
new
(
%w[1.7+]
)
}
it
"returns false if all are lower"
do
setup_java_with_version
"1.6.0_5"
expect
(
subject
).
not_to
be_satisfied
end
it
"returns true if one is equal"
do
setup_java_with_version
"1.7.0_5"
expect
(
subject
).
to
be_satisfied
end
it
"returns true if one is higher"
do
setup_java_with_version
"1.8.0_5"
expect
(
subject
).
to
be_satisfied
end
end
end
end
end
This diff is collapsed.
Click to expand it.
Library/Homebrew/test/java_requirement_test.rb
deleted
100644 → 0
+
0
−
50
View file @
0a3b7b3f
require
"testing_env"
require
"requirements/java_requirement"
class
JavaRequirementTests
<
Homebrew
::
TestCase
def
setup
super
ENV
[
"JAVA_HOME"
]
=
nil
end
def
test_message
a
=
JavaRequirement
.
new
([])
assert_match
(
/Java is required to install this formula./
,
a
.
message
)
end
def
test_inspect
a
=
JavaRequirement
.
new
(
%w[1.7+]
)
assert_equal
a
.
inspect
,
'#<JavaRequirement: "java" [] version="1.7+">'
end
def
test_display_s
x
=
JavaRequirement
.
new
([])
assert_equal
x
.
display_s
,
"java"
y
=
JavaRequirement
.
new
(
%w[1.8]
)
assert_equal
y
.
display_s
,
"java = 1.8"
z
=
JavaRequirement
.
new
(
%w[1.8+]
)
assert_equal
z
.
display_s
,
"java >= 1.8"
end
def
test_satisfied?
a
=
JavaRequirement
.
new
(
%w[1.8]
)
File
.
stubs
(
:executable?
).
returns
(
false
)
refute_predicate
a
,
:satisfied?
b
=
JavaRequirement
.
new
([])
b
.
stubs
(
:preferred_java
).
returns
(
Pathname
.
new
(
"/usr/bin/java"
))
assert_predicate
b
,
:satisfied?
c
=
JavaRequirement
.
new
(
%w[1.7+]
)
c
.
stubs
(
:possible_javas
).
returns
([
Pathname
.
new
(
"/usr/bin/java"
)])
Utils
.
stubs
(
:popen_read
).
returns
(
'java version "1.6.0_5"'
)
refute_predicate
c
,
:satisfied?
Utils
.
stubs
(
:popen_read
).
returns
(
'java version "1.8.0_5"'
)
assert_predicate
c
,
:satisfied?
d
=
JavaRequirement
.
new
(
%w[1.7]
)
d
.
stubs
(
:possible_javas
).
returns
([
Pathname
.
new
(
"/usr/bin/java"
)])
Utils
.
stubs
(
:popen_read
).
returns
(
'java version "1.8.0_5"'
)
refute_predicate
d
,
:satisfied?
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment