Skip to content
This repository has been archived by the owner on Jul 26, 2021. It is now read-only.

Commit

Permalink
Use Matchers
Browse files Browse the repository at this point in the history
  • Loading branch information
mariogalic committed Apr 9, 2017
1 parent 9ef90e6 commit 0c3687c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 32 deletions.
8 changes: 4 additions & 4 deletions src/test/scala/com/gu/tip/HttpClientTest.scala
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package com.gu.tip

import org.scalatest.FlatSpec
import org.scalatest.{FlatSpec, MustMatchers}

class HttpClientTest extends FlatSpec {
class HttpClientTest extends FlatSpec with MustMatchers {

behavior of "HttpClient"

it should "be able to make a GET request" in {
object HttpClient extends HttpClient
val (code, body) = HttpClient.get("http://example.com", ("Authorization","test"))
assert(code == 200)
code mustBe 200
}

it should "be able to make a POST request" in {
object HttpClient extends HttpClient
val (code, body) =
HttpClient.post("http://petstore.swagger.io/v2/pet", ("Authorization","test"), "{\"name\": \"doggie\"}")
assert(code == 200)
code mustBe 200
}

}
8 changes: 4 additions & 4 deletions src/test/scala/com/gu/tip/NotifierTest.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.gu.tip

import org.scalatest.FlatSpec
import org.scalatest.{FlatSpec, MustMatchers}

class NotifierTest extends FlatSpec {
class NotifierTest extends FlatSpec with MustMatchers {

val mockCommitMessageResponse =
"""
Expand All @@ -27,7 +27,7 @@ class NotifierTest extends FlatSpec {

object Notifier extends Notifier with GitHubApi with MockHttpClient

assert(Notifier.setLabelOnLatestMergedPr() != 200)
Notifier.setLabelOnLatestMergedPr() must not be 200
}

behavior of "happy Notifier"
Expand All @@ -43,6 +43,6 @@ class NotifierTest extends FlatSpec {

object Notifier extends Notifier with GitHubApi with MockHttpClient

assert(Notifier.setLabelOnLatestMergedPr() == 200)
Notifier.setLabelOnLatestMergedPr() mustBe 200
}
}
28 changes: 9 additions & 19 deletions src/test/scala/com/gu/tip/TipTest.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.gu.tip

import org.scalatest.{AsyncFlatSpec}
import org.scalatest.Matchers._
import org.scalatest.{AsyncFlatSpec, MustMatchers}

class TipTest extends AsyncFlatSpec {
class TipTest extends AsyncFlatSpec with MustMatchers {
trait MockHttpClient extends HttpClient {
override def get(endpoint: String = "", authHeader: (String, String) = ("", "")) = (200, "")
override def post(endpoint: String = "", authHeader: (String, String) = ("", ""), jsonBody: String = "") = (200, "")
Expand All @@ -14,22 +13,22 @@ class TipTest extends AsyncFlatSpec {
behavior of "unhappy Tip"

it should "error on bad path name" in {
Tip.verify("badName").map { result => assert(result == UnrecognizedPathName) }
Tip.verify("badName").map(_ mustBe UnrecognizedPathName)
}

it should "error on bad syntax path definition" in {
object Tip extends Tip with Notifier with GitHubApi with MockHttpClient {
override val pathConfigFilename: String = "tip-bad.yaml"
}

Tip.verify("").map { result => assert(result == PathDefinitionSyntaxError) }
Tip.verify("").map( _ mustBe PathDefinitionSyntaxError)
}

it should "error on missing path definition file" in {
object Tip extends Tip with Notifier with GitHubApi with MockHttpClient {
override val pathConfigFilename: String = "tip-not-found.yaml"
}
Tip.verify("").map { result => assert(result == PathDefinitionFileNotFound) }
Tip.verify("").map(_ mustBe PathDefinitionFileNotFound)
}

it should "error on unclassifed error"
Expand All @@ -44,20 +43,16 @@ class TipTest extends AsyncFlatSpec {
for {
_ <- Tip.verify("Name A")
result <- Tip.verify("Name B")
} yield {
assert(result == FailedToSetLabel)
}
} yield result mustBe FailedToSetLabel
}

behavior of "happy Tip"

it should "verify a path" in {
Tip.verify("Name A").map { result => assert(result == PathVerified) }

Tip.verify("Name A").map(_ mustBe PathVerified)
}

it should "set the label when all paths are verified" in {

trait MockNotifier extends NotifierIf {this: GitHubApiIf =>
override def setLabelOnLatestMergedPr(): Int = 200
}
Expand All @@ -67,13 +62,10 @@ class TipTest extends AsyncFlatSpec {
for {
_ <- Tip.verify("Name A")
result <- Tip.verify("Name B")
} yield {
assert(result == LabelSet)
}
} yield result mustBe LabelSet
}

it should "set the label only once" in {

trait MockNotifier extends NotifierIf {this: GitHubApiIf =>
override def setLabelOnLatestMergedPr(): Int = 200
}
Expand All @@ -85,8 +77,6 @@ class TipTest extends AsyncFlatSpec {
_ <- Tip.verify("Name B")
_ <- Tip.verify("Name A")
result <- Tip.verify("Name B")
} yield {
assert(result == LabelAlreadySet)
}
} yield result mustBe LabelAlreadySet
}
}
9 changes: 4 additions & 5 deletions src/test/scala/com/gu/tip/YamlPathConfigReaderTest.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import java.io.FileNotFoundException

import org.scalatest.FlatSpec
import org.scalatest.Matchers._
import org.scalatest.{FlatSpec, Matchers}
import com.gu.tip.{EnrichedPath, Path, Paths, YamlPathConfigReader}

class YamlPathConfigReaderTest extends FlatSpec {
class YamlPathConfigReaderTest extends FlatSpec with Matchers {

"YamlPathConfigReader" should "convert tip.yaml definition to Paths type" in {
YamlPathConfigReader("tip.yaml") shouldBe a [Paths]
Expand Down Expand Up @@ -39,7 +38,7 @@ class YamlPathConfigReaderTest extends FlatSpec {
val enrichedPath = new EnrichedPath(Path("Path Name", "Path Description"))
val paths = new Paths(Map("Path Name" -> enrichedPath))
paths.verify("Path Name")
assert(paths.allVerified)
paths shouldBe 'allVerified
}

it should "verify a path only if it has not been verified before" in {
Expand All @@ -48,6 +47,6 @@ class YamlPathConfigReaderTest extends FlatSpec {
val paths = new Paths(Map("Path Name A" -> enrichedPathA, "Path Name B" -> enrichedPathB))
paths.verify("Path Name A")
paths.verify("Path Name A")
assert(!paths.allVerified)
paths should not be 'allVerified
}
}

0 comments on commit 0c3687c

Please sign in to comment.