在 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/