[rspec-users] specs for attributes with default values on the SQL layer
svoop at delirium.ch
Thu Apr 16 16:15:25 EDT 2009
> What do you mean by it blocks refactorings? This isn't any different
> from the first example, with the exception that you provide a value
> instead of letting the default kick in...
article = Article.new
article.fetched # => false (due to default)
article = Article.new(valid_attributes.except(:fetched))
article.fetched # => false (again due to default)
article.should have(1).error_on(:fetched) # => RED LIGHT
This would work:
article = Article.new(:fetched => nil)
article.fetched # => nil (default overridden)
article.should have(1).error_on(:fetched) # => GREEN LIGHT
The problem is that Article.new doesn't return an object where all attributes
are nil and therefore the attributes passed must set defaultet attributes
explicitly to nil for it to override the defaults.
I wonder how other people treat this case.
More information about the rspec-users