-
-
Save bravoecho/1985730 to your computer and use it in GitHub Desktop.
RSpec shared examples for ActiveModel::Lint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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