Skip to content

Instantly share code, notes, and snippets.

@shoyan
Created January 15, 2015 09:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shoyan/0954f9502a0d2c3015cb to your computer and use it in GitHub Desktop.
Save shoyan/0954f9502a0d2c3015cb to your computer and use it in GitHub Desktop.
test of EmailValidator.
require 'spec_helper'
describe "EmailValidator" do
before do
@validator = EmailValidator.new({:attributes => {email: ''}})
@mock = double("Foo")
allow(@mock).to receive(:errors).and_return([])
allow(@mock.errors).to receive(:[]).and_return({})
allow(@mock.errors[]).to receive(:<<)
end
it "should validate valid address" do
expect(@mock).not_to receive(:errors)
@validator.validate_each(@mock, "email", "test@test.com")
end
it "should validate invalid address" do
expect(@mock.errors[]).to receive(:<<)
@validator.validate_each(@mock, "email", "notvalid")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment