当前位置: 首页>>代码示例>>Scala>>正文


Scala AsyncFlatSpec类代码示例

本文整理汇总了Scala中org.scalatest.AsyncFlatSpec的典型用法代码示例。如果您正苦于以下问题:Scala AsyncFlatSpec类的具体用法?Scala AsyncFlatSpec怎么用?Scala AsyncFlatSpec使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了AsyncFlatSpec类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: ChromedModuleSpec

//设置package包名称以及导入依赖的类
package com.dealermade.chromed.test

import scala.concurrent.ExecutionContext

import com.dealermade.chromed.ChromedModule
import com.dealermade.chromed.client.ChromedClient
import com.dealermade.chromed.models.Vehicle
import org.scalatest.{AsyncFlatSpec, FlatSpec}
import play.api.Application
import play.api.inject.guice.GuiceApplicationBuilder

class ChromedModuleSpec extends AsyncFlatSpec {

  val application: Application = new GuiceApplicationBuilder()
    .bindings(new ChromedModule)
    .build()

  implicit val ec: ExecutionContext = application.injector.instanceOf(classOf[ExecutionContext])
  val client: ChromedClient = application.injector.instanceOf(classOf[ChromedClient])

  behavior of "ChromedClient"

  it should "describe a vehicle by its vin" in {
    client.describeVehicle(vin = "3VWJM71K98M043923")
      .mapTo[Option[Vehicle]]
      .map { v =>
        assert(v.isDefined)
        assert(v.get.modelYear == 2008)
        assert(v.get.model == "Jetta Sedan")
        assert(v.get.division == "Volkswagen")
      }
  }

  it should "return an empty option when a vehicle isn't found" in {
    client.describeVehicle(vin = "INVALIDVIN")
      .mapTo[Option[Vehicle]]
      .map { v => assert(v.isEmpty) }
  }
} 
开发者ID:Dealermade,项目名称:ChromedScala,代码行数:40,代码来源:ChromedModuleSpec.scala

示例2: CopySourceSpec

//设置package包名称以及导入依赖的类
package it

import java.sql.ResultSet

import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import akka.stream.scaladsl.Sink
import akka.util.ByteString
import org.scalatest.{AsyncFlatSpec, BeforeAndAfterAll, Matchers}
import ru.arigativa.akka.streams.ConnectionProvider._
import ru.arigativa.akka.streams.{PgCopySourceSettings, PgCopyStreamConverters}
import util.PostgresFixture


class CopySourceSpec extends AsyncFlatSpec with Matchers with PostgresFixture with BeforeAndAfterAll {

  implicit val system = ActorSystem()
  implicit val materializer = ActorMaterializer()
  override def afterAll(): Unit = {
    system.terminate()
  }

  def fetchPeople(rs: ResultSet): (Long, String, Int) = {
    rs.next()
    (rs.getLong(1), rs.getString(2), rs.getInt(3))
  }

  "PgCopySource" should "copy bytes as expected" in {
    withPostgres("people_filled") { conn =>
      PgCopyStreamConverters.bytesSource("COPY (SELECT id, name, age FROM people) TO STDOUT", PgCopySourceSettings(conn))
        .runWith(Sink.fold(ByteString.empty) {
          case (acc, next) => acc ++ next
        })
        .map { result =>
          result.decodeString("UTF-8") shouldBe (
            "1\tAlex\t26\n" +
            "2\tLisa\t22\n" +
            "3\tWith\\r\\n\\t special chars\\\\\t10\n" +
            "4\t\\N\t-1\n"
          )
        }
    }
  }

  "PgCopySource" should "copy lines as expected" in {
    withPostgres("people_filled") { conn =>
      PgCopyStreamConverters.source("COPY (SELECT id, name, age FROM people) TO STDOUT", PgCopySourceSettings(conn))
        .runWith(Sink.seq)
        .map { result =>
          result shouldBe Seq(
            Seq("1", "Alex", "26"),
            Seq("2", "Lisa", "22"),
            Seq("3", "With\r\n\t special chars\\", "10"),
            Seq("4", null, "-1")
          )
        }
    }
  }
} 
开发者ID:klpx,项目名称:akka-streams-postgresql-copy,代码行数:60,代码来源:CopySourceSpec.scala

示例3: FastSyncStateActorSpec

