How to get current context name of rspec?

穿精又带淫゛_ 提交于 2021-02-07 11:17:16

问题


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

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

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


回答1:


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

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



来源:https://stackoverflow.com/questions/1518264/how-to-get-current-context-name-of-rspec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!