Fix brokena and brittle tests

This commit is contained in:
Adam Meehan 2011-09-11 21:29:46 +10:00
parent 9a99c47323
commit af9d6cdba4
3 changed files with 15 additions and 7 deletions

View File

@ -81,7 +81,7 @@ class Employee < ActiveRecord::Base
end
end
Rspec.configure do |c|
RSpec.configure do |c|
c.mock_with :rspec
c.include(RspecTagMatchers)
c.include(ModelHelpers)

View File

@ -15,15 +15,15 @@ end
describe ValidatesTimeliness, 'Mongoid' do
class Article
::ValidatesTimeliness.use_plugin_parser = true
include Mongoid::Document
ValidatesTimeliness.use_plugin_parser = true
field :publish_date, :type => Date
field :publish_time, :type => Time
field :publish_datetime, :type => DateTime
validates_date :publish_date, :allow_nil => true
validates_time :publish_time, :allow_nil => true
validates_datetime :publish_datetime, :allow_nil => true
::ValidatesTimeliness.use_plugin_parser = false
ValidatesTimeliness.use_plugin_parser = false
end
context "validation methods" do
@ -52,7 +52,7 @@ describe ValidatesTimeliness, 'Mongoid' do
end
context "with plugin parser" do
with_config(:use_plugin_parser, false)
with_config(:use_plugin_parser, true)
it 'should parse a string value' do
Timeliness::Parser.should_receive(:parse)
@ -60,12 +60,20 @@ describe ValidatesTimeliness, 'Mongoid' do
r.publish_date = '2010-01-01'
end
it 'should parse an invalid value as nil' do
Timeliness::Parser.should_receive(:parse)
r = Article.new
r.publish_date = 'bad value'
r.publish_date.should be_nil
end
context "for a date column" do
it 'should store a date value after parsing string' do
it 'should store a Time value after parsing string' do
r = Article.new
r.publish_date = '2010-01-01'
r.publish_date.should be_kind_of(Date)
r.publish_date.should be_kind_of(Time)
r.publish_date.should == Date.new(2010, 1, 1)
end
end

View File

@ -138,7 +138,7 @@ describe ValidatesTimeliness::Validator do
it "should be added when ignore_restriction_errors is false" do
with_config(:ignore_restriction_errors, false) do
person.valid?
person.errors[:birth_date].first.should match("Error occurred validating birth_date for :is_at restriction")
person.errors[:birth_date].first.should match("Error occurred validating birth_date")
end
end