def test_contacts(flag: true)
describe "sidebar with contacts" do
it { (:flag ? should : should_not) have_content('phone: ') }
end
end
So much is wrong with this code:
:flag
is always truthy, since it is a symbol. If you want to check if the value passed ittrue
you should useflag
(the variable), not:flag
(the symbol)should
andshould_not
are methods, so actually you need to call eithershould(have_content('phone: ')
orshould_not(have_content('phone: ')
- you can't separate the method call from the variables you send it.
So, inside your describe your code should look like:
it { flag ? should(have_content('phone: ')) : should_not(have_content('phone: ') }
Beside this, I've never seen this kind of pattern for writing rspec test cases, and I'm pretty sure you are better off using better idioms like shared_examples_for