模块 Kernel
Kernel
的 minitest 扩展
私有实例方法
describe(desc, *additional_desc, &block) 点击切换源码
描述给定目标 desc
的一系列期望。
定义一个测试类,该测试类是 Minitest::Spec
的子类,或者是周围 describe 类的子类。周围的类可以手动继承 Minitest::Spec
,以便轻松共享代码
class MySpec < Minitest::Spec # ... shared code ... end class TestStuff < MySpec it "does stuff" do # shared code available here end describe "inner stuff" do it "still does stuff" do # ...and here end end end
有关开始编写 spec 的更多信息,请参阅
www.rubyinside.com/a-minitestspec-tutorial-elegant-spec-style-testing-that-comes-with-ruby-5354.html
有关如何改进 spec 的一些建议,请尝试
但请注意,其中的一些条目是有争议的,或者特定于 rspec。
有关期望的更多信息,请参阅 Minitest::Expectations
。
# File minitest-5.25.4/lib/minitest/spec.rb, line 82 def describe desc, *additional_desc, &block # :doc: stack = Minitest::Spec.describe_stack is_spec_class = Class === self && kind_of?(Minitest::Spec::DSL) name = [stack.last, desc, *additional_desc] name.prepend self if stack.empty? && is_spec_class sclas = stack.last \ || (is_spec_class && self) \ || Minitest::Spec.spec_type(desc, *additional_desc) cls = sclas.create name.compact.join("::"), desc stack.push cls cls.class_eval(&block) stack.pop cls end