Expectations are not meant to be used in conditionals like this -- they communicate pass/fail by raising an exception or not rather than returning boolean values. So, just use the expression you've wrapped in `expect` directly in a conditional:
if @driver.find_element(:xpath, "//*[@href='/gallery/']").displayed?