Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.