public
Last active

  • Download Gist
pirate_validator.rb
Ruby
1 2
class PirateValidator < ActiveModel::Validator
end
pirate_validator_spec.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
require 'active_model'
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
 
end

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. :)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.