have_time_tag.rb 917 B

12345678910111213141516171819202122232425262728293031323334353637
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module HaveTimeTag
  3. extend RSpec::Matchers::DSL
  4. matcher :have_time_tag do
  5. match do |actual|
  6. actual.has_css?('time', **args) { |elem| elem[:datetime] == expected.utc.iso8601 || elem[:datetime] == expected.utc.iso8601(3) } # handle JS version with miliseconds too
  7. end
  8. def args
  9. hash = {}
  10. hash[:text] = @display if @display.present?
  11. hash
  12. end
  13. chain :displayed_as do |display|
  14. @display = display
  15. end
  16. failure_message do |actual|
  17. "Expected #{actual} to include #{@display || expected}"
  18. end
  19. failure_message_when_negated do |actual|
  20. "Expected #{actual} to not include published time element"
  21. end
  22. match_when_negated do |actual|
  23. actual.has_no_css?('time')
  24. end
  25. end
  26. end
  27. RSpec.configure do |config|
  28. config.include HaveTimeTag, type: :system
  29. end