如何获取rspec的当前上下文名称? [英] How to get current context name of rspec?

查看:36
本文介绍了如何获取rspec的当前上下文名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有这样的 rspec

if i have rspec like this

describe 'Foo' do
   // init go here
   describe 'Sub-Foo' do
      it "should Bar" do
         // test go here
         // puts ... <-- need "Foo.Sub-Foo should Bar" here 
      end
   end
end

如何在//test go here 的测试上下文中获得Foo.Sub-Foo should Bar"?

How can i get "Foo.Sub-Foo should Bar" inside the test context at // test go here?

它类似于specdocs的格式,但如何将其内部化?

It is similar to format with specdocs, but how to get it inside itself?

推荐答案

describe 'Foo' do
   describe 'Sub-Foo' do
      it "should Bar" do |example|
         puts "#{self.class.description} #{example.description}"
      end
   end
end

上面的代码打印出Foo Sub-Foo should Bar".

The above code prints out "Foo Sub-Foo should Bar".

这篇关于如何获取rspec的当前上下文名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