ruby - 为什么为 describe 执行 before(:context) ?理想情况下,它应该在规范中的 Context 之前执行
问题描述
我想执行一个应该在规范中执行 before(:context) 的代码。
我的规格文件:
describe "" do
context 'test context' do
it 'test' do
end
end
end
我的规范 helper.rb 文件:
RSpec.configure do |config|
config.before(:context) do |example|
\\ some code which should be executed before context but getting executed during decribe
end
end
有什么方法可以执行仅在 before(:context) 上运行的代码
解决方案
您可以使用Filters > Use symbols as metadata中所示的过滤器,例如:
RSpec.configure do |config|
config.before(:context, :before_context) do |example|
# ...
end
end
只有context
/describe
指定该过滤器的块将使用它:
describe "" do
context 'test context', :before_context do
it 'test' do
# ...
end
end
end
请注意,这:before_context
只是一个示例,您可以使用任何符号。
推荐阅读
- python - python贷款计算器中运行时的计算错误
- nginx - 如何为 minikube 启用旧版本的 NGINX 入口
- python - 当 val 是列表时如何格式化输出?
- node.js - Node.js // 我想要一个函数等待一个变量,直到它运行
- python - 从更大的列表列表中提取列表列表
- spring-boot - 模板解析时出错(springboot+thymeleaf)
- javascript - 使用 Fetch 方法动态创建单个卡片
- python - 如何使用两个列表将数据附加到 df 索引
- python - Plotly Polar Bar Plot - 设置自定义 theta 单位
- regex - 如何在正则表达式中有异常?