rspec 挂钩中当前示例/组的名称
我添加了一个 rspec 挂钩,它允许我打开录像机并使用当前示例的名称作为磁带名称。
it "should have collaborators", :vcr => :once do
# web interactions
end
config.around(:each, :vcr => :once) do |example|
VCR.use_cassette(example.name, :record => :once) do
example.call
end
end
问题是我不知道如何获取当前示例的名称(example.name 不起作用)。
I'm adding an rspec hook that will allow me to switch on vcr and use the name of the current example as the cassette name.
it "should have collaborators", :vcr => :once do
# web interactions
end
config.around(:each, :vcr => :once) do |example|
VCR.use_cassette(example.name, :record => :once) do
example.call
end
end
trouble is I don't know how to get the name of the current example (example.name doesn't work).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
RSpec 定义了一个元数据方法,该方法返回一个哈希值,其中包含有关示例的一些有用信息。您可以尝试:
它应该返回组和示例名称,并连接成一个字符串。
RSpec defines a
metadata
method that returns a hash with some useful information about the example. You might try:which should return the group(s) and example name, concatenated into one string.
这看起来有点繁琐,但它确实有效
This seems a bit fiddly but it does the job