别名
describe
和 context
是 example_group
的默认别名。您可以为 example_group
定义自己的别名,并为这些自定义别名提供默认元数据。
RSpec 提供了一些内置别名
* `xdescribe` and `xcontext` add `:skip` metadata to the example group in
order to temporarily disable the examples.
* `fdescribe` and `fcontext` add `:focus` metadata to the example group in
order to make it easy to temporarily focus the example group (when
combined with `config.filter_run :focus`.)
具有元数据的自定义示例组别名
给定一个名为“nested_example_group_aliases_spec.rb”的文件,其中包含
RSpec.configure do |c|
c.alias_example_group_to :detail, :detailed => true
end
RSpec.detail "a detail" do
it "can do some less important stuff" do
end
end
RSpec.describe "a thing" do
describe "in broad strokes" do
it "can do things" do
end
end
detail "something less important" do
it "can do an unimportant thing" do
end
end
end
当我运行 rspec nested_example_group_aliases_spec.rb --tag detailed -fdoc
那么输出应包含
a detail
can do some less important stuff
a thing
something less important