//设置package包名称以及导入依赖的类
package io.iohk.ethereum.blockchain.sync

import akka.actor.ActorSystem
import akka.pattern._
import akka.testkit.TestActorRef
import akka.util.ByteString
import io.iohk.ethereum.NormalPatience
import io.iohk.ethereum.blockchain.sync.FastSync.SyncState
import io.iohk.ethereum.blockchain.sync.FastSyncStateActor.GetStorage
import io.iohk.ethereum.db.dataSource.EphemDataSource
import io.iohk.ethereum.db.storage.FastSyncStateStorage
import io.iohk.ethereum.domain.BlockHeader
import org.scalatest.concurrent.Eventually
import org.scalatest.{AsyncFlatSpec, Matchers}

class FastSyncStateActorSpec extends AsyncFlatSpec with Matchers with Eventually with NormalPatience {

  "FastSyncStateActor" should "eventually persist a newest state of a fast sync" in {

    val dataSource = EphemDataSource()
    implicit val system = ActorSystem("FastSyncStateActorSpec_System")
    val syncStateActor = TestActorRef(new FastSyncStateActor)
    val maxN = 10

    val targetBlockHeader = BlockHeader(ByteString(""), ByteString(""), ByteString(""), ByteString(""), ByteString(""),
      ByteString(""), ByteString(""), 0, 0, 0, 0, 0, ByteString(""), ByteString(""), ByteString(""))
    syncStateActor ! new FastSyncStateStorage(dataSource)
    (0 to maxN).foreach(n => syncStateActor ! SyncState(targetBlockHeader).copy(downloadedNodesCount = n))

    eventually {
      (syncStateActor ? GetStorage).mapTo[Option[SyncState]].map { syncState =>
        val expected = SyncState(targetBlockHeader).copy(downloadedNodesCount = maxN)
        syncState shouldEqual Some(expected)
      }
    }

  }

} 
开发者ID:input-output-hk,项目名称:etc-client,代码行数:40,代码来源:FastSyncStateActorSpec.scala

示例4: TestSpec

//设置package包名称以及导入依赖的类
package com.sijali.commands

import com.sijali.util.{BotMessage, TestMessage}
import org.scalatest.{AsyncFlatSpec, Matchers}
import com.sijali.util.TestMessage._

class TestSpec extends AsyncFlatSpec with Matchers with TestMessage {
  "Test command" should "generate a test message" in {
    val command = "sijali test"

    val botMessage = BotMessage(
      channelId = imIdAdmin,
      message = "success"
    )

    assertMessage(getChannelMessage(command), Some(botMessage))
  }
} 
开发者ID:OscarOdic,项目名称:sijali,代码行数:19,代码来源:TestSpec.scala

示例5: LmgtfySpec

//设置package包名称以及导入依赖的类
package com.sijali.commands

import com.sijali.util.{BotMessage, TestMessage}
import org.scalatest.{AsyncFlatSpec, Matchers}
import com.sijali.util.TestMessage._

class LmgtfySpec extends AsyncFlatSpec with Matchers with TestMessage {
  "Lmgtfy command" should "generate a message with a link to lmgtfy" in {
    val command = s"sijali lmgtfy $channelName example message"

    val botMessageOpt = for {
      channelId <- channelIdOpt
    } yield BotMessage(
      channelId = channelId,
      message = "http://letmegooglethatforyou.com/?q=example+message"
    )

    assertMessage(getChannelMessage(command), botMessageOpt)
  }

  it should "generate an error if the channel, user or group is not found" in {
    val command = "sijali lmgtfy nothing example message"

    assertError(getChannelMessage(command), Some("Channel, User or Group nothing not found"))
  }
} 
开发者ID:OscarOdic,项目名称:sijali,代码行数:27,代码来源:LmgtfySpec.scala

示例6: PollSpec

//设置package包名称以及导入依赖的类
package com.sijali.commands

import com.sijali.util.{BotMessage, TestMessage}
import org.scalatest.{AsyncFlatSpec, Matchers}
import com.sijali.util.TestMessage._

class PollSpec extends AsyncFlatSpec with Matchers with TestMessage {
  "Poll command" should "generate a message with a poll" in {
    val command = s"""sijali poll $channelName "example message" :one: "one" :two: "two" :three: "three""""

    val botMessageOpt = for {
      channelId <- channelIdOpt
    } yield BotMessage(
      channelId = channelId,
      message = "*example message*\n:one: one\n:two: two\n:three: three",
      reactions = List("one", "two", "three")
    )

    assertMessage(getChannelMessage(command), botMessageOpt)
  }

