Sha256: 33a5178017240c47fc1b1add84d705cf9aa70f52ec7e1fafd8e51b5de206a2fd

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

require 'spec_helper'

describe EmailFormatValidator do

  let(:fake_model) { FakeModel.new }

  context "with valid emails" do

    let(:valid_emails) { %w(valid@email.com another.valid@email.email.net) }

    it "should be happy" do
      valid_emails.each do |email|
        fake_model.email = email
        expect(fake_model.valid?).to be_true
      end
    end
  end

  context "with invalid emails" do

    let(:invalid_emails) { %w(invalid_email@
                              another_invalid_email@@email.email
                              invalid
                              bad@email@here
                              @bad_email
                              another@bad,email) }

    it "shouldn't be happy" do
      invalid_emails.each do |email|
        fake_model.email = email
        expect(fake_model.valid?).to be_false
      end
    end
  end

  context "with allow_blank: true" do

    let(:fake_model)   { FakeModelWithBlankEmail.new }
    let(:blank_emails) { ['', nil, ' '] }

    it "should allow blank emails" do
      blank_emails.each do |blank_email|
        fake_model.email = blank_email
        expect(fake_model.valid?).to be_true
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
email_format-0.0.2 spec/email_format_validator_spec.rb