Skip to content

Instantly share code, notes, and snippets.

@bravoecho
Forked from mikegehard/active_model_lint.rb
Created March 6, 2012 11:17
Show Gist options
  • Save bravoecho/1985730 to your computer and use it in GitHub Desktop.
Save bravoecho/1985730 to your computer and use it in GitHub Desktop.
RSpec shared examples for ActiveModel::Lint
# adapted from rspec-rails http://github.com/rspec/rspec-rails/blob/master/spec/rspec/rails/mocks/mock_model_spec.rb
# put this in a file in your spec/support directory, or add the code to the spec_helper.rb
# USAGE:
#
# context "ActiveModel Lint" do
# it_behaves_like "an ActiveModel", YourModel.new
# end
shared_examples "an ActiveModel" do |model|
require 'test/unit/assertions'
require 'active_model/lint'
include Test::Unit::Assertions
include ActiveModel::Lint::Tests
active_model_lints = ActiveModel::Lint::Tests.public_instance_methods.map(&:to_s).grep(/^test/)
let(:model) { model }
active_model_lints.each do |test_name|
it "#{test_name.sub(/^test_/, '')}" do
send(test_name)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment