diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..129d139 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,7 @@ +language: ruby +sudo: false +rvm: + - 1.9.3 + - 2.0.0 + - 2.1.5 + - 2.2.0 diff --git a/Gemfile b/Gemfile index 803f95f..6f76f14 100644 --- a/Gemfile +++ b/Gemfile @@ -7,7 +7,7 @@ gemspec SOURCE = ENV.fetch('SOURCE', :git).to_sym REPO_POSTFIX = SOURCE == :path ? '' : '.git' DATAMAPPER = SOURCE == :path ? Pathname(__FILE__).dirname.parent : 'http://github.com/datamapper' -DM_VERSION = '~> 1.3.0.beta' +DM_VERSION = '~> 1.2' RAILS_VERSION = [ '>= 3.0', '< 5.0' ] CURRENT_BRANCH = ENV.fetch('GIT_BRANCH', 'master') @@ -16,11 +16,6 @@ gem 'activemodel', RAILS_VERSION, :require => nil group :development do gem 'dm-validations', DM_VERSION, SOURCE => "#{DATAMAPPER}/dm-validations#{REPO_POSTFIX}", :branch => CURRENT_BRANCH - - gem 'jeweler', '~> 1.6.4' - gem 'rake', '~> 0.9.2' - gem 'rspec', '~> 1.3.2' - gem 'test-unit', '= 1.2.3' end platforms :mri_18 do @@ -39,9 +34,7 @@ group :datamapper do plugins = plugins.to_s.tr(',', ' ').split.uniq plugins.each do |plugin| - gem plugin, DM_VERSION, - SOURCE => "#{DATAMAPPER}/#{plugin}#{REPO_POSTFIX}", - :branch => CURRENT_BRANCH + gem plugin, DM_VERSION, SOURCE => "#{DATAMAPPER}/#{plugin}#{REPO_POSTFIX}", :branch => CURRENT_BRANCH end end diff --git a/dm-active_model.gemspec b/dm-active_model.gemspec index 14b8cdc..812e479 100644 --- a/dm-active_model.gemspec +++ b/dm-active_model.gemspec @@ -7,6 +7,7 @@ Gem::Specification.new do |gem| gem.summary = "active_model compliance for datamapper" gem.description = 'A datamapper plugin for active_model compliance and thus rails 3 compatibility.' gem.homepage = "http://datamapper.org" + gem.license = 'MIT' gem.files = `git ls-files`.split("\n") gem.test_files = `git ls-files -- {spec}/*`.split("\n") @@ -19,7 +20,8 @@ Gem::Specification.new do |gem| gem.add_runtime_dependency('dm-core', '~> 1.2', '>= 1.2.0') gem.add_runtime_dependency('activemodel', '>= 3.0', '< 5.0') - gem.add_development_dependency('rake', '~> 0.9.2') - gem.add_development_dependency('rspec', '~> 1.3.2') + gem.add_development_dependency('dm-validations', '~> 1.2') + gem.add_development_dependency('rake', '~> 10.0') + gem.add_development_dependency('rspec', '~> 3.0') gem.add_development_dependency('test-unit', '= 1.2.3') end diff --git a/lib/dm-active_model.rb b/lib/dm-active_model.rb index 9d295eb..e33f0a6 100644 --- a/lib/dm-active_model.rb +++ b/lib/dm-active_model.rb @@ -1,5 +1,6 @@ require 'dm-core' require 'active_support/core_ext/module/delegation' # needed by active_model/naming +require 'active_support/core_ext/module/remove_method' # needed for Module.remove_possible_method in active_model/naming.rb (active_model ~> 4.1) require 'active_support/concern' # needed by active_model/conversion require 'active_model/naming' require 'active_model/conversion' diff --git a/spec/amo_interface_compliance_examples.rb b/spec/amo_interface_compliance_examples.rb new file mode 100644 index 0000000..191c70f --- /dev/null +++ b/spec/amo_interface_compliance_examples.rb @@ -0,0 +1,10 @@ +RSpec.shared_examples_for 'an active_model compliant object' do + + include ActiveModel::Lint::Tests + + instance_methods.grep(/^test_/).each do |meth| + it meth.to_s do + send(meth) + end + end +end diff --git a/spec/amo_interface_compliance_spec.rb b/spec/amo_interface_compliance_spec.rb deleted file mode 100644 index 2b7df48..0000000 --- a/spec/amo_interface_compliance_spec.rb +++ /dev/null @@ -1,45 +0,0 @@ -require 'spec/test/unit' -require 'active_support/core_ext/object/blank' # needed by active_model/lint -require 'active_model/lint' -require 'active_support/core_ext/string' - -# This must be kept in sync with active_model/lint tests -# at least for as long as -# -# http://rspec.lighthouseapp.com/projects/5645/tickets/900 -# -# isn't resolved in some way (probably with rspec2) - -share_examples_for 'an active_model compliant object' do - - include ActiveModel::Lint::Tests - - it 'must implement the #to_key interface' do - test_to_key - end - - it 'must implement the #to_param interface' do - test_to_param - end - - it 'must implement the #to_partial_path interface' do - test_to_partial_path if respond_to?(:test_to_partial_path) - end - - it 'must implement the #valid? interface' do - test_valid? if respond_to?(:test_valid?) - end - - it 'must implement the #persisted? interface' do - test_persisted? - end - - it 'must implement the .model_name interface' do - test_model_naming - end - - it 'must implement the #errors interface' do - test_errors_aref - test_errors_full_messages if respond_to?(:test_errors_full_messages) - end -end diff --git a/spec/amo_validation_compliance_spec.rb b/spec/amo_validation_compliance_examples.rb similarity index 66% rename from spec/amo_validation_compliance_spec.rb rename to spec/amo_validation_compliance_examples.rb index fd61bf9..bd8d733 100644 --- a/spec/amo_validation_compliance_spec.rb +++ b/spec/amo_validation_compliance_examples.rb @@ -1,8 +1,4 @@ -require 'spec/test/unit' -require 'lib/amo_lint_extensions' - -share_examples_for 'an active_model/validations compliant object' do - +RSpec.shared_examples_for 'an active_model/validations compliant object' do include ActiveModel::Lint::Tests::Validations ActiveModel::Lint::Tests::Validations::VALIDATION_METHODS.each do |validation_method| diff --git a/spec/dm-active_model_spec.rb b/spec/dm-active_model_spec.rb index ccd3f1b..1850a3e 100644 --- a/spec/dm-active_model_spec.rb +++ b/spec/dm-active_model_spec.rb @@ -1,17 +1,7 @@ -require 'dm-core' -require 'dm-active_model' - -require 'amo_interface_compliance_spec' - -if ENV['DM_VALIDATIONS'] || ENV['AMO_VALIDATIONS'] - require 'dm-validations' - require 'amo_validation_compliance_spec' -end - -describe 'An active_model compliant DataMapper::Resource' do +require 'spec_helper' +RSpec.describe 'An active_model compliant DataMapper::Resource' do before :all do - module ::ComplianceTest class ProfileInfo include DataMapper::Resource @@ -21,17 +11,15 @@ class ProfileInfo end DataMapper.setup(:default, { :adapter => :in_memory }) - end before :each do @model = ComplianceTest::ProfileInfo.new.to_model end - it_should_behave_like 'an active_model compliant object' + include_examples 'an active_model compliant object' if ENV['AMO_VALIDATIONS'] == 'true' - it_should_behave_like 'an active_model/validations compliant object' + include_examples 'an active_model/validations compliant object' end - end diff --git a/spec/spec.opts b/spec/spec.opts deleted file mode 100644 index e0f74bb..0000000 --- a/spec/spec.opts +++ /dev/null @@ -1,2 +0,0 @@ ---format specdoc ---colour diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..ad6842a --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,20 @@ +require 'rspec' +require 'test/unit/assertions' + +require 'dm-core' +require 'dm-active_model' + +require 'active_support/core_ext/object/blank' # needed by active_model/lint +require 'active_model/lint' + +require 'amo_interface_compliance_examples' + +if ENV['DM_VALIDATIONS'] || ENV['AMO_VALIDATIONS'] + require 'dm-validations' + require 'lib/amo_lint_extensions' + require 'amo_validation_compliance_examples' +end + +RSpec.configure do |config| + config.include Test::Unit::Assertions +end diff --git a/tasks/spec.rake b/tasks/spec.rake index 652b946..45a7860 100644 --- a/tasks/spec.rake +++ b/tasks/spec.rake @@ -1,38 +1,3 @@ -spec_defaults = lambda do |spec| - spec.pattern = 'spec/**/*_spec.rb' - spec.libs << 'lib' << 'spec' - spec.spec_opts << '--options' << 'spec/spec.opts' -end - -begin - require 'spec/rake/spectask' - - Spec::Rake::SpecTask.new(:spec, &spec_defaults) -rescue LoadError - task :spec do - abort 'rspec is not available. In order to run spec, you must: gem install rspec' - end -end - -begin - require 'rcov' - require 'spec/rake/verify_rcov' - - Spec::Rake::SpecTask.new(:rcov) do |rcov| - spec_defaults.call(rcov) - rcov.rcov = true - rcov.rcov_opts = File.read('spec/rcov.opts').split(/\s+/) - end - - RCov::VerifyTask.new(:verify_rcov => :rcov) do |rcov| - rcov.threshold = 100 - end -rescue LoadError - %w[ rcov verify_rcov ].each do |name| - task name do - abort "rcov is not available. In order to run #{name}, you must: gem install rcov" - end - end -end - +require 'rspec/core/rake_task' +RSpec::Core::RakeTask.new(:spec) task :default => :spec