Scala 为什么要像每个库中的构造一样,用DSL重新发明轮子?
更多的反问句,但仍然需要问。 今天我听说了Scala 为什么要像每个库中的构造一样,用DSL重新发明轮子?,scala,scalatest,Scala,Scalatest,更多的反问句,但仍然需要问。 今天我听说了org.scalatest.concurrent.finallytrait并决定尝试它(以前我使用的是fluent waits)。 所以trait是很好的,允许写一些东西,比如: def waitUntilTeamFormIsShown(implicit driver: WebDriver) = { eventually(Timeout(10 seconds), Interval(50 milliseconds)){ find(xpath("
org.scalatest.concurrent.finally
trait并决定尝试它(以前我使用的是fluent waits)。
所以trait是很好的,允许写一些东西,比如:
def waitUntilTeamFormIsShown(implicit driver: WebDriver) = {
eventually(Timeout(10 seconds), Interval(50 milliseconds)){
find(xpath("//div[contains(@class, 'user_groups')]/form")) shouldBe defined
}
completed
}
但有一刻我不喜欢:10秒
和50毫秒
这里不是scala.concurrent.duration.duration的实例,而是您需要导入:
import org.scalatest.time.SpanSugar._
import org.scalatest.concurrent.PatienceConfiguration._
所以ScalaTest实现了自己的stuff版本,它已经在Scala库中提供了
例如,当我使用Future
-s并需要等待结果时,我会像这样编写smth
Await.result(DB.matchingPointIDsByRadarID(arId)(db), 4 seconds).head
4秒
这里看起来完全一样,但这次是scala.concurrent.duration.FiniteDuration
我需要使用不同的导入:
导入scala.concurrent.duration.\ucode>
我的问题是:这是一个好的图书馆设计吗?我认为第三方库设计者可能会坚持Scala中已有的方法。但可能有一些详细的原因来实现Span
模拟持续时间
注:我确实认为Bill Venner的ScalaTest是一个很棒的库:)