Jerry Cheung
2014-Oct-28 17:01 UTC
[Feature request] assert_valid / refute_valid ActiveModel test helpers
This was proposed as an idea 4 years ago in
https://github.com/rails/rails/pull/95. It was closed at that time, but I'd
like to propose a refreshed version targeted towards ActiveModel and
Minitest. The gem is at https://github.com/jch/minitest-model.
This feature is more useful today than when it was originally proposed
because any ActiveModel::Validations standardized the interface used by
ORMs and general ruby objects. Here is a sample of what it looks like:
class MyTest < ActiveSupport::TestCase
include Minitest::Model
test "model requires email" do
m = Model.new
refute_valid m, :email
m.email = "foo@bar.com"
assert_valid m, :email
end
end
Failed assertions print a descriptive message of why it failed rather than
a generic "Expected true" if asserting on just `valid?`.
Thanks!
-Jerry
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to rubyonrails-core+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.