Permalink
Browse files

Replace Test::Unit with RSpec

  • Loading branch information...
1 parent 3115673 commit 4f49e51605b181e2e4ed561b43643933d9acd6f6 @justincampbell justincampbell committed Apr 11, 2012
Showing with 87 additions and 92 deletions.
  1. +2 −0 .rspec
  2. +5 −4 Guardfile
  3. +8 −9 Rakefile
  4. +2 −1 easystats.gemspec
  5. +68 −0 spec/lib/easystats_spec.rb
  6. +2 −0 spec/spec_helper.rb
  7. +0 −73 test/easystats_test.rb
  8. +0 −5 test/test_helper.rb
View
2 .rspec
@@ -0,0 +1,2 @@
+--color
+--format progress
View
9 Guardfile
@@ -1,5 +1,6 @@
-guard :test do
- watch(%r{^lib/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
- watch(%r{^test/.+_test\.rb$})
- watch('test/test_helper.rb') { "test" }
+guard 'rspec', :version => 2 do
+ watch(%r{^spec/.+_spec\.rb$})
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
+ watch('spec/spec_helper.rb') { "spec" }
end
+
View
17 Rakefile
@@ -4,12 +4,11 @@ require 'rake/testtask'
Bundler::GemHelper.install_tasks
-desc 'Default: run unit tests.'
-task :default => :test
-
-desc 'Run unit tests.'
-Rake::TestTask.new(:test) do |t|
- t.libs << 'lib'
- t.pattern = 'test/*_test.rb'
- t.verbose = true
-end
+require 'rspec/core/rake_task'
+
+desc 'Default: run specs.'
+task :default => :spec
+
+desc "Run specs"
+RSpec::Core::RakeTask.new
+
View
3 easystats.gemspec
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
- s.add_development_dependency "guard-test"
+ s.add_development_dependency "guard-rspec"
s.add_development_dependency "rake"
+ s.add_development_dependency "rspec"
end
View
68 spec/lib/easystats_spec.rb
@@ -0,0 +1,68 @@
+require 'spec_helper'
+
+describe Array do
+ describe "#mean" do
+ it { [1].mean.should == 1 }
+ it { [1,2].mean.should == 1.5 }
+ it { [1,2,3].mean.should == 2 }
+ it { [1,2,3,4].mean.should == 2.5 }
+ end
+
+ describe "#average" do
+ it { [1,2,3,4].average.should == 2.5 }
+ end
+
+ describe "#median" do
+ it { [1].median.should == 1 }
+ it { [1,2].median.should == 1.5 }
+ it { [1,2,3].median.should == 2 }
+ it { [1,2,3,4].median.should == 2.5 }
+ it { [1,2,2,4].median.should == 2 }
+ it { [1,3,3,4].median.should == 3 }
+ end
+
+ describe "#mode" do
+ it { [1].mode.should == 1 }
+ it { [1,2].mode.should be_nil }
+ it { [1,2,3].mode.should be_nil }
+ it { [1,2,3,4].mode.should be_nil }
+ it { [1,2,2,4].mode.should == 2 }
+ it { [1,3,3,4].mode.should == 3 }
+ end
+
+ describe "#range" do
+ it { [1].range.should == 0 }
+ it { [1,2].range.should == 1 }
+ it { [1,2,3].range.should == 2 }
+ it { [1,2,3,4].range.should == 3 }
+ it { [1,2,2,4].range.should == 3 }
+ it { [1,3,3,4].range.should == 3 }
+ end
+
+ describe "#sum" do
+ it { [1].sum.should == 1 }
+ it { [1,2].sum.should == 3 }
+ it { [1,2,3].sum.should == 6 }
+ it { [1,2,3,4].sum.should == 10 }
+ it { [1,2,2,4].sum.should == 9 }
+ it { [1,3,3,4].sum.should == 11 }
+ end
+
+ describe "#variance" do
+ it { [1].variance.should == 0.0 }
+ it { [1,2].variance.should == 0.25 }
+ it { [1,2,3].variance.should == 2.0/3.0 }
+ it { [1,2,3,4].variance.should == 1.25 }
+ end
+
+ describe "#standard_deviation" do
+ let(:delta) { 0.00000000000001 }
+
+ it { [1].standard_deviation.should be_within(delta).of(0) }
+ it { [1,2].standard_deviation.should be_within(delta).of(0.707106781186548) }
+ it { [1,2,3].standard_deviation.should be_within(delta).of(1) }
+ it { [1,2,3,4].standard_deviation.should be_within(delta).of(1.29099444873581) }
+ end
+end
+
+
View
2 spec/spec_helper.rb
@@ -0,0 +1,2 @@
+require 'easystats'
+
View
73 test/easystats_test.rb
@@ -1,73 +0,0 @@
-require File.expand_path(File.dirname(__FILE__) + '/test_helper')
-
-class EasystatsTest < Test::Unit::TestCase
-
- def test_mean
- assert_equal 1, [1].mean, "1"
- assert_equal 1.5, [1,2].mean, "1,2"
- assert_equal 2, [1,2,3].mean, "1,2,3"
- assert_equal 2.5, [1,2,3,4].mean, "1,2,3,4"
- end
-
- def test_average_synonym_for_mean
- assert_equal 2.5, [1,2,3,4].average, "1,2,3,4"
- end
-
- def test_median
- assert_equal 1, [1].median, "1"
- assert_equal 1.5, [1,2].median, "1,2"
- assert_equal 2, [1,2,3].median, "1,2,3"
- assert_equal 2.5, [1,2,3,4].median, "1,2,3,4"
- assert_equal 2, [1,2,2,4].median, "1,2,2,4"
- assert_equal 3, [1,3,3,4].median, "1,3,3,4"
- end
-
- def test_mode
- assert_equal 1, [1].mode, "1"
- assert_equal nil, [1,2].mode, "1,2"
- assert_equal nil, [1,2,3].mode, "1,2,3"
- assert_equal nil, [1,2,3,4].mode, "1,2,3,4"
- assert_equal 2, [1,2,2,4].mode, "1,2,2,4"
- assert_equal 3, [1,3,3,4].mode, "1,3,3,4"
- end
-
- def test_range
- assert_equal 0, [1].range, "1"
- assert_equal 1, [1,2].range, "1,2"
- assert_equal 2, [1,2,3].range, "1,2,3"
- assert_equal 3, [1,2,3,4].range, "1,2,3,4"
- assert_equal 3, [1,2,2,4].range, "1,2,2,4"
- assert_equal 3, [1,3,3,4].range, "1,3,3,4"
- end
-
- def test_sum
- assert_equal 1, [1].sum, "1"
- assert_equal 3, [1,2].sum, "1,2"
- assert_equal 6, [1,2,3].sum, "1,2,3"
- assert_equal 10, [1,2,3,4].sum, "1,2,3,4"
- assert_equal 9, [1,2,2,4].sum, "1,2,2,4"
- assert_equal 11, [1,3,3,4].sum, "1,3,3,4"
- end
-
- def test_variance
- assert_equal 0.0, [1].variance, "1"
- assert_equal 0.25, [1,2].variance, "1,2"
- assert_equal 2.0/3.0, [1,2,3].variance, "1,2,3"
- assert_equal 1.25, [1,2,3,4].variance, "1,2,3,4"
- end
-
- def test_standard_deviation
- delta = 0.00000000000001
- assert_in_delta 0, [1].standard_deviation, delta, "1"
- assert_in_delta 0.707106781186548, [1,2].standard_deviation, delta, "1,2"
- assert_in_delta 1, [1,2,3].standard_deviation, delta, "1,2,3"
- assert_in_delta 1.29099444873581, [1,2,3,4].standard_deviation, delta, "1,2,3,4"
- end
-
- def test_should_not_be_able_to_access_protected_method_sum_of_deviations_squared
- assert_raise(NoMethodError) do
- [1].sum_of_deviations_squared
- end
- end
-
-end
View
5 test/test_helper.rb
@@ -1,5 +0,0 @@
-$:.unshift(File.dirname(__FILE__) + '/../lib')
-
-require 'rubygems'
-require 'test/unit'
-require 'easystats'

0 comments on commit 4f49e51

Please sign in to comment.