rspec 中上下文的条件过滤器?
Conditional filters for contexts in rspec?
有没有办法为 rspec 中的上下文设置条件过滤器?
我有一个上下文,其中的变量仅在特定变量 != 1 时才有效,因此我想将其用作该上下文测试的过滤器。我无法在测试本身上使用过滤器,因为我正在使用所述变量来设置该测试的上下文(理想状态见下文):
context 'if interval is not 1 every non interval day', :if => Reminders::INTERVAL != 1 do
num = rand(0..100)
non_limbo = num + num/(Reminders::INTERVAL - 1) + 1
let!(:evaluation) { create(:evaluation, created_at: non_limbo.days.ago) }
it 'doesn't send an email' do
expect { subject }.to change { ActionMailer::Base.deliveries.count }.by(0)
end
end
您可以将整个上下文包围在一个条件中:
if Reminders::INTERVAL != 1
context 'if interval...' do
# ...
end
end
有没有办法为 rspec 中的上下文设置条件过滤器?
我有一个上下文,其中的变量仅在特定变量 != 1 时才有效,因此我想将其用作该上下文测试的过滤器。我无法在测试本身上使用过滤器,因为我正在使用所述变量来设置该测试的上下文(理想状态见下文):
context 'if interval is not 1 every non interval day', :if => Reminders::INTERVAL != 1 do
num = rand(0..100)
non_limbo = num + num/(Reminders::INTERVAL - 1) + 1
let!(:evaluation) { create(:evaluation, created_at: non_limbo.days.ago) }
it 'doesn't send an email' do
expect { subject }.to change { ActionMailer::Base.deliveries.count }.by(0)
end
end
您可以将整个上下文包围在一个条件中:
if Reminders::INTERVAL != 1
context 'if interval...' do
# ...
end
end