【问题标题】:How to get current context name of rspec?如何获取 rspec 的当前上下文名称?
【发布时间】:2009-10-05 04:27:01
【问题描述】:

如果我有这样的 rspec

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”?

它类似于带有规范文档的格式,但是如何将其放入自身?

【问题讨论】:

    标签: ruby-on-rails ruby rspec


    【解决方案1】:
    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”。

    【讨论】:

    • 这就是我要找的。谢谢
    • 尝试it "should Bar" do |example|,然后尝试example.description。 Guess RSpec 的 API 对此有所改变。更多内容请参见the docs
    猜你喜欢
    • 1970-01-01
    • 2022-11-18
    • 2016-11-02
    • 1970-01-01
    • 2012-02-11
    • 1970-01-01
    • 2020-04-22
    • 1970-01-01
    • 2012-05-11
    相关资源
    最近更新 更多