  it should "generate an error if the channel, user or group is not found" in {
    val command = """sijali poll nothing "example message" :one: "one" :two: "two" :three: "three""""

    assertError(getChannelMessage(command), Some("Channel, User or Group nothing not found"))
  }
} 
开发者ID:OscarOdic,项目名称:sijali,代码行数:28,代码来源:PollSpec.scala

示例7: PrivateSpec

//设置package包名称以及导入依赖的类
package com.sijali.commands

import com.sijali.util.{BotMessage, TestMessage}
import org.scalatest.{AsyncFlatSpec, Matchers}
import com.sijali.util.TestMessage._

class PrivateSpec extends AsyncFlatSpec with Matchers with TestMessage {
  "Private command" should "generate a private message" in {
    val command = s"sijali private $userName example message"

    val botMessageOpt = for {
      imId <- imIdOpt
    } yield BotMessage(
      channelId = imId,
      message = "example message"
    )

    assertMessage(getChannelMessage(command), botMessageOpt)
  }

  it should "generate an error if the user is not found" in {
    val command = "sijali private nothing example message"

    assertError(getChannelMessage(command), Some("User nothing not found"))
  }
} 
开发者ID:OscarOdic,项目名称:sijali,代码行数:27,代码来源:PrivateSpec.scala

示例8: ChannelSpec

//设置package包名称以及导入依赖的类
package com.sijali.commands

import com.sijali.util.{BotMessage, TestMessage}
import org.scalatest.{AsyncFlatSpec, Matchers}
import com.sijali.util.TestMessage._

class ChannelSpec extends AsyncFlatSpec with Matchers with TestMessage {
  "Channel command" should "generate a message for a channel slack" in {
    val command = s"sijali channel $channelName example message"

    val botMessageOpt = for {
      channelId <- channelIdOpt
    } yield BotMessage(
      channelId = channelId,
      message = "example message"
    )

    assertMessage(getChannelMessage(command), botMessageOpt)
  }

  it should "generate an error if the channel is not found" in {
    val command = "sijali channel nothing example message"

    assertError(getChannelMessage(command), Some("Channel nothing not found"))
  }
} 
开发者ID:OscarOdic,项目名称:sijali,代码行数:27,代码来源:ChannelSpec.scala

示例9: EmojiSpec

//设置package包名称以及导入依赖的类
package com.sijali.commands

import com.sijali.util.{BotMessage, TestMessage}
import org.scalatest.{AsyncFlatSpec, Matchers}
import com.sijali.util.TestMessage._

class EmojiSpec extends AsyncFlatSpec with Matchers with TestMessage {
  "Emoji command" should "generate a message with other username and emoji icon" in {
    val command = s"sijali emoji testbot :smile: $channelName example message"

    val botMessageOpt = for {
      channelId <- channelIdOpt
    } yield BotMessage(
      channelId = channelId,
      message = "example message",
      username = Some("testbot"),
      iconEmoji = Some(":smile:")
    )

    assertMessage(getChannelMessage(command), botMessageOpt)
  }

  it should "generate an error if the channel, user or group is not found" in {
    val command = "sijali emoji testbot :smile: nothing example message"

    assertError(getChannelMessage(command), Some("Channel, User or Group nothing not found"))
  }
} 
开发者ID:OscarOdic,项目名称:sijali,代码行数:29,代码来源:EmojiSpec.scala

示例10: HelpSpec

//设置package包名称以及导入依赖的类
package com.sijali.commands

import com.sijali.util.{BotMessage, TestMessage}
import org.scalatest.{AsyncFlatSpec, Matchers}
import com.sijali.util.TestMessage._

class HelpSpec extends AsyncFlatSpec with Matchers with TestMessage {

  val defaultHelp: String = "*test* - _Test if the bot is connected to slack, post a private to the admin user_\n\n" +
    "*channel* - _Post on a slack channel or group with the bot_\n\n" +
    "*private* - _Post on a slack private conversation with the bot_\n\n" +
    "*as* - _To chat on slack in place of a user_\n\n" +
    "*emoji* - _Post a slack message with other username and emoji icon_\n\n" +
    "*lmgtfy* - _Redirect a user to a google page, with lmgtfy website_\n\n" +
    "*poll* - _Post a poll on a slack channel, we can vote with all emojis_\n\n" +
    "*help* - _Show available commands and how to use it for the bot_\n"

