gpt4 book ai didi

ruby - 如何获取 RSpec 的当前上下文名称?

转载 作者:数据小太阳 更新时间:2023-10-29 06:32:12 26 4
gpt4 key购买 nike

如果我有这样的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”?

它类似于 specdocs 的格式,但如何将其放入自身?

最佳答案

RSpec.describe 'Foo' do
describe 'Sub-Foo' do
# NOTE: `self.` context is also available within subject { } block

it 'should Bar' do |example|
expect(self.class.description).to eq('Sub-Foo')
expect(example.description).to eq('should Bar')

expect(self.class.top_level_description).to eq('Foo')
end
end
end

关于ruby - 如何获取 RSpec 的当前上下文名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1518264/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com