Skip to content

Commit

Permalink
Update EmptyFunctionBlockSpec to use hasLocationStrings
Browse files Browse the repository at this point in the history
  • Loading branch information
cortinico committed Jun 13, 2019
1 parent a78844b commit 0560f0a
Showing 1 changed file with 10 additions and 6 deletions.
@@ -1,9 +1,10 @@
package io.gitlab.arturbosch.detekt.rules.empty

import io.gitlab.arturbosch.detekt.api.Config
import io.gitlab.arturbosch.detekt.test.TEST_FILENAME
import io.gitlab.arturbosch.detekt.test.TestConfig
import io.gitlab.arturbosch.detekt.test.assertThat
import io.gitlab.arturbosch.detekt.test.compileAndLint
import org.assertj.core.api.Assertions.assertThat
import org.spekframework.spek2.Spek
import org.spekframework.spek2.style.specification.describe

Expand All @@ -13,6 +14,8 @@ import org.spekframework.spek2.style.specification.describe
*/
class EmptyFunctionBlockSpec : Spek({

val fileName = TEST_FILENAME

val subject by memoized { EmptyFunctionBlock(Config.empty) }

describe("EmptyFunctionBlock rule") {
Expand All @@ -22,7 +25,7 @@ class EmptyFunctionBlockSpec : Spek({
class A {
protected fun stuff() {}
}"""
assertThat(subject.compileAndLint(code)).hasSize(1)
assertThat(subject.compileAndLint(code)).hasLocationStrings("'{}' at (2,27) in /$fileName")
}

it("should not flag function with open modifier") {
Expand All @@ -38,7 +41,7 @@ class EmptyFunctionBlockSpec : Spek({
fun a() {
fun b() {}
}"""
assertThat(subject.compileAndLint(code)).hasSize(1)
assertThat(subject.compileAndLint(code)).hasLocationStrings("'{}' at (2,10) in /$fileName")
}

context("some overridden functions") {
Expand Down Expand Up @@ -72,7 +75,7 @@ class EmptyFunctionBlockSpec : Spek({

it("should not flag overridden functions") {
val config = TestConfig(mapOf(EmptyFunctionBlock.IGNORE_OVERRIDDEN_FUNCTIONS to "true"))
assertThat(EmptyFunctionBlock(config).compileAndLint(code)).hasSize(1)
assertThat(EmptyFunctionBlock(config).compileAndLint(code)).hasLocationStrings("'{}' at (1,13) in /$fileName")
}
}

Expand All @@ -95,12 +98,13 @@ class EmptyFunctionBlockSpec : Spek({
}
""".trimIndent()
it("should not flag overridden functions with commented body") {
assertThat(subject.compileAndLint(code)).hasSize(1)
assertThat(subject.compileAndLint(code))
.hasLocationStrings("'{\n\n }' at (12,31) in /$fileName")
}

it("should not flag overridden functions with ignoreOverriddenFunctions") {
val config = TestConfig(mapOf(EmptyFunctionBlock.IGNORE_OVERRIDDEN_FUNCTIONS to "true"))
assertThat(EmptyFunctionBlock(config).compileAndLint(code)).hasSize(0)
assertThat(EmptyFunctionBlock(config).compileAndLint(code)).isEmpty()
}
}
}
Expand Down

0 comments on commit 0560f0a

Please sign in to comment.