Check results of spread operator with startsWith or like
up vote
0
down vote
favorite
Let's say I have:
class Conflict extends RuntimeException {
Conflict(String message) {
super(message)
}
}
and
class Conflicts extends RuntimeException {
List<Conflict> conflicts = new ArrayList<>()
Conflicts(List<Conflict> conflicts) {
this.conflicts = conflicts
}
}
In Spock, I typically check exception messages with spread operator:
def e = thrown(Conflicts)
e.conflicts*.message == ["my expected message 1", "my expected message 2"]
Is there any way how to check startsWith, like and other operations in similar succinct way in Groovy?
groovy spock
add a comment |
up vote
0
down vote
favorite
Let's say I have:
class Conflict extends RuntimeException {
Conflict(String message) {
super(message)
}
}
and
class Conflicts extends RuntimeException {
List<Conflict> conflicts = new ArrayList<>()
Conflicts(List<Conflict> conflicts) {
this.conflicts = conflicts
}
}
In Spock, I typically check exception messages with spread operator:
def e = thrown(Conflicts)
e.conflicts*.message == ["my expected message 1", "my expected message 2"]
Is there any way how to check startsWith, like and other operations in similar succinct way in Groovy?
groovy spock
Maybe:["my expected message 1", "my expected message 2"].every { it.contains('expected') }?
– Opal
Nov 7 at 12:19
e.conflicts*.message.findAll{it=~"my expected message 1|my expected message 2"}
– daggett
Nov 7 at 12:31
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Let's say I have:
class Conflict extends RuntimeException {
Conflict(String message) {
super(message)
}
}
and
class Conflicts extends RuntimeException {
List<Conflict> conflicts = new ArrayList<>()
Conflicts(List<Conflict> conflicts) {
this.conflicts = conflicts
}
}
In Spock, I typically check exception messages with spread operator:
def e = thrown(Conflicts)
e.conflicts*.message == ["my expected message 1", "my expected message 2"]
Is there any way how to check startsWith, like and other operations in similar succinct way in Groovy?
groovy spock
Let's say I have:
class Conflict extends RuntimeException {
Conflict(String message) {
super(message)
}
}
and
class Conflicts extends RuntimeException {
List<Conflict> conflicts = new ArrayList<>()
Conflicts(List<Conflict> conflicts) {
this.conflicts = conflicts
}
}
In Spock, I typically check exception messages with spread operator:
def e = thrown(Conflicts)
e.conflicts*.message == ["my expected message 1", "my expected message 2"]
Is there any way how to check startsWith, like and other operations in similar succinct way in Groovy?
groovy spock
groovy spock
asked Nov 7 at 12:05
Patrik Mihalčin
5462925
5462925
Maybe:["my expected message 1", "my expected message 2"].every { it.contains('expected') }?
– Opal
Nov 7 at 12:19
e.conflicts*.message.findAll{it=~"my expected message 1|my expected message 2"}
– daggett
Nov 7 at 12:31
add a comment |
Maybe:["my expected message 1", "my expected message 2"].every { it.contains('expected') }?
– Opal
Nov 7 at 12:19
e.conflicts*.message.findAll{it=~"my expected message 1|my expected message 2"}
– daggett
Nov 7 at 12:31
Maybe:
["my expected message 1", "my expected message 2"].every { it.contains('expected') }?– Opal
Nov 7 at 12:19
Maybe:
["my expected message 1", "my expected message 2"].every { it.contains('expected') }?– Opal
Nov 7 at 12:19
e.conflicts*.message.findAll{it=~"my expected message 1|my expected message 2"}– daggett
Nov 7 at 12:31
e.conflicts*.message.findAll{it=~"my expected message 1|my expected message 2"}– daggett
Nov 7 at 12:31
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
You can use every for that:
def e = thrown(Conflicts)
e.conflicts*.message.every { it.startsWith("my expected message" }
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
You can use every for that:
def e = thrown(Conflicts)
e.conflicts*.message.every { it.startsWith("my expected message" }
add a comment |
up vote
1
down vote
accepted
You can use every for that:
def e = thrown(Conflicts)
e.conflicts*.message.every { it.startsWith("my expected message" }
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
You can use every for that:
def e = thrown(Conflicts)
e.conflicts*.message.every { it.startsWith("my expected message" }
You can use every for that:
def e = thrown(Conflicts)
e.conflicts*.message.every { it.startsWith("my expected message" }
answered Nov 8 at 21:19
Michael
1,0331712
1,0331712
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53189143%2fcheck-results-of-spread-operator-with-startswith-or-like%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Maybe:
["my expected message 1", "my expected message 2"].every { it.contains('expected') }?– Opal
Nov 7 at 12:19
e.conflicts*.message.findAll{it=~"my expected message 1|my expected message 2"}– daggett
Nov 7 at 12:31