Skip to content

@jeffkreeftmeijer /pirate_validator.rb
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
class PirateValidator < ActiveModel::Validator
def validate(document)
end
end
require 'active_model'
require 'rspec/rails/extensions'
require File.expand_path('app/validators/pirate_validator')
class Validatable
include ActiveModel::Validations
validates_with PirateValidator
end
describe PirateValidator do
subject { Validatable.new }
context 'with a comment that sounds like a pirate' do
before { subject.stub(:comment).and_return('Ahoy, matey!') }
it { should be_valid }
end
context 'with a comment that sounds like a dinosaur' do
before { subject.stub(:comment).and_return('ROOOAAAR!') }
it { should have(1).error_on(:comment) }
end
end
@jeffkreeftmeijer

Don't want to load up spec/rails/extensions? Put validations.rb in your support directory and require 'support/validations' instead. It saves me ~ 2 seconds. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.