Sha256: 7139fd11589485b59ec48613382458fe9087c2c69ba21660b0053aa0f124465a

Contents?: true

Size: 1.5 KB

Versions: 3

Compression:

Stored size: 1.5 KB

Contents

require 'spec_helper'

require 'mailgun'
require 'mailgun/address'

vcr_opts = { :cassette_name => "email_validation" }

describe 'For the email validation endpoint', order: :defined, vcr: vcr_opts do
  before(:all) do
    @mg_obj = Mailgun::Address.new(PUB_APIKEY)

    @valid = ["Alice <alice@example.com>", "bob@example.com"]
    @invalid = ["example.org"]

    @all_addrs = @valid + @invalid
  end

  it 'returns parsed and unparsable lists' do
    res = @mg_obj.parse(@all_addrs)

    expect(res["parsed"]).to eq(@valid)
    expect(res["unparseable"]).to eq(@invalid)
  end

  it 'validates alice@mailgun.net with info' do
    res = @mg_obj.validate("alice@mailgun.net")

    expected = {
        "address" => "alice@mailgun.net",
        "did_you_mean" => nil,
        "is_valid" => true,
        "parts" => {
            "display_name" => nil,
            "domain" => "mailgun.net",
            "local_part" => "alice",
        },
    }
    expect(res).to eq(expected)
  end

  it 'performs mailbox validation for alice@mailgun.net' do
    res = @mg_obj.validate("alice@mailgun.net", true)

    expect(res["mailbox_verification"]).to eq("true")
  end

  it 'fails to validate example.org' do
    res = @mg_obj.validate("example.org")

    expected = {
        "address" => "example.org",
        "did_you_mean" => nil,
        "is_valid" => false,
        "parts" => {
            "display_name" => nil,
            "domain" => nil,
            "local_part" => nil,
        },
    }
    expect(res).to eq(expected)
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mailgun-ruby-1.1.10 spec/integration/email_validation_spec.rb
mailgun-ruby-1.1.9 spec/integration/email_validation_spec.rb
mailgun-ruby-1.1.8 spec/integration/email_validation_spec.rb