Skip to content

Commit e6adfb6

Browse files
committed
Drop rspec in favor of minispec
1 parent efa63ec commit e6adfb6

File tree

5 files changed

+45
-60
lines changed

5 files changed

+45
-60
lines changed

Gemfile.lock

+3-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
date_validator (0.6.1)
4+
date_validator (0.6.2)
55
activemodel (>= 3.0.0, < 3.2.0)
66

77
GEM
@@ -14,16 +14,8 @@ GEM
1414
activesupport (3.0.0)
1515
bluecloth (2.0.11)
1616
builder (2.1.2)
17-
diff-lcs (1.1.2)
1817
i18n (0.4.2)
19-
rspec (2.5.0)
20-
rspec-core (~> 2.5.0)
21-
rspec-expectations (~> 2.5.0)
22-
rspec-mocks (~> 2.5.0)
23-
rspec-core (2.5.1)
24-
rspec-expectations (2.5.0)
25-
diff-lcs (~> 1.1.2)
26-
rspec-mocks (2.5.0)
18+
minitest (2.2.2)
2719
simplecov (0.3.6)
2820
simplecov-html (>= 0.3.7)
2921
simplecov-html (0.3.8)
@@ -38,7 +30,7 @@ DEPENDENCIES
3830
activesupport (~> 3.0.0)
3931
bluecloth
4032
date_validator!
41-
rspec (~> 2.5.0)
33+
minitest (~> 2.2)
4234
simplecov
4335
tzinfo (~> 0.3.0)
4436
yard

Rakefile

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
require 'bundler'
22
Bundler::GemHelper.install_tasks
33

4-
require 'rspec/core/rake_task'
5-
desc "Run superrtext specs"
6-
RSpec::Core::RakeTask.new
4+
require 'rake/testtask'
5+
Rake::TestTask.new do |t|
6+
t.libs << "test"
7+
t.test_files = FileList['test/**/*_test.rb']
8+
t.verbose = true
9+
end
710

811
require 'yard'
912
YARD::Rake::YardocTask.new(:docs) do |t|
@@ -39,5 +42,4 @@ end
3942

4043
task :doc => [:docs]
4144

42-
task :default => :spec
43-
task :test => [:spec]
45+
task :default => :test

date_validator.gemspec

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ Gem::Specification.new do |s|
1616

1717
s.add_runtime_dependency 'activemodel', ['>= 3.0.0', '< 3.2.0']
1818

19-
s.add_development_dependency 'rspec', '~> 2.5.0'
19+
s.add_development_dependency 'minitest'
2020
s.add_development_dependency 'simplecov'
21-
s.add_development_dependency 'activesupport', '~> 3.0.0'
21+
s.add_development_dependency 'activesupport', ['>= 3.0.0', '< 3.2.0']
22+
2223
s.add_development_dependency 'tzinfo', '~> 0.3.0'
2324

2425
s.add_development_dependency 'yard'

spec/date_validator_spec.rb renamed to test/date_validator_test.rb

+30-41
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'spec_helper'
1+
require 'test_helper'
22

33
module ActiveModel
44
module Validations
@@ -11,10 +11,9 @@ module Validations
1111

1212
it "checks validity of the arguments" do
1313
[3, "foo", 1..6].each do |wrong_argument|
14-
expect {
15-
TestRecord.validates :expiration_date,
16-
:date => {:before => wrong_argument}
17-
}.to raise_error(ArgumentError, ":before must be a time, a date, a time_with_zone, a symbol or a proc")
14+
proc {
15+
TestRecord.validates(:expiration_date, :date => {:before => wrong_argument})
16+
}.must_raise(ArgumentError, ":before must be a time, a date, a time_with_zone, a symbol or a proc")
1817
end
1918
end
2019

@@ -23,38 +22,37 @@ module Validations
2322
:date => {:before => Time.now}
2423

2524
model = TestRecord.new(nil)
26-
model.should_not be_valid
27-
model.errors[:expiration_date].should eq(["is not a date"])
25+
model.valid?.must_equal false
26+
model.errors[:expiration_date].must_equal(["is not a date"])
2827
end
2928

3029
it "works with helper methods" do
3130
time = Time.now
3231
TestRecord.validates_date_of :expiration_date, :before => time
3332
model = TestRecord.new(time + 20000)
34-
model.should_not be_valid
33+
model.valid?.must_equal false
3534
end
3635

37-
[:valid,:invalid].each do |should_be|
38-
_context = should_be == :valid ? 'when value validates correctly' : 'when value does not match validation requirements'
36+
[:valid,:invalid].each do |must_be|
37+
_context = must_be == :valid ? 'when value validates correctly' : 'when value does not match validation requirements'
3938

40-
context _context do
39+
describe _context do
4140
[:after, :before, :after_or_equal_to, :before_or_equal_to].each do |check|
4241
now = Time.now.to_datetime
4342

4443
model_date = case check
45-
when :after then should_be == :valid ? now + 21000 : now - 1
46-
when :before then should_be == :valid ? now - 21000 : now + 1
47-
when :after_or_equal_to then should_be == :valid ? now : now - 21000
48-
when :before_or_equal_to then should_be == :valid ? now : now + 21000
44+
when :after then must_be == :valid ? now + 21000 : now - 1
45+
when :before then must_be == :valid ? now - 21000 : now + 1
46+
when :after_or_equal_to then must_be == :valid ? now : now - 21000
47+
when :before_or_equal_to then must_be == :valid ? now : now + 21000
4948
end
5049

