email_address_validation_spec.rb 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. require 'rails_helper'
  2. RSpec.describe EmailAddressValidation do
  3. describe 'Valid email address' do
  4. describe 'with dot in domain' do
  5. describe 'with MX record' do
  6. let(:email_address) { 'greetings@example.com' }
  7. let(:email_address_validation) { described_class.new(email_address) }
  8. it 'reports given email address' do
  9. expect(email_address_validation.email_address).to eq(email_address)
  10. expect(email_address_validation.to_s).to eq(email_address)
  11. end
  12. it 'reports email address as valid' do
  13. expect(email_address_validation.valid_format?).to be(true)
  14. end
  15. it 'reports email address to have domain with MX record' do
  16. expect(email_address_validation.valid_mx?).to be(true)
  17. end
  18. end
  19. describe 'without MX record' do
  20. let(:email_address) { 'someone@this-is-probably-a-non-existent-domain.com.example' }
  21. let(:email_address_validation) { described_class.new(email_address) }
  22. it 'reports given email address' do
  23. expect(email_address_validation.email_address).to eq(email_address)
  24. expect(email_address_validation.to_s).to eq(email_address)
  25. end
  26. it 'reports email address as valid' do
  27. expect(email_address_validation.valid_format?).to be(true)
  28. end
  29. it 'reports email address to have domain without MX record' do
  30. expect(email_address_validation.valid_mx?).to be(false)
  31. end
  32. end
  33. end
  34. describe 'without dot in domain' do
  35. let(:email_address) { 'greetings@localhost' }
  36. let(:email_address_validation) { described_class.new(email_address) }
  37. it 'reports given email address' do
  38. expect(email_address_validation.email_address).to eq(email_address)
  39. expect(email_address_validation.to_s).to eq(email_address)
  40. end
  41. it 'reports email address as valid' do
  42. expect(email_address_validation.valid_format?).to be(true)
  43. end
  44. it 'reports email address to have domain without MX record' do
  45. expect(email_address_validation.valid_mx?).to be(false)
  46. end
  47. end
  48. end
  49. describe 'Email address' do
  50. describe 'without domain' do
  51. let(:email_address) { 'zammad' }
  52. let(:email_address_validation) { described_class.new(email_address) }
  53. it 'reports given email address' do
  54. expect(email_address_validation.email_address).to eq(email_address)
  55. expect(email_address_validation.to_s).to eq(email_address)
  56. end
  57. it 'reports email address as invalid' do
  58. expect(email_address_validation.valid_format?).to be(false)
  59. end
  60. it 'reports email address to have domain without MX record' do
  61. expect(email_address_validation.valid_mx?).to be(false)
  62. end
  63. end
  64. describe 'with invalid domain format' do
  65. let(:email_address) { 'greetings@example..com' }
  66. let(:email_address_validation) { described_class.new(email_address) }
  67. it 'reports given email address' do
  68. expect(email_address_validation.email_address).to eq(email_address)
  69. expect(email_address_validation.to_s).to eq(email_address)
  70. end
  71. it 'reports email address as invalid' do
  72. expect(email_address_validation.valid_format?).to be(false)
  73. end
  74. it 'reports email address to have domain without MX record' do
  75. expect(email_address_validation.valid_mx?).to be(false)
  76. end
  77. end
  78. describe 'which is empty' do
  79. let(:email_address) { '' }
  80. let(:email_address_validation) { described_class.new(email_address) }
  81. it 'reports given email address' do
  82. expect(email_address_validation.email_address).to eq(email_address)
  83. expect(email_address_validation.to_s).to eq(email_address)
  84. end
  85. it 'reports email address as invalid' do
  86. expect(email_address_validation.valid_format?).to be(false)
  87. end
  88. it 'reports email address to have domain without MX record' do
  89. expect(email_address_validation.valid_mx?).to be(false)
  90. end
  91. end
  92. end
  93. end