I want to make sure that the item on my website only displays when I log in.
Here is how I am achieving this at the moment:
it 'displays statistics when logged in' do
expect {
login_as(create :user)
refresh_page
}.to change {
page.has_content? 'Statistics'
}.from(false).to true
end
It somehow seems awkward. Especially when the specification fails, I donβt get the error message that I usually get on execution expect(page).to have_content 'Statistics', I just get something like βthe expected result, which changed from false to true but did not changeβ, which isnβt very informative .
I know that there are common examples, but they feel too much for this occasion.
I tried something like the following, but failed:
it 'displays statistics when logged in' do
expect(expect_to_have_content_statistics).to raise_error
login_as(create :user)
refresh_page
expect_to_have_content_statistics
end
def expect_to_have_content_statistics
expect(page).to have_content 'Statistics'
end
Any ideas? I do not want to write the wait 2 times, as this is very error prone.
source
share