ruby - 如何将消息附加到 RSpec 检查?

标签 ruby tdd rspec xunit

在 RSpec 中:我可以像在 xUnit 风格的测试框架中那样将消息附加到支票上吗?怎么办?

assert_equal value1, value2, 'something is wrong'

最佳答案

对于 RSpec 3+:

消息可以自定义为字符串或使用 proc(查看引用资料)。

expect(1).to eq(2), 'one is not two!'

Customized message RSpec tries to provide useful failure messages, but for cases in which you want more specific information, you can define your own message right in the example. This works for any matcher other than the operator matchers.

source @ relishapp


对于旧的 RSpec 版本

shouldshould_not采用第二个参数 (message) 覆盖匹配器的默认消息。

1.should be(2), 'one is not two!'

不过,默认消息通常非常有用。

关于ruby - 如何将消息附加到 RSpec 检查?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4183656/

相关文章:

ruby-on-rails - 如何从其他类( Controller 外部)调用 send_data 和 send_file

ruby-on-rails - 浮点乘法的 Ruby 奇怪问题

c# - 使用 Mocks 验证依赖调用时的 TDD Arrange Act Assert 模式

ruby-on-rails - Rails3.1 中的测试非常慢。有某种解决方案可以更快地加载测试吗?

ruby - 在 Capybara Webkit 测试中将 Ctrl-S 发送到浏览器

ruby - "each"在ruby中使用'for each'的函数实现

ruby - 我可以使用默认值在 Ruby 中创建数组吗?

tdd - 关于 SOLID/TDD 的问题

ruby-on-rails - RSpec 测试失败,方法未定义 `respond_with'

ruby-on-rails - Devise::TestHelpers 文档不清楚 Devise.mappings[:mapping] 的用法