From b0034237324b618171396f8fffa38f9ebc995a7b Mon Sep 17 00:00:00 2001 From: Piotr Solnica Date: Mon, 14 Nov 2011 12:15:49 +0100 Subject: [PATCH 01/11] Remove jeweler --- Gemfile | 4 ++-- dm-aggregates.gemspec | 3 ++- lib/dm-aggregates/version.rb | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 8c2de53..ea58ada 100644 --- a/Gemfile +++ b/Gemfile @@ -1,13 +1,13 @@ require 'pathname' -source :rubygems +source 'https://rubygems.org' 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' DO_VERSION = '~> 0.10.6' DM_DO_ADAPTERS = %w[ sqlite postgres mysql oracle sqlserver ] CURRENT_BRANCH = ENV.fetch('GIT_BRANCH', 'master') diff --git a/dm-aggregates.gemspec b/dm-aggregates.gemspec index fcc9f1b..e486ef5 100644 --- a/dm-aggregates.gemspec +++ b/dm-aggregates.gemspec @@ -7,6 +7,7 @@ Gem::Specification.new do |gem| gem.summary = "DataMapper plugin providing support for aggregates on collections" gem.description = gem.summary gem.homepage = "http://datamapper.org" + gem.license = 'MIT' gem.files = `git ls-files`.split("\n") gem.test_files = `git ls-files -- {spec}/*`.split("\n") @@ -16,7 +17,7 @@ Gem::Specification.new do |gem| gem.require_paths = [ "lib" ] gem.version = DataMapper::Aggregates::VERSION - gem.add_runtime_dependency('dm-core', '~> 1.3.0.beta') + gem.add_runtime_dependency('dm-core', '~> 1.2') gem.add_development_dependency('rake', '~> 0.9.2') gem.add_development_dependency('rspec', '~> 1.3.2') diff --git a/lib/dm-aggregates/version.rb b/lib/dm-aggregates/version.rb index 25d0bf1..977cd75 100644 --- a/lib/dm-aggregates/version.rb +++ b/lib/dm-aggregates/version.rb @@ -1,5 +1,5 @@ module DataMapper module Aggregates - VERSION = '1.3.0.beta' + VERSION = '1.2.0' end end From 8098e593bbfb3b983f98eb02e6c3f9c7255a387d Mon Sep 17 00:00:00 2001 From: Martin Emde Date: Mon, 26 Jan 2015 16:24:16 -0800 Subject: [PATCH 02/11] Loosen gem deps in gemspec --- dm-aggregates.gemspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dm-aggregates.gemspec b/dm-aggregates.gemspec index e486ef5..d49aded 100644 --- a/dm-aggregates.gemspec +++ b/dm-aggregates.gemspec @@ -19,6 +19,6 @@ Gem::Specification.new do |gem| gem.add_runtime_dependency('dm-core', '~> 1.2') - gem.add_development_dependency('rake', '~> 0.9.2') - gem.add_development_dependency('rspec', '~> 1.3.2') + gem.add_development_dependency('rake', '~> 0.9') + gem.add_development_dependency('rspec', '~> 1.3') end From 67efd49f0dd742e76544220267271496423bf297 Mon Sep 17 00:00:00 2001 From: Martin Emde Date: Tue, 27 Jan 2015 10:53:22 -0800 Subject: [PATCH 03/11] Build on travis --- .travis.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..78f2e0c --- /dev/null +++ b/.travis.yml @@ -0,0 +1,11 @@ +language: ruby +sudo: false +rvm: + - 1.9.3 + - 2.0.0 + - 2.1.5 + - 2.2.0 +matrix: + allow_failures: + - rvm: 2.1.5 + - rvm: 2.2.0 From 9f68051575149792ca4aaf077c7bda990e7f1333 Mon Sep 17 00:00:00 2001 From: Martin Emde Date: Tue, 3 Feb 2015 09:57:57 -0800 Subject: [PATCH 04/11] Remove 2.1.5 from allow failures in travis --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 78f2e0c..145e8ad 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,5 +7,4 @@ rvm: - 2.2.0 matrix: allow_failures: - - rvm: 2.1.5 - rvm: 2.2.0 From c447b4c1445e3de05ad65931873b933c0491c175 Mon Sep 17 00:00:00 2001 From: Martin Emde Date: Thu, 26 Feb 2015 16:25:22 -0800 Subject: [PATCH 05/11] Test adapters on travis --- .travis.yml | 12 ++++++++++++ tasks/db.rake | 11 +++++++++++ 2 files changed, 23 insertions(+) create mode 100644 tasks/db.rake diff --git a/.travis.yml b/.travis.yml index 145e8ad..edc2169 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,17 @@ language: ruby sudo: false +services: + - mysql +before_script: + - "bundle exec rake db:create" +before_install: + - gem install bundler +script: "bundle exec rake spec" +env: + - "ADAPTER=in_memory" +# - "ADAPTER=yaml" + - "ADAPTER=sqlite" + - "ADAPTER=mysql DM_DB_USER=root DM_DB_PASSWORD=''" rvm: - 1.9.3 - 2.0.0 diff --git a/tasks/db.rake b/tasks/db.rake new file mode 100644 index 0000000..ecb1168 --- /dev/null +++ b/tasks/db.rake @@ -0,0 +1,11 @@ +namespace :db do + task :create do + sh 'mysql -uroot -e "CREATE DATABASE IF NOT EXISTS datamapper_default_tests;"' + sh 'mysql -uroot -e "CREATE DATABASE IF NOT EXISTS datamapper_alternate_tests;"' + end + + task :drop do + sh 'mysql -uroot -e "DROP DATABASE IF EXISTS datamapper_default_tests;"' + sh 'mysql -uroot -e "DROP DATABASE IF EXISTS datamapper_alternate_tests;"' + end +end From 006a3f5000b30ed1c232893387490b0c64e288f0 Mon Sep 17 00:00:00 2001 From: Martin Emde Date: Thu, 26 Feb 2015 16:26:52 -0800 Subject: [PATCH 06/11] RSpec 2.99 compatible --- dm-aggregates.gemspec | 4 +-- spec/isolated/require_after_setup_spec.rb | 8 ++--- spec/isolated/require_before_setup_spec.rb | 8 ++--- spec/isolated/require_spec.rb | 2 +- spec/public/collection_spec.rb | 6 ++-- spec/public/model_spec.rb | 6 ++-- spec/public/shared/aggregate_shared_spec.rb | 10 +++--- spec/spec_helper.rb | 4 +-- tasks/spec.rake | 39 ++------------------- 9 files changed, 23 insertions(+), 64 deletions(-) diff --git a/dm-aggregates.gemspec b/dm-aggregates.gemspec index d49aded..228eb31 100644 --- a/dm-aggregates.gemspec +++ b/dm-aggregates.gemspec @@ -19,6 +19,6 @@ Gem::Specification.new do |gem| gem.add_runtime_dependency('dm-core', '~> 1.2') - gem.add_development_dependency('rake', '~> 0.9') - gem.add_development_dependency('rspec', '~> 1.3') + gem.add_development_dependency('rake', '~> 10.0') + gem.add_development_dependency('rspec', '~> 2.0') end diff --git a/spec/isolated/require_after_setup_spec.rb b/spec/isolated/require_after_setup_spec.rb index 1a97d4f..0ea4410 100644 --- a/spec/isolated/require_after_setup_spec.rb +++ b/spec/isolated/require_after_setup_spec.rb @@ -1,6 +1,4 @@ -require 'backports' -require 'spec' - +require 'rspec' require 'isolated/require_spec' require 'dm-core/spec/setup' @@ -9,14 +7,14 @@ if %w[ postgres mysql sqlite oracle sqlserver ].include?(ENV['ADAPTER']) - describe "require 'dm-aggregates after calling DataMapper.setup" do + RSpec.describe "require 'dm-aggregates after calling DataMapper.setup" do before(:all) do @adapter = DataMapper::Spec.adapter require 'dm-aggregates' end - it_should_behave_like "require 'dm-aggregates'" + include_examples "require 'dm-aggregates'" end diff --git a/spec/isolated/require_before_setup_spec.rb b/spec/isolated/require_before_setup_spec.rb index 592618e..6a399a7 100644 --- a/spec/isolated/require_before_setup_spec.rb +++ b/spec/isolated/require_before_setup_spec.rb @@ -1,6 +1,4 @@ -require 'backports' -require 'spec' - +require 'rspec' require 'isolated/require_spec' require 'dm-core/spec/setup' @@ -9,14 +7,14 @@ if %w[ postgres mysql sqlite oracle sqlserver ].include?(ENV['ADAPTER']) - describe "require 'dm-aggregates' before calling DataMapper.setup" do + RSpec.describe "require 'dm-aggregates' before calling DataMapper.setup" do before(:all) do require 'dm-aggregates' @adapter = DataMapper::Spec.adapter end - it_should_behave_like "require 'dm-aggregates'" + include_examples "require 'dm-aggregates'" end diff --git a/spec/isolated/require_spec.rb b/spec/isolated/require_spec.rb index 8ef75d3..5830f27 100644 --- a/spec/isolated/require_spec.rb +++ b/spec/isolated/require_spec.rb @@ -1,4 +1,4 @@ -shared_examples_for "require 'dm-aggregates'" do +RSpec.shared_examples_for "require 'dm-aggregates'" do %w[ Repository Model Collection Query ].each do |name| it "should include the aggregate api in DataMapper::#{name}" do diff --git a/spec/public/collection_spec.rb b/spec/public/collection_spec.rb index bfcdb50..f47f654 100644 --- a/spec/public/collection_spec.rb +++ b/spec/public/collection_spec.rb @@ -1,12 +1,12 @@ require 'spec_helper' -describe DataMapper::Collection do +RSpec.describe DataMapper::Collection do supported_by :sqlite, :mysql, :postgres do let(:dragons) { Dragon.all } let(:countries) { Country.all } - it_should_behave_like 'It Has Setup Resources' - it_should_behave_like 'An Aggregatable Class' + include_examples 'It Has Setup Resources' + include_examples 'An Aggregatable Class' describe 'ignore invalid query' do let(:dragons) { Dragon.all.all(:id => []) } diff --git a/spec/public/model_spec.rb b/spec/public/model_spec.rb index 447cbfb..3568d56 100644 --- a/spec/public/model_spec.rb +++ b/spec/public/model_spec.rb @@ -1,11 +1,11 @@ require 'spec_helper' -describe DataMapper::Model do +RSpec.describe DataMapper::Model do supported_by :sqlite, :mysql, :postgres do let(:dragons) { Dragon } let(:countries) { Country } - it_should_behave_like 'It Has Setup Resources' - it_should_behave_like 'An Aggregatable Class' + include_examples 'It Has Setup Resources' + include_examples 'An Aggregatable Class' end end diff --git a/spec/public/shared/aggregate_shared_spec.rb b/spec/public/shared/aggregate_shared_spec.rb index d3df6f6..6a7a7ac 100644 --- a/spec/public/shared/aggregate_shared_spec.rb +++ b/spec/public/shared/aggregate_shared_spec.rb @@ -1,4 +1,4 @@ -shared_examples_for 'It Has Setup Resources' do +RSpec.shared_examples_for 'It Has Setup Resources' do before :all do @mysql = defined?(DataMapper::Adapters::MysqlAdapter) && @adapter.kind_of?(DataMapper::Adapters::MysqlAdapter) @postgres = defined?(DataMapper::Adapters::PostgresAdapter) && @adapter.kind_of?(DataMapper::Adapters::PostgresAdapter) @@ -81,13 +81,13 @@ end end -shared_examples_for 'An Aggregatable Class' do +RSpec.shared_examples_for 'An Aggregatable Class' do describe '#size' do - it_should_behave_like 'count with no arguments' + include_examples 'count with no arguments' end describe '#count' do - it_should_behave_like 'count with no arguments' + include_examples 'count with no arguments' context 'with a property name' do it 'counts the results' do @@ -298,7 +298,7 @@ end end -shared_examples_for 'count with no arguments' do +RSpec.shared_examples_for 'count with no arguments' do it 'counts the results' do dragons.count.should == 3 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9319584..41d8891 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,3 @@ -require 'backports' - require 'dm-core/spec/setup' require 'dm-core/spec/lib/adapter_helpers' require 'dm-core/spec/lib/pending_helpers' @@ -11,7 +9,7 @@ DataMapper::Spec.setup -Spec::Runner.configure do |config| +RSpec.configure do |config| config.extend(DataMapper::Spec::Adapters::Helpers) config.include(DataMapper::Spec::PendingHelpers) 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 From a2c3fe97ddbb0543af5cb6aa3f9a42d2c939d5ec Mon Sep 17 00:00:00 2001 From: Martin Emde Date: Thu, 26 Feb 2015 16:28:21 -0800 Subject: [PATCH 07/11] Convert specs to RSpec 2.99.2 syntax with Transpec This conversion is done by Transpec 3.0.7 with the following command: transpec * 64 conversions from: obj.should to: expect(obj).to * 53 conversions from: == expected to: eq(expected) * 16 conversions from: it { should ... } to: it { is_expected.to ... } * 4 conversions from: <= expected to: be <= expected * 4 conversions from: >= expected to: be >= expected * 1 conversion from: pending { do_something_fail } to: pending; do_something_fail For more details: https://github.com/yujinakayama/transpec#supported-conversions --- spec/isolated/require_spec.rb | 4 +- spec/public/collection_spec.rb | 33 +++--- spec/public/shared/aggregate_shared_spec.rb | 124 ++++++++++---------- 3 files changed, 81 insertions(+), 80 deletions(-) diff --git a/spec/isolated/require_spec.rb b/spec/isolated/require_spec.rb index 5830f27..6b5bdb8 100644 --- a/spec/isolated/require_spec.rb +++ b/spec/isolated/require_spec.rb @@ -2,12 +2,12 @@ %w[ Repository Model Collection Query ].each do |name| it "should include the aggregate api in DataMapper::#{name}" do - (DataMapper.const_get(name) < DataMapper::Aggregates.const_get(name)).should be(true) + expect(DataMapper.const_get(name) < DataMapper::Aggregates.const_get(name)).to be(true) end end it "should include the aggregate api into the adapter" do - @adapter.respond_to?(:aggregate).should be(true) + expect(@adapter.respond_to?(:aggregate)).to be(true) end end diff --git a/spec/public/collection_spec.rb b/spec/public/collection_spec.rb index f47f654..f25cd35 100644 --- a/spec/public/collection_spec.rb +++ b/spec/public/collection_spec.rb @@ -15,38 +15,38 @@ describe "##{method}" do subject { dragons.send(method) } - it { should == 0 } + it { is_expected.to eq(0) } end end describe '#min' do subject { dragons.min(:id) } - it { should be_nil } + it { is_expected.to be_nil } end describe '#max' do subject { dragons.max(:id) } - it { should be_nil } + it { is_expected.to be_nil } end describe '#avg' do subject { dragons.avg(:id) } - it { should be_nil } + it { is_expected.to be_nil } end describe '#sum' do subject { dragons.sum(:id) } - it { should be_nil } + it { is_expected.to be_nil } end describe '#aggregate' do subject { dragons.aggregate(:id) } - it { should == [] } + it { is_expected.to eq([]) } end end @@ -56,43 +56,43 @@ describe '#size' do subject { collection.size } - it { should == 2 } + it { is_expected.to eq(2) } end describe '#count' do subject { collection.count } - it { should == 2 } + it { is_expected.to eq(2) } end describe '#min' do subject { collection.min(:toes_on_claw) } - it { should == 3 } + it { is_expected.to eq(3) } end describe '#max' do subject { collection.max(:toes_on_claw) } - it { should == 4 } + it { is_expected.to eq(4) } end describe '#avg' do subject { collection.avg(:toes_on_claw) } - it { should == 3.5 } + it { is_expected.to eq(3.5) } end describe '#sum' do subject { collection.sum(:toes_on_claw) } - it { should == 7 } + it { is_expected.to eq(7) } end describe '#aggregate' do subject { collection.aggregate(:all.count, :name.count, :toes_on_claw.min, :toes_on_claw.max, :toes_on_claw.avg, :toes_on_claw.sum)} - it { should == [ 2, 2, 3, 4, 3.5, 7 ] } + it { is_expected.to eq([ 2, 2, 3, 4, 3.5, 7 ]) } end end @@ -102,13 +102,14 @@ describe '#size' do subject { dragons.size } - it { should == 1 } + it { is_expected.to eq(1) } end describe '#count' do subject { dragons.count } - it { pending('TODO: make count apply to the limited collection. Currently limit applies after the count') { should == 1 } } + it { pending('TODO: make count apply to the limited collection. Currently limit applies after the count') + is_expected.to eq(1) } end end @@ -118,7 +119,7 @@ let(:dragons) { Dragon.all(:order => [ :birth_at.desc ]) } it 'displays the results in reverse order' do - should == Dragon.aggregate(:birth_at, :all.count).reverse + is_expected.to eq(Dragon.aggregate(:birth_at, :all.count).reverse) end end end diff --git a/spec/public/shared/aggregate_shared_spec.rb b/spec/public/shared/aggregate_shared_spec.rb index 6a7a7ac..b9a86c1 100644 --- a/spec/public/shared/aggregate_shared_spec.rb +++ b/spec/public/shared/aggregate_shared_spec.rb @@ -91,17 +91,17 @@ context 'with a property name' do it 'counts the results' do - dragons.count(:name).should == 2 + expect(dragons.count(:name)).to eq(2) end it 'counts the results with conditions having operators' do - dragons.count(:name, :toes_on_claw.gt => 3).should == 1 + expect(dragons.count(:name, :toes_on_claw.gt => 3)).to eq(1) end it 'counts the results with raw conditions' do statement = 'is_fire_breathing = ?' - dragons.count(:name, :conditions => [ statement, false ]).should == 1 - dragons.count(:name, :conditions => [ statement, true ]).should == 1 + expect(dragons.count(:name, :conditions => [ statement, false ])).to eq(1) + expect(dragons.count(:name, :conditions => [ statement, true ])).to eq(1) end end end @@ -115,41 +115,41 @@ context 'with a property name' do it 'provides the lowest value of an Integer property' do - dragons.min(:toes_on_claw).should == 3 - countries.min(:population).should == 82369548 + expect(dragons.min(:toes_on_claw)).to eq(3) + expect(countries.min(:population)).to eq(82369548) end it 'provides the lowest value of a Float property' do - countries.min(:birth_rate).should be_kind_of(Float) - countries.min(:birth_rate).should >= 7.87 - @approx_by # approx match - countries.min(:birth_rate).should <= 7.87 + @approx_by # approx match + expect(countries.min(:birth_rate)).to be_kind_of(Float) + expect(countries.min(:birth_rate)).to be >= 7.87 - @approx_by # approx match + expect(countries.min(:birth_rate)).to be <= 7.87 + @approx_by # approx match end it 'provides the lowest value of a BigDecimal property' do - countries.min(:gold_reserve_value).should be_kind_of(BigDecimal) - countries.min(:gold_reserve_value).should == BigDecimal('1217050983400.0') + expect(countries.min(:gold_reserve_value)).to be_kind_of(BigDecimal) + expect(countries.min(:gold_reserve_value)).to eq(BigDecimal('1217050983400.0')) end it 'provides the lowest value of a DateTime property' do pending_if 'TODO: returns incorrect value until DO handles TZs properly', @skip do - dragons.min(:birth_at).should be_kind_of(DateTime) - dragons.min(:birth_at).to_s.should == @birth_at.to_s + expect(dragons.min(:birth_at)).to be_kind_of(DateTime) + expect(dragons.min(:birth_at).to_s).to eq(@birth_at.to_s) end end it 'provides the lowest value of a Date property' do - dragons.min(:birth_on).should be_kind_of(Date) - dragons.min(:birth_on).should == @birth_on + expect(dragons.min(:birth_on)).to be_kind_of(Date) + expect(dragons.min(:birth_on)).to eq(@birth_on) end it 'provides the lowest value of a Time property' do - dragons.min(:birth_time).should be_kind_of(Time) - dragons.min(:birth_time).to_s.should == @birth_time.to_s + expect(dragons.min(:birth_time)).to be_kind_of(Time) + expect(dragons.min(:birth_time).to_s).to eq(@birth_time.to_s) end it 'provides the lowest value when conditions provided' do - dragons.min(:toes_on_claw, :is_fire_breathing => true).should == 4 - dragons.min(:toes_on_claw, :is_fire_breathing => false).should == 3 + expect(dragons.min(:toes_on_claw, :is_fire_breathing => true)).to eq(4) + expect(dragons.min(:toes_on_claw, :is_fire_breathing => false)).to eq(3) end end end @@ -163,40 +163,40 @@ context 'with a property name' do it 'provides the highest value of an Integer property' do - dragons.max(:toes_on_claw).should == 5 - countries.max(:population).should == 1330044605 + expect(dragons.max(:toes_on_claw)).to eq(5) + expect(countries.max(:population)).to eq(1330044605) end it 'provides the highest value of a Float property' do - countries.max(:birth_rate).should be_kind_of(Float) - countries.max(:birth_rate).should >= 20.04 - @approx_by # approx match - countries.max(:birth_rate).should <= 20.04 + @approx_by # approx match + expect(countries.max(:birth_rate)).to be_kind_of(Float) + expect(countries.max(:birth_rate)).to be >= 20.04 - @approx_by # approx match + expect(countries.max(:birth_rate)).to be <= 20.04 + @approx_by # approx match end it 'provides the highest value of a BigDecimal property' do - countries.max(:gold_reserve_value).should == BigDecimal('22589877164500.0') + expect(countries.max(:gold_reserve_value)).to eq(BigDecimal('22589877164500.0')) end it 'provides the highest value of a DateTime property' do pending_if 'TODO: returns incorrect value until DO handles TZs properly', @skip do - dragons.min(:birth_at).should be_kind_of(DateTime) - dragons.min(:birth_at).to_s.should == @birth_at.to_s + expect(dragons.min(:birth_at)).to be_kind_of(DateTime) + expect(dragons.min(:birth_at).to_s).to eq(@birth_at.to_s) end end it 'provides the highest value of a Date property' do - dragons.min(:birth_on).should be_kind_of(Date) - dragons.min(:birth_on).should == @birth_on + expect(dragons.min(:birth_on)).to be_kind_of(Date) + expect(dragons.min(:birth_on)).to eq(@birth_on) end it 'provides the highest value of a Time property' do - dragons.min(:birth_time).should be_kind_of(Time) - dragons.min(:birth_time).to_s.should == @birth_time.to_s + expect(dragons.min(:birth_time)).to be_kind_of(Time) + expect(dragons.min(:birth_time).to_s).to eq(@birth_time.to_s) end it 'provides the highest value when conditions provided' do - dragons.max(:toes_on_claw, :is_fire_breathing => true).should == 5 - dragons.max(:toes_on_claw, :is_fire_breathing => false).should == 3 + expect(dragons.max(:toes_on_claw, :is_fire_breathing => true)).to eq(5) + expect(dragons.max(:toes_on_claw, :is_fire_breathing => false)).to eq(3) end end end @@ -210,26 +210,26 @@ context 'with a property name' do it 'provides the average value of an Integer property' do - dragons.avg(:toes_on_claw).should be_kind_of(Float) - dragons.avg(:toes_on_claw).should == 4.0 + expect(dragons.avg(:toes_on_claw)).to be_kind_of(Float) + expect(dragons.avg(:toes_on_claw)).to eq(4.0) end it 'provides the average value of a Float property' do mean_birth_rate = (13.71 + 14.18 + 16.04 + 11.03 + 7.87 + 20.04 + 8.18) / 7 - countries.avg(:birth_rate).should be_kind_of(Float) - countries.avg(:birth_rate).should >= mean_birth_rate - @approx_by # approx match - countries.avg(:birth_rate).should <= mean_birth_rate + @approx_by # approx match + expect(countries.avg(:birth_rate)).to be_kind_of(Float) + expect(countries.avg(:birth_rate)).to be >= mean_birth_rate - @approx_by # approx match + expect(countries.avg(:birth_rate)).to be <= mean_birth_rate + @approx_by # approx match end it 'provides the average value of a BigDecimal property' do mean_gold_reserve_value = ((600.0 + 8133.50 + 438.20 + 765.20 + 3417.40) * @gold_tonne_price) / 5 - countries.avg(:gold_reserve_value).should be_kind_of(BigDecimal) - countries.avg(:gold_reserve_value).should == BigDecimal(mean_gold_reserve_value.to_s) + expect(countries.avg(:gold_reserve_value)).to be_kind_of(BigDecimal) + expect(countries.avg(:gold_reserve_value)).to eq(BigDecimal(mean_gold_reserve_value.to_s)) end it 'provides the average value when conditions provided' do - dragons.avg(:toes_on_claw, :is_fire_breathing => true).should == 4.5 - dragons.avg(:toes_on_claw, :is_fire_breathing => false).should == 3 + expect(dragons.avg(:toes_on_claw, :is_fire_breathing => true)).to eq(4.5) + expect(dragons.avg(:toes_on_claw, :is_fire_breathing => false)).to eq(3) end end end @@ -243,27 +243,27 @@ context 'with a property name' do it 'provides the sum of values for an Integer property' do - dragons.sum(:toes_on_claw).should == 12 + expect(dragons.sum(:toes_on_claw)).to eq(12) total_population = 1330044605 + 303824646 + 191908598 + 140702094 + 127288419 + 109955400 + 82369548 - countries.sum(:population).should == total_population + expect(countries.sum(:population)).to eq(total_population) end it 'provides the sum of values for a Float property' do total_tonnes = 600.0 + 8133.5 + 438.2 + 765.2 + 3417.4 - countries.sum(:gold_reserve_tonnes).should be_kind_of(Float) - countries.sum(:gold_reserve_tonnes).should >= total_tonnes - @approx_by # approx match - countries.sum(:gold_reserve_tonnes).should <= total_tonnes + @approx_by # approx match + expect(countries.sum(:gold_reserve_tonnes)).to be_kind_of(Float) + expect(countries.sum(:gold_reserve_tonnes)).to be >= total_tonnes - @approx_by # approx match + expect(countries.sum(:gold_reserve_tonnes)).to be <= total_tonnes + @approx_by # approx match end it 'provides the sum of values for a BigDecimal property' do - countries.sum(:gold_reserve_value).should == BigDecimal('37090059214100.0') + expect(countries.sum(:gold_reserve_value)).to eq(BigDecimal('37090059214100.0')) end it 'provides the average value when conditions provided' do - dragons.sum(:toes_on_claw, :is_fire_breathing => true).should == 9 - dragons.sum(:toes_on_claw, :is_fire_breathing => false).should == 3 + expect(dragons.sum(:toes_on_claw, :is_fire_breathing => true)).to eq(9) + expect(dragons.sum(:toes_on_claw, :is_fire_breathing => false)).to eq(3) end end end @@ -278,14 +278,14 @@ context 'with only aggregate fields specified' do it 'provides aggregate results' do results = dragons.aggregate(:all.count, :name.count, :toes_on_claw.min, :toes_on_claw.max, :toes_on_claw.avg, :toes_on_claw.sum) - results.should == [ 3, 2, 3, 5, 4.0, 12 ] + expect(results).to eq([ 3, 2, 3, 5, 4.0, 12 ]) end end context 'with aggregate fields and a property to group by' do it 'provides aggregate results' do results = dragons.aggregate(:all.count, :name.count, :toes_on_claw.min, :toes_on_claw.max, :toes_on_claw.avg, :toes_on_claw.sum, :is_fire_breathing) - results.should == [ [ 1, 1, 3, 3, 3.0, 3, false ], [ 2, 1, 4, 5, 4.5, 9, true ] ] + expect(results).to eq([ [ 1, 1, 3, 3, 3.0, 3, false ], [ 2, 1, 4, 5, 4.5, 9, true ] ]) end end end @@ -293,30 +293,30 @@ describe 'query path issue' do it 'does not break when a query path is specified' do dragon = dragons.first(Dragon.knight.name => 'Chuck') - dragon.name.should == 'George' + expect(dragon.name).to eq('George') end end end RSpec.shared_examples_for 'count with no arguments' do it 'counts the results' do - dragons.count.should == 3 + expect(dragons.count).to eq(3) - countries.count.should == 7 + expect(countries.count).to eq(7) end it 'counts the results with conditions having operators' do - dragons.count(:toes_on_claw.gt => 3).should == 2 + expect(dragons.count(:toes_on_claw.gt => 3)).to eq(2) - countries.count(:birth_rate.lt => 12).should == 3 - countries.count(:population.gt => 1000000000).should == 1 - countries.count(:population.gt => 2000000000).should == 0 - countries.count(:population.lt => 10).should == 0 + expect(countries.count(:birth_rate.lt => 12)).to eq(3) + expect(countries.count(:population.gt => 1000000000)).to eq(1) + expect(countries.count(:population.gt => 2000000000)).to eq(0) + expect(countries.count(:population.lt => 10)).to eq(0) end it 'counts the results with raw conditions' do dragon_statement = 'is_fire_breathing = ?' - dragons.count(:conditions => [ dragon_statement, false ]).should == 1 - dragons.count(:conditions => [ dragon_statement, true ]).should == 2 + expect(dragons.count(:conditions => [ dragon_statement, false ])).to eq(1) + expect(dragons.count(:conditions => [ dragon_statement, true ])).to eq(2) end end From 878a832831dbd575a82d46af510f59099fd28ceb Mon Sep 17 00:00:00 2001 From: Martin Emde Date: Thu, 26 Feb 2015 16:40:09 -0800 Subject: [PATCH 08/11] DO no longer messes up timezones apparently (rspec pending fails) --- Gemfile | 2 +- spec/public/collection_spec.rb | 7 +++++-- spec/public/shared/aggregate_shared_spec.rb | 14 ++++---------- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/Gemfile b/Gemfile index ea58ada..9c14d53 100644 --- a/Gemfile +++ b/Gemfile @@ -8,7 +8,7 @@ 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.2' -DO_VERSION = '~> 0.10.6' +DO_VERSION = '~> 0.10.15' DM_DO_ADAPTERS = %w[ sqlite postgres mysql oracle sqlserver ] CURRENT_BRANCH = ENV.fetch('GIT_BRANCH', 'master') diff --git a/spec/public/collection_spec.rb b/spec/public/collection_spec.rb index f25cd35..3f9a67d 100644 --- a/spec/public/collection_spec.rb +++ b/spec/public/collection_spec.rb @@ -108,8 +108,11 @@ describe '#count' do subject { dragons.count } - it { pending('TODO: make count apply to the limited collection. Currently limit applies after the count') - is_expected.to eq(1) } + it do + pending('TODO: make count apply to the limited collection. Currently limit applies after the count') + is_expected.to eq(1) + end + end end diff --git a/spec/public/shared/aggregate_shared_spec.rb b/spec/public/shared/aggregate_shared_spec.rb index b9a86c1..e6686ed 100644 --- a/spec/public/shared/aggregate_shared_spec.rb +++ b/spec/public/shared/aggregate_shared_spec.rb @@ -2,8 +2,6 @@ before :all do @mysql = defined?(DataMapper::Adapters::MysqlAdapter) && @adapter.kind_of?(DataMapper::Adapters::MysqlAdapter) @postgres = defined?(DataMapper::Adapters::PostgresAdapter) && @adapter.kind_of?(DataMapper::Adapters::PostgresAdapter) - - @skip = (@mysql || @postgres) && ENV['TZ'].to_s.downcase != 'utc' end before :all do @@ -131,10 +129,8 @@ end it 'provides the lowest value of a DateTime property' do - pending_if 'TODO: returns incorrect value until DO handles TZs properly', @skip do - expect(dragons.min(:birth_at)).to be_kind_of(DateTime) - expect(dragons.min(:birth_at).to_s).to eq(@birth_at.to_s) - end + expect(dragons.min(:birth_at)).to be_kind_of(DateTime) + expect(dragons.min(:birth_at).to_s).to eq(@birth_at.to_s) end it 'provides the lowest value of a Date property' do @@ -178,10 +174,8 @@ end it 'provides the highest value of a DateTime property' do - pending_if 'TODO: returns incorrect value until DO handles TZs properly', @skip do - expect(dragons.min(:birth_at)).to be_kind_of(DateTime) - expect(dragons.min(:birth_at).to_s).to eq(@birth_at.to_s) - end + expect(dragons.min(:birth_at)).to be_kind_of(DateTime) + expect(dragons.min(:birth_at).to_s).to eq(@birth_at.to_s) end it 'provides the highest value of a Date property' do From c31259fa1d458271c32b6fdc78aaf0e91c0724ec Mon Sep 17 00:00:00 2001 From: Martin Emde Date: Thu, 26 Feb 2015 16:49:13 -0800 Subject: [PATCH 09/11] Require ruby 2.2.0 to pass on travis --- .travis.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index edc2169..092760a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,6 +17,3 @@ rvm: - 2.0.0 - 2.1.5 - 2.2.0 -matrix: - allow_failures: - - rvm: 2.2.0 From 0de8607a6bcf1a8d05babcbb4deb2e20f47eb4e3 Mon Sep 17 00:00:00 2001 From: Martin Emde Date: Thu, 26 Feb 2015 17:28:05 -0800 Subject: [PATCH 10/11] Some of the tests fail when TZ is not set. --- spec/spec_helper.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 41d8891..931a946 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -7,6 +7,9 @@ require 'public/shared/aggregate_shared_spec' +# Some of the tests fail when TZ is not set, but not when it's blank. Go figure +ENV['TZ'] ||= '' + DataMapper::Spec.setup RSpec.configure do |config| From 9eeea8fc007d0ccf5eb0f96da336f45b8ae14ddb Mon Sep 17 00:00:00 2001 From: Martin Emde Date: Thu, 26 Feb 2015 17:28:15 -0800 Subject: [PATCH 11/11] rspec ~> 3.0 --- dm-aggregates.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dm-aggregates.gemspec b/dm-aggregates.gemspec index 228eb31..a9dde0a 100644 --- a/dm-aggregates.gemspec +++ b/dm-aggregates.gemspec @@ -20,5 +20,5 @@ Gem::Specification.new do |gem| gem.add_runtime_dependency('dm-core', '~> 1.2') gem.add_development_dependency('rake', '~> 10.0') - gem.add_development_dependency('rspec', '~> 2.0') + gem.add_development_dependency('rspec', '~> 3.0') end