Search code examples
curlserverspec

How to use or condition in serverspec?


I have a website to be tested for status code, Using curl command to get the status code of the website. Sometimes it is giving 200 and 302 status codes. I am using serverspec to test the website status code. As I am getting 2 status code, I want to use 'or' condition to get it done. How could I use it. Here is my Serverspec test case.

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

This one is giving error for me.


Solution

  • I have never seen an or in serverspec. But maybe just solve this in the command itself:

    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