51-
it "ensures that an attribute is #{should_be} when #{should_be == :valid ? 'respecting' : 'offending' } the #{check} check" do
50+
it "ensures that an attribute is #{must_be} when #{must_be == :valid ? 'respecting' : 'offending' } the #{check} check" do
5251
TestRecord.validates :expiration_date,
5352
:date => {:"#{check}" => now}
5453

5554
model = TestRecord.new(model_date)
56-
should_be == :valid ? model.should(be_valid, "an attribute should be valid when respecting the #{check} check")\
57-
: model.should_not(be_valid, "an attribute should be invalidwhen offending the #{check} check")
55+
must_be == :valid ? model.valid?.must_equal(true) : model.valid?.must_equal(false)
5856
end
5957

6058
if _context == 'when value does not match validation requirements'
@@ -63,8 +61,8 @@ module Validations
6361
:date => {:"#{check}" => now}
6462

6563
model = TestRecord.new(model_date)
66-
model.should_not be_valid
67-
model.errors[:expiration_date].should eq(["must be " + check.to_s.gsub('_',' ') + " #{I18n.localize(now)}"])
64+
model.valid?.must_equal false
65+
model.errors[:expiration_date].must_equal(["must be " + check.to_s.gsub('_',' ') + " #{I18n.localize(now)}"])
6866
end
6967
end
7068
end
@@ -78,8 +76,8 @@ module Validations
7876
:message => 'must be after Christmas'}
7977

8078
model = TestRecord.new(now + 21000)
81-
model.should_not be_valid
82-
model.errors[:expiration_date].should eq(["must be after Christmas"])
79+
model.valid?.must_equal false
80+
model.errors[:expiration_date].must_equal(["must be after Christmas"])
8381
end
8482

8583
it "allows custom validation message to be handled by I18n" do
@@ -89,8 +87,8 @@ module Validations
8987
TestRecord.validates :expiration_date, :date => true
9088

9189
model = TestRecord.new(nil)
92-
model.should_not be_valid
93-
model.errors[:expiration_date].should eq([custom_message])
90+
model.valid?.must_equal false
91+
model.errors[:expiration_date].must_equal([custom_message])
9492
end
9593
end
9694

@@ -105,24 +103,15 @@ module Validations
105103
it "accepts a #{type} as an argument to a check" do
106104
case type
107105
when :proc then
108-
expect {
109-
TestRecord.validates :expiration_date,
110-
:date => {:after => Proc.new{Time.now + 21000}}
111-
}.to_not raise_error
106+
TestRecord.validates(:expiration_date, :date => {:after => Proc.new{Time.now + 21000}}).must_be_kind_of Hash
112107
when :symbol then
113-
expect {
114-
TestRecord.send(:define_method, :min_date, lambda { Time.now + 21000 })
115-
TestRecord.validates :expiration_date, :date => {:after => :min_date}
116-
}.to_not raise_error
108+
TestRecord.send(:define_method, :min_date, lambda { Time.now + 21000 })
109+
TestRecord.validates(:expiration_date, :date => {:after => :min_date}).must_be_kind_of Hash
117110
when :date then
118-
expect {
119-
TestRecord.validates :expiration_date, :date => {:after => Time.now.to_date}
120-
}.to_not raise_error
111+
TestRecord.validates(:expiration_date, :date => {:after => Time.now.to_date}).must_be_kind_of Hash
121112
when :time_with_zone then
122-
expect {
123-
Time.zone = "Hawaii"
124-
TestRecord.validates :expiration_date, :date => {:before => Time.zone.parse((Time.now + 21000).to_s)}
125-
}.to_not raise_error
113+
Time.zone = "Hawaii"
114+
TestRecord.validates(:expiration_date, :date => {:before => Time.zone.parse((Time.now + 21000).to_s)}).must_be_kind_of Hash
126115
end
127116
end
128117
end
@@ -131,15 +120,15 @@ module Validations
131120
TestRecord.validates :expiration_date,
132121
:date => {:after => Proc.new{ nil }}
133122

134-
TestRecord.new(Time.now).should_not be_valid
123+
TestRecord.new(Time.now).valid?.must_equal false
135124
end
136125

137126
it "gracefully handles an unexpected result from a symbol argument evaluation" do
138127
TestRecord.send(:define_method, :min_date, lambda { nil })
139128
TestRecord.validates :expiration_date,
140129
:date => {:after => :min_date}
141130

142-
TestRecord.new(Time.now).should_not be_valid
131+
TestRecord.new(Time.now).valid?.must_equal false
143132
end
144133
end
145134

spec/spec_helper.rb renamed to test/test_helper.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
add_group "Lib", "lib"
44
end
55

6-
require 'rspec'
6+
require 'minitest/spec'
7+
require 'minitest/autorun'
78

89
require 'active_support/time' # For testing Date and TimeWithZone objects
910

0 commit comments

Comments
 (0)