ruby - Minitest 有 RSpec 的任何版本吗?

标签 ruby minitest

在 RSpec 中,我可以执行 mock_obj.should_receive(:method).with(anything)... 其中“anything”是任何变量。

我可以在 Minitest 中执行此操作吗?

最佳答案

Minitest ,因为它包含在 Ruby 1.9 中,所以提供了 MiniTest::Spec,一种类似上下文 RSpec 的语法。这不是 RSpec。

来自 Github 页面,这就是 Minitest提供

  • minitest/autorun - the easy and explicit way to run all your tests.
  • minitest/unit - a very fast, simple, and clean test system.
  • minitest/spec - a very fast, simple, and clean spec system.
  • minitest/mock - a simple and clean mock/stub system.
  • minitest/benchmark - an awesome way to assert your algorithm's performance.
  • minitest/pride - show your pride in testing!
  • Incredibly small and fast runner, but no bells and whistles.

要执行与mock_obj.should_receive(:method).with(anything) 相同的操作,您将编写

需要'minitest/autorun'

describe YourClass do
  it 'should receive a call to method' do
    mock_obj = Minitest::Mock.new
    mock_obj.expect(:method, :your_return, [anything])
    # ...
    mock_obj.verify # verify that the expected call has been made
  end
end

关于ruby - Minitest 有 RSpec 的任何版本吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16136823/

相关文章:

ruby-on-rails - 如何通过 Rails 控制台测试 Rails 方法

ruby - `gets.chomp.downcase!` 获取空字符串错误

ruby-on-rails - 最小测试和测试::单元

ruby - 如何使用 Rspec Mocks stub 给定类的任何实例

ruby - 模拟时,如何返回传入的参数之一?

ruby-on-rails - Guard-Minitest + Spring 未按预期工作

ruby - :method: notation supposed to do for ruby docs?到底是什么

ruby-on-rails - Rails4 rails-api 测试 : undefined session_serializer when testing auth via headers token

ruby-on-rails - 获取访问 token !在 Google API 中—— "Missing authorization code."

ruby - 使用 Guard 忽略目录