我想在before(:all)方法中显示测试组名称(和祖先):
describe "My awesome app" do before(:all) do puts running_example_group.Metadata[:full_description] # <- what I'm imagining ... done ... describe "awesome widget" do before (:all) do puts running_example_group.Metadata[:full_description] # <- what I'm imagining ... done ... done done
这个想法会产生输出:
My awesome app My awesome app awesome widget
这个数据在“it”子句中可用,但是我以前不能(…).是不是可用?我只是犯了一个愚蠢的错误?
解决方法
在一个before(:all)块之前,没有“运行示例”,但您仍然可以通过RSpec :: Core :: ExampleGroup访问元数据.以下是可以从各种范围访问元数据的示例:
describe "My app",js: true do context "with js set to #{Metadata[:js]}" do before :all do puts "in before block: js is set to #{self.class.Metadata[:js]}" end it "works" do puts "in example: js is set to #{example.Metadata[:js]}" end end end
有关更多信息,请查看this comment in rspec/rspec-core#42.