RSpec::Matchers.define :have_image do |image_name, alt: nil|
match do |actual|
result = expect(actual).to have_xpath "//img[contains(@src, '#{image_name}')]"
result &&= expect(actual).to have_xpath "//img[@alt='#{alt}']" if alt
result
end
end
RSpec::Matchers.define :have_current_path_with_hash do |expected_path|
match do |actual|
uri = URI.parse(actual.current_url)
expect(uri.path_with_hash).to eq expected_path
end
end
RSpec::Matchers.define :have_current_path_query do |expected_path_query|
match do |actual|
actual_path_query = CGI.parse(actual.current_url.sub(/\A.*\?/, ''))
expect(actual_path_query).to match expected_path_query
end
end
RSpec::Matchers.define :have_toaster do |type: nil, title: nil, message: nil|
match do |actual|
css_class = type ? ".toast.toast-#{type}" : '.toast'
result = expect(actual).to have_css css_class
result &&= expect(actual.find("#{css_class} > .toast-title")).to have_content title if title
result &&= expect(actual.find("#{css_class} > .toast-message")).to have_content message if message
result
end
end