- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用 specs2 2.3.12
,Scala 2.11.6
。我在一个示例中看到类型不匹配错误,我觉得我从文档中得到了其他信息。代码如下:
val newUsers: Seq[(String, User)] = response.newUsers.toSeq
newUsers must contain((email: String, user: User) => (user.email.toString must be_==(email))).forall
我收到以下错误:
[error] <redacted>/UserSpec.scala:561: type mismatch;
[error] found : org.specs2.matcher.ContainWithResult[(String, com.nitro.models.User) => org.specs2.matcher.MatchResult[String]]
[error] required: org.specs2.matcher.Matcher[Seq[(String, com.nitro.models.User)]]
[error] newUsers must contain((email: String, user: User) => (user.email.toString must be_==(email))).forall
[error] ^
[error] one error found
[error] (api/test:compileIncremental) Compilation failed
[error] Total time: 2 s, completed Aug 3, 2015 10:07:04 AM
这些是 examples我在关注:
// contain matcher accepting a function
Seq(1, 2, 3) must contain((i: Int) => i must be_>=(2))
Seq(1, 2, 3) must contain(be_>(0)).forall // this will stop after the first failure
我绝对可以重写测试来绕过这个错误,但我想了解我哪里出错了。感谢您的指点!
最佳答案
这里发生了几件事。最重要的一点是,当您针对元组进行测试时,您的函数返回一个 MatchResult[String]
,编译器不会帮助您意识到这一点,因为如果你返回了一个 MatchResult[(String, User)]
。
您可以构建自己的 MatchResult
,但是(在我看来)您最好还是创建一个 Matcher[(String,User)]
,这真的很简单。
如果您将此添加到您的规范中:
def matchingEmail: Matcher[(String, User)] =
(pair: (String, User)) => (pair._1 == pair._2.email, s"email ${pair._1} did not match user ${pair._2}")
您可以简单地用 newUsers must contain(matchingEmail).forall
调用它
关于scala - Specs2:集合匹配器上的类型不匹配编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31793037/
Hi得到了一个对我来说似乎有效的YAML,但当应用它时它不起作用,我不知道它有什么问题。错误:。Kubeval部署.yaml通过,没有错误
当我通过“rake spec”运行它时,我的一个规范失败了,但当我使用 RSpec 可执行文件“spec”时,它通过了。当我在 ActionMailer View 中使用 url 帮助器时,规范失败。
我对码头公司还是个新手。我使用的是最新版本的Python、Django和Docker。我已经在这个项目上工作了两周了,我已经创建了docker-compose.yml文件,并且已经构建了我的docke
我正在遵循 clojure.spec 的指南 ( http://clojure.org/guides/spec )。我对序列规范的 alt 和 or 之间的差异感到困惑。 对我来说,以下两个示例同样有
当我在我的 Rails 项目中运行 rake spec 时,它会执行所有规范,然后尝试运行测试(如 rake test): $ rake spec ruby -S rspec ./spec/... #
Nestjs:如果 --no-spec 用于禁用规范文件生成,如何生成“spec.ts”文件。我需要测试完整的模块,但我没有 spec.ts 文件。是否有任何机制可以为现有模块生成这些文件。 最佳答案
我是 erlang 编程的新手。我有很多疑问。其中之一是使用-spec。 “-spec”在 Erlang 语法中有什么作用?使用或不使用 -spec 创建函数有什么区别 没有 -spec 的功能 ad
我需要验证已从 json 字符串转换的 clojure 映射的形状。 json 字符串是我正在实现的协议(protocol)的消息。 为此,我正在尝试 clojure.spec.alpha。 我正在使
有没有办法在另一个函数规范中引用一个函数的返回类型规范? defmodule Car do @spec beep(none()) :: String.t def beep do "be
出于学习目的,我正在尝试将 Chef 解释器项目转换为 python 3.4,并尝试将涉及的库转换为最新版本,但是当涉及到 funcparserlib 时,我有点不知所措。 这是 Chef 脚本: f
我正在将一堆旧脚本转换为 Jenkins 管道作业。对于我们的许多脚本,我们使用 JFrog CLI 来处理与 Artifactory 的所有交互。有了 Jenkins 管道,我们现在可以选择通过 A
我使用 RSpec 设置了一个新的 Rails 4 应用程序。但是运行时rake rspec ,所有示例都运行两次: rake spec [deprecated] I18n.enforce_avail
我有 Kubernetes 部署 的 list 。当我尝试从 Azure Devops 部署它时,出现以下错误: error: error validating "/home/vsts/work/r1
为什么使用 Combine(...) 保留空格,而 Keyword(...) 删除这些空格? 我需要保留匹配标记后面的空格。 测试如下: from pyparsing import * def par
以下是使用 time rspec spec 进行的 3 次随机运行对比time bundle exec spec在一个相当简单的 Rails 3 应用程序上。不使用 bundler 始终更快,并且它使
我修改了 Github 上的一个 repo 以集成我的库的 swift 版本。 https://github.com/iDevelopper/PBRevealViewController 然而,当我在
我在 Rails 3.2 上,我正在使用 rspec (2.11.1)。当我使用“rake spec”运行我的测试套件时,我会失败。当我用“rspec”运行它时,一切都过去了。我已经看到其他人提到这个
我正在第二次学习 Rails 教程。当我输入这个 rails generate integration_test static_pages 我得到 spec/rails_helper.rb 和 spe
我正在尝试通过 https 向服务器验证我的客户端应用程序 - 我正在使用 axis 1.4 jar。我将正确的 JKS 文件传递给信任库。但是,我收到以下异常。 Caused by: ja
我一直在尝试使用HELM UPGRADE创建POD: helm upgrade --values=$(System.DefaultWorkingDirectory)/_NAME-deploy-CI/d
我是一名优秀的程序员,十分优秀!