Skip to content
Browse files

Drop rspec in favor of minispec

  • Loading branch information...
1 parent efa63ec commit e6adfb6da05edc7a7b7908add0060329060c28b6 @oriolgual oriolgual committed Jun 11, 2011
View
14 Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- date_validator (0.6.1)
+ date_validator (0.6.2)
activemodel (>= 3.0.0, < 3.2.0)
GEM
@@ -14,16 +14,8 @@ GEM
activesupport (3.0.0)
bluecloth (2.0.11)
builder (2.1.2)
- diff-lcs (1.1.2)
i18n (0.4.2)
- rspec (2.5.0)
- rspec-core (~> 2.5.0)
- rspec-expectations (~> 2.5.0)
- rspec-mocks (~> 2.5.0)
- rspec-core (2.5.1)
- rspec-expectations (2.5.0)
- diff-lcs (~> 1.1.2)
- rspec-mocks (2.5.0)
+ minitest (2.2.2)
simplecov (0.3.6)
simplecov-html (>= 0.3.7)
simplecov-html (0.3.8)
@@ -38,7 +30,7 @@ DEPENDENCIES
activesupport (~> 3.0.0)
bluecloth
date_validator!
- rspec (~> 2.5.0)
+ minitest (~> 2.2)
simplecov
tzinfo (~> 0.3.0)
yard
View
12 Rakefile
@@ -1,9 +1,12 @@
require 'bundler'
Bundler::GemHelper.install_tasks
-require 'rspec/core/rake_task'
-desc "Run superrtext specs"
-RSpec::Core::RakeTask.new
+require 'rake/testtask'
+Rake::TestTask.new do |t|
+ t.libs << "test"
+ t.test_files = FileList['test/**/*_test.rb']
+ t.verbose = true
+end
require 'yard'
YARD::Rake::YardocTask.new(:docs) do |t|
@@ -39,5 +42,4 @@ end
task :doc => [:docs]
-task :default => :spec
-task :test => [:spec]
+task :default => :test
View
5 date_validator.gemspec
@@ -16,9 +16,10 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'activemodel', ['>= 3.0.0', '< 3.2.0']
- s.add_development_dependency 'rspec', '~> 2.5.0'
+ s.add_development_dependency 'minitest'
s.add_development_dependency 'simplecov'
- s.add_development_dependency 'activesupport', '~> 3.0.0'
+ s.add_development_dependency 'activesupport', ['>= 3.0.0', '< 3.2.0']
+
s.add_development_dependency 'tzinfo', '~> 0.3.0'
s.add_development_dependency 'yard'
View
71 spec/date_validator_spec.rb → test/date_validator_test.rb
@@ -1,4 +1,4 @@
-require 'spec_helper'
+require 'test_helper'
module ActiveModel
module Validations
@@ -11,10 +11,9 @@ module Validations
it "checks validity of the arguments" do
[3, "foo", 1..6].each do |wrong_argument|
- expect {
- TestRecord.validates :expiration_date,
- :date => {:before => wrong_argument}
- }.to raise_error(ArgumentError, ":before must be a time, a date, a time_with_zone, a symbol or a proc")
+ proc {
+ TestRecord.validates(:expiration_date, :date => {:before => wrong_argument})
+ }.must_raise(ArgumentError, ":before must be a time, a date, a time_with_zone, a symbol or a proc")
end
end
@@ -23,38 +22,37 @@ module Validations
:date => {:before => Time.now}
model = TestRecord.new(nil)
- model.should_not be_valid
- model.errors[:expiration_date].should eq(["is not a date"])
+ model.valid?.must_equal false
+ model.errors[:expiration_date].must_equal(["is not a date"])
end
it "works with helper methods" do
time = Time.now
TestRecord.validates_date_of :expiration_date, :before => time
model = TestRecord.new(time + 20000)
- model.should_not be_valid
+ model.valid?.must_equal false
end
- [:valid,:invalid].each do |should_be|
- _context = should_be == :valid ? 'when value validates correctly' : 'when value does not match validation requirements'
+ [:valid,:invalid].each do |must_be|
+ _context = must_be == :valid ? 'when value validates correctly' : 'when value does not match validation requirements'
- context _context do
+ describe _context do
[:after, :before, :after_or_equal_to, :before_or_equal_to].each do |check|
now = Time.now.to_datetime
model_date = case check
- when :after then should_be == :valid ? now + 21000 : now - 1
- when :before then should_be == :valid ? now - 21000 : now + 1
- when :after_or_equal_to then should_be == :valid ? now : now - 21000
- when :before_or_equal_to then should_be == :valid ? now : now + 21000
+ when :after then must_be == :valid ? now + 21000 : now - 1
+ when :before then must_be == :valid ? now - 21000 : now + 1
+ when :after_or_equal_to then must_be == :valid ? now : now - 21000
+ when :before_or_equal_to then must_be == :valid ? now : now + 21000
end
- it "ensures that an attribute is #{should_be} when #{should_be == :valid ? 'respecting' : 'offending' } the #{check} check" do
+ it "ensures that an attribute is #{must_be} when #{must_be == :valid ? 'respecting' : 'offending' } the #{check} check" do
TestRecord.validates :expiration_date,
:date => {:"#{check}" => now}
model = TestRecord.new(model_date)
- should_be == :valid ? model.should(be_valid, "an attribute should be valid when respecting the #{check} check")\
- : model.should_not(be_valid, "an attribute should be invalidwhen offending the #{check} check")
+ must_be == :valid ? model.valid?.must_equal(true) : model.valid?.must_equal(false)
end
if _context == 'when value does not match validation requirements'
@@ -63,8 +61,8 @@ module Validations
:date => {:"#{check}" => now}
model = TestRecord.new(model_date)
- model.should_not be_valid
- model.errors[:expiration_date].should eq(["must be " + check.to_s.gsub('_',' ') + " #{I18n.localize(now)}"])
+ model.valid?.must_equal false
+ model.errors[:expiration_date].must_equal(["must be " + check.to_s.gsub('_',' ') + " #{I18n.localize(now)}"])
end
end
end
@@ -78,8 +76,8 @@ module Validations
:message => 'must be after Christmas'}
model = TestRecord.new(now + 21000)
- model.should_not be_valid
- model.errors[:expiration_date].should eq(["must be after Christmas"])
+ model.valid?.must_equal false
+ model.errors[:expiration_date].must_equal(["must be after Christmas"])
end
it "allows custom validation message to be handled by I18n" do
@@ -89,8 +87,8 @@ module Validations
TestRecord.validates :expiration_date, :date => true
model = TestRecord.new(nil)
- model.should_not be_valid
- model.errors[:expiration_date].should eq([custom_message])
+ model.valid?.must_equal false
+ model.errors[:expiration_date].must_equal([custom_message])
end
end
@@ -105,24 +103,15 @@ module Validations
it "accepts a #{type} as an argument to a check" do
case type
when :proc then
- expect {
- TestRecord.validates :expiration_date,
- :date => {:after => Proc.new{Time.now + 21000}}
- }.to_not raise_error
+ TestRecord.validates(:expiration_date, :date => {:after => Proc.new{Time.now + 21000}}).must_be_kind_of Hash
when :symbol then
- expect {
- TestRecord.send(:define_method, :min_date, lambda { Time.now + 21000 })
- TestRecord.validates :expiration_date, :date => {:after => :min_date}
- }.to_not raise_error
+ TestRecord.send(:define_method, :min_date, lambda { Time.now + 21000 })
+ TestRecord.validates(:expiration_date, :date => {:after => :min_date}).must_be_kind_of Hash
when :date then
- expect {
- TestRecord.validates :expiration_date, :date => {:after => Time.now.to_date}
- }.to_not raise_error
+ TestRecord.validates(:expiration_date, :date => {:after => Time.now.to_date}).must_be_kind_of Hash
when :time_with_zone then
- expect {
- Time.zone = "Hawaii"
- TestRecord.validates :expiration_date, :date => {:before => Time.zone.parse((Time.now + 21000).to_s)}
- }.to_not raise_error
+ Time.zone = "Hawaii"
+ TestRecord.validates(:expiration_date, :date => {:before => Time.zone.parse((Time.now + 21000).to_s)}).must_be_kind_of Hash
end
end
end
@@ -131,15 +120,15 @@ module Validations
TestRecord.validates :expiration_date,
:date => {:after => Proc.new{ nil }}
- TestRecord.new(Time.now).should_not be_valid
+ TestRecord.new(Time.now).valid?.must_equal false
end
it "gracefully handles an unexpected result from a symbol argument evaluation" do
TestRecord.send(:define_method, :min_date, lambda { nil })
TestRecord.validates :expiration_date,
:date => {:after => :min_date}
- TestRecord.new(Time.now).should_not be_valid
+ TestRecord.new(Time.now).valid?.must_equal false
end
end
View
3 spec/spec_helper.rb → test/test_helper.rb
@@ -3,7 +3,8 @@
add_group "Lib", "lib"
end
-require 'rspec'
+require 'minitest/spec'
+require 'minitest/autorun'
require 'active_support/time' # For testing Date and TimeWithZone objects

0 comments on commit e6adfb6

Please sign in to comment.
Something went wrong with that request. Please try again.