custom_matchers.rb 738 B

1234567891011121314151617181920212223242526272829303132
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. # taken from https://makandracards.com/makandra/1080-rspec-matcher-to-check-if-an-activerecord-exists-in-the-database
  3. RSpec::Matchers.define :exist_in_database do
  4. match do |actual|
  5. actual.class.exists?(actual.id)
  6. end
  7. end
  8. RSpec::Matchers.define :have_computed_style do
  9. match do
  10. actual_value == expected_value
  11. end
  12. failure_message do
  13. "Expected element to have CSS property #{expected_key} with value #{expected_value}. But it was #{actual_value}."
  14. end
  15. def expected_key
  16. expected[0]
  17. end
  18. def expected_value
  19. expected[1]
  20. end
  21. def actual_value
  22. actual.evaluate_script "getComputedStyle(this).#{expected_key}"
  23. end
  24. end