serverspec - can 'should_be_owned_by' chec

2019-08-12 17:33发布

问题:

I'm new to ServerSpec, Rspec, ruby so don't have much knowledge of the specifics of the grammar available. I'd like to write a test that does something like:

describe file("foo") do
    it { should_be_owned_by 'bill' or 'ted' }
end

That test runs but seems to only check the first owner and not the second.

Is there a standard way to perform a test where there may be multiple acceptable values?

Thanks

回答1:

I can not find it in the official file documentation, but you can use a grep regular expression pattern there:

describe file('foo') do
  it { should_be_owned_by 'bill\|ted' }
end

Since RSpec 3.0 you can also use .or to make compound expectations:

describe file('foo') do
  it { should be_owned_by('bill').or be_owned_by('ted') }
end


标签: serverspec