'How to test for multiple possible outcomes with have_content?

I'm new to testing, so bear with me :)

I would like to test for random content on a page. For example, let's test the page for displaying the content either 'foo' or 'bar'.

Something like the below is what I'm trying to achieve

page.should (have_content('foo') || have_content('bar'))

Any ideas?



Solution 1:[1]

I had this same question but realized it's probably easier & more resilient to add an if statement to your spec.

it 'can complete my incredible form' do
  visit '/testing_path'
  #...dostuff...

  if object_im_testing.contains_my_condition?
    current_path.should eq('/special_condition_url')
  else
    current_path.should eq('/normal_condition_url')
  end
end

Hope this helps w/ another perspective. Simplest solution is usually the best.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1