Skip to content

Commit

Permalink
Improve test description in ForEachOnRangeSpec.kt (#4402)
Browse files Browse the repository at this point in the history
  • Loading branch information
schalkms committed Dec 27, 2021
1 parent f5d2a17 commit 4b88d31
Showing 1 changed file with 10 additions and 8 deletions.
Expand Up @@ -7,9 +7,11 @@ import org.spekframework.spek2.style.specification.describe

class ForEachOnRangeSpec : Spek({

val subject by memoized { ForEachOnRange() }

describe("ForEachOnRange rule") {

context("a kt file with using a forEach on a range") {
context("using a forEach on a range") {
val code = """
fun test() {
(1..10).forEach {
Expand All @@ -28,25 +30,25 @@ class ForEachOnRangeSpec : Spek({
"""

it("should report the forEach usage") {
val findings = ForEachOnRange().compileAndLint(code)
val findings = subject.compileAndLint(code)
assertThat(findings).hasSize(4)
}
}

context("a kt file with using any other method on a range") {
context("using any other method on a range") {
val code = """
fun test() {
(1..10).isEmpty()
}
"""

it("should report not report any issues") {
val findings = ForEachOnRange().compileAndLint(code)
it("should not report any issues") {
val findings = subject.compileAndLint(code)
assertThat(findings).isEmpty()
}
}

context("a kt file with using a forEach on a list") {
context("using a forEach on a list") {
val code = """
fun test() {
listOf(1, 2, 3).forEach {
Expand All @@ -55,8 +57,8 @@ class ForEachOnRangeSpec : Spek({
}
"""

it("should report not report any issues") {
val findings = ForEachOnRange().compileAndLint(code)
it("should not report any issues") {
val findings = subject.compileAndLint(code)
assertThat(findings).isEmpty()
}
}
Expand Down

0 comments on commit 4b88d31

Please sign in to comment.