Rspec/capybara - test presence of a class OR another class

Viewed 8485

In my ruby on Rails 4.2 app, on a page I have a conditional back end rule that translates into the page front end in a change in class

<div id="content">
    <i class='<% if x=true %>glyphicon glyphicon-thumbs-down<% else> glyphicon glyphicon-thumbs-up ><% end %>' </i>
       this is the message.
</div>

How to check presence with rspec 3/capybara that the page contains the class glyphicon-thumbs-down OR the class glyphicon-thumbs-up ?

I tried the code below but it fails:

it "should sheck one of the 2 classes presence" do
  expect(page).to have_css '.glyphicon-thumbs-down' || expect(page).to have_css '.glyphicon-thumbs-up'
end

I am getting the following error message:

syntax error, unexpected tIDENTIFIER, expecting keyword_end (SyntaxError)
4 Answers

Maybe you can try to use option :count, in expect method like this:

it 'should contains 2 same selector' do
  expect(page).to have_css '.some-class', count: 2
end
Related