Permalink
Browse files

kill off remaining tests and remove rake tasks

  • Loading branch information...
1 parent 31ab7b9 commit 91704fe2dd2121e7bffbb86054531bfb1f3a3600 @olbrich olbrich committed Feb 25, 2012
Showing with 4 additions and 162 deletions.
  1. +1 −33 RakeFile
  2. +3 −1 spec/ruby-units/time_spec.rb
  3. +0 −2 spec/ruby-units/unit_spec.rb
  4. +0 −126 test/test_ruby-units.rb
View
@@ -41,16 +41,6 @@ rescue LoadError
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
end
-begin
- require 'rcov/rcovtask'
- desc "Generate code coverage"
- Rcov::RcovTask.new do |t|
- t.test_files = FileList['test/test*.rb']
- #t.verbose = true # uncomment to see the executed command
- end
-rescue LoadError
-end
-
begin
require 'simplecov'
desc "code coverage report using simplecov (ruby 1.9+)"
@@ -79,28 +69,8 @@ begin
rescue LoadError
end
-
-desc "Run unit tests"
-Rake::TestTask.new do |t|
- t.libs << "test"
- t.test_files = FileList['test/test*.rb']
-end
-
task :specs => :spec
-desc "Run tests against several ruby versions, requires rvm"
-task :multitest do
- rubies = %w{
- ruby-1.8.7-p357@ruby-units
- ruby-1.8.7-p357@ruby-units-with-chronic
- ruby-1.9.2-p290@ruby-units
- ruby-1.9.2-p290@ruby-units-with-chronic
- rbx-head@ruby-units
- jruby-1.6.5.1@ruby-units
- }
- exec "rvm #{rubies.join(',')} do rake tests"
-end
-
rubies = {
"ruby-1.8.7" => %w{ruby-1.8.7-p357@ruby-units ruby-1.8.7-p357@ruby-units-with-chronic},
"ruby-1.9.2" => %w{ruby-1.9.2-p290@ruby-units ruby-1.9.2-p290@ruby-units-with-chronic},
@@ -118,6 +88,4 @@ end
desc "Run specs against several ruby versions, requires rvm"
task "spec:all" => rubies.keys.map {|name| "spec:#{name}"}
-task :default => :spec
-
-task :tests => :test
+task :default => :spec
@@ -1,8 +1,9 @@
require File.dirname(__FILE__) + '/../spec_helper'
describe Time do
+ let(:now) { Time.at(1303656390) }
before(:each) do
- Time.stub(:now).and_return(Time.at(1303656390))
+ Time.stub(:now).and_return(now)
end
context ".at" do
@@ -24,6 +25,7 @@
context 'subtraction (-)' do
specify { (Time.now - 1).should == Time.at(1303656390 - 1)}
specify { (Time.now - Unit("10 min")).should == Time.at(1303656390 - 600)}
+ specify { (Time.now - Unit("150 years")).should == Time.parse("1861-04-24 09:46:30 -0500")}
end
end
@@ -1294,8 +1294,6 @@
specify { Unit('23 m').div(Unit('2 m')).should == 11 }
end
-
-
context "Time helper functions" do
before do
Time.stub!(:now).and_return(Time.utc(2011,10,16))
View
@@ -1,126 +0,0 @@
-require 'rubygems'
-require 'test/unit'
-require 'ruby-units'
-require 'yaml'
-begin
- require 'chronic'
-rescue LoadError
- warn "Can't test Chronic integration unless gem 'chronic' is installed"
-end
-begin
- require 'uncertain'
-rescue LoadError
- warn "Can't test Uncertain Units unless 'Uncertain' gem is installed"
-end
-
-
-class Time
- @@forced_now = nil
- @@forced_gmt = nil
- class << self
- alias :unforced_now :now
- def forced_now
- @@forced_now.nil? ? unforced_now : @@forced_now
- end
- alias :now :forced_now
-
- def forced_now=(now)
- @@forced_now = now
- end
- end
-
- alias :unforced_gmt :gmt_offset
- def forced_gmt
- @@forced_gmt.nil? ? unforced_gmt : @@forced_gmt
- end
- alias :gmt_offset :forced_gmt
-
- def forced_gmt=(gmt)
- @@forced_gmt = now
- end
-
-end
-
-class DateTime
- @@forced_now = nil
- class << self
- alias :unforced_now :now
- def forced_now
- return @@forced_now ? @@forced_now : unforced_now
- end
- alias :now :forced_now
-
- def forced_now=(now)
- @@forced_now = now
- end
-
- end
-end
-
-class Dummy
- def to_unit
- '1 mm'.unit
- end
-end
-
-class TestRubyUnits < Test::Unit::TestCase
-
- def setup
- @april_fools = Time.at 1143910800
- @april_fools_datetime = DateTime.parse('2006-04-01T12:00:00-05:00')
- Time.forced_now = @april_fools
- DateTime.forced_now = @april_fools_datetime
- #Unit.clear_cache
- end
-
- def teardown
- Time.forced_now = nil
- DateTime.forced_now = nil
- end
-
- def test_temperature_conversions
- assert_raises(ArgumentError) { '-1 tempK'.unit}
- assert_raises(ArgumentError) { '-1 tempR'.unit}
- assert_raises(ArgumentError) { '-1000 tempC'.unit}
- assert_raises(ArgumentError) { '-1000 tempF'.unit}
-
- assert_in_delta '32 tempF'.unit.base_scalar, '0 tempC'.unit.base_scalar, 0.01
- assert_in_delta '0 tempC'.unit.base_scalar, '32 tempF'.unit.base_scalar, 0.01
- assert_in_delta '0 tempC'.unit.base_scalar, '273.15 tempK'.unit.base_scalar, 0.01
- assert_in_delta '0 tempC'.unit.base_scalar, '491.67 tempR'.unit.base_scalar, 0.01
-
- a = '10 degC'.unit
- assert_equal a >> 'tempC', '-263.15 tempC'.unit
- assert_equal a >> 'tempK', '10 tempK'.unit
- assert_equal a >> 'tempR', '18 tempR'.unit
- assert_equal a >> 'tempF', '-441.67 tempF'.unit
-
- unit1 = '37 tempC'.unit
- assert_equal unit1 >> 'tempF' >> 'tempK' >> 'tempR' >> 'tempC', unit1
-
- a = '100 tempF'.unit
- b = '10 degC'.unit
- c = '50 tempF'.unit
- d = '18 degF'.unit
- assert_equal('118 tempF'.unit,a+b)
- assert_equal b+a, '118 tempF'.unit
- assert_equal a-b, '82 tempF'.unit
- assert_in_delta((a-c).scalar, '50 degF'.unit.scalar, 0.01)
- assert_in_delta '20 degC'.unit.scalar, (b+d).scalar, 0.01
- assert_raises(ArgumentError) { a * b }
- assert_raises(ArgumentError) { a / b }
- assert_raises(ArgumentError) { a ** 2 }
- assert_raises(ArgumentError) { c - '400 degK'.unit}
- assert_equal a, a.convert_to('tempF')
- end
-
- def test_time_conversions
- today = Time.now
- assert_equal today,@april_fools
- last_century = today - '150 years'.unit
- assert_equal last_century.to_date, DateTime.parse('1856-04-01')
- end
-
-
-end
-

0 comments on commit 91704fe

Please sign in to comment.