  "Help command" should "show how to use the bot" in {
    val command = "sijali help"

    val botMessageOpt = for {
      channelId <- channelIdOpt
    } yield BotMessage(
      channelId = channelId,
      message = defaultHelp
    )

    assertMessage(getChannelMessage(command), botMessageOpt)
  }

  it should "show how to use a command" in {
    val command = "sijali help poll"

    val botMessageOpt = for {
      channelId <- channelIdOpt
    } yield BotMessage(
      channelId = channelId,
      message = "*NAME*\n\n  *poll* - Post a poll on a slack channel, we can vote with all emojis\n\n" +
        "*SYNOPSIS*\n\n  _\"sijali poll <channel/group> \"<question>\" :<firstEmoji>: \"<firstAnswer>\" [ :<secondEmoji>: \"<secondAnswer>\" ] ..._"
    )

    assertMessage(getChannelMessage(command), botMessageOpt)
  }

  it should "show how to use the bot if the command asked doesn't exist" in {
    val command = "sijali help nothing"

    val botMessageOpt = for {
      channelId <- channelIdOpt
    } yield BotMessage(
      channelId = channelId,
      message = defaultHelp
    )

    assertMessage(getChannelMessage(command), botMessageOpt)
  }
} 
开发者ID:OscarOdic,项目名称:sijali,代码行数:58,代码来源:HelpSpec.scala

示例11: AsSpec

//设置package包名称以及导入依赖的类
package com.sijali.commands

import com.sijali.util.{BotMessage, TestMessage}
import org.scalatest.{AsyncFlatSpec, Matchers}
import com.sijali.util.TestMessage._

class AsSpec extends AsyncFlatSpec with Matchers with TestMessage {
  "As command" should "generate a message in place of a user" in {
    val command = s"sijali as $userName $channelName example message"

    val botMessageOpt = for {
      channelId <- channelIdOpt
      user <- userOpt
    } yield BotMessage(
      channelId = channelId,
      message = "example message",
      username = Some(userName),
      iconUrl = user.profile.map(_.image_72)
    )

    assertMessage(getChannelMessage(command), botMessageOpt)
  }

  it should "generate an error if the user is not found" in {
    val command = s"sijali as nothing $channelName example message"

    assertError(getChannelMessage(command), Some("User nothing not found"))
  }

  it should "generate an error if the channel, user or group is not found" in {
    val command = s"sijali as $userName nothing example message"

    assertError(getChannelMessage(command), Some("Channel, User or Group nothing not found"))
  }
} 
开发者ID:OscarOdic,项目名称:sijali,代码行数:36,代码来源:AsSpec.scala

示例12: handlersSpec

//设置package包名称以及导入依赖的类
package com.sijali.handlers

import com.sijali.util.{BotMessage, TestMessage}
import org.scalatest.{AsyncFlatSpec, Matchers}
import com.sijali.util.TestMessage._
import com.typesafe.config.ConfigFactory

class handlersSpec extends AsyncFlatSpec with Matchers with TestMessage {

  "Admin" should "receive the private messages sent to the bot" in {
    val message = getChannelMessage("example message", imIdOpt)

    val botMessageOpt = for {
      user <- userOpt
    } yield BotMessage(
      channelId = imIdAdmin,
      message = "example message",
      username = Some(userName),
      iconUrl = user.profile.map(_.image_72)
    )

    assertMessage(message, botMessageOpt)
  }

  "Banned user" should "not be able to execute command" in {
    val command = s"sijali channel $channelName example message"
    val userId = userIdOpt.getOrElse(fail)

    val botMessageOpt = for {
      imId <- imIdOpt
    } yield BotMessage(
      channelId = imId,
      message = ConfigFactory.load().getString("ban.message")
    )

    assertMessage(getChannelMessage(command), botMessageOpt, Array(userId))
  }
} 
开发者ID:OscarOdic,项目名称:sijali,代码行数:39,代码来源:handlersSpec.scala


注:本文中的org.scalatest.AsyncFlatSpec类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。