如何在serverspec中使用或条件?

How to use or condition in serverspec?

我有一个网站需要测试状态码,使用curl命令获取网站的状态码。有时它会给出 200 和 302 状态代码。 我正在使用 serverspec 来测试网站状态代码。 当我收到 2 个状态代码时,我想使用 'or' 条件来完成它。 我怎么能用它。 这是我的 Serverspec 测试用例。

describe command('curl -IL --retry 4 "www.example.com"') do
  its(:stdout) { should match '200' or '302' }
end

这个对我来说是错误的。

我在 serverspec 中从未见过 。但也许只是在命令本身中解决这个问题:

describe command('curl -sL -w "%{http_code}\n" "www.example.com" -o /dev/null | sed "s/200/OK/" | sed "s/302/OK/"') do
  its(:stdout) { should match 'OK' }
end