7stud -- wrote in post #1019720:
>
> Also note that this test doesn't do what it's advertised to do:
>
>
> test "User attributes must not be empty" do
> user = User.new
> assert user.invalid?
> assert user.errors[:email].any?
> assert user.errors[:name].any?
> assert user.errors[:password].any?
> assert user.errors[:security_question].any?
> assert user.errors[:security_answer].any?
> assert user.errors[:mobile_phone].any?
> end
>
>
> Because some attributes have validations other than :presence, an error
> does not mean the attribute was missing.
>
Actually, it's worse than that. Suppose all the attributes were empty.
That test would pass, and therefore one would think from the title of
the test, that the User's attributes were all present.
> I think you are going about your testing all wrong. Instead, you should
> create users that have something wrong with them to test if the
> validations catch the errors. For instance,
>
> test "User's name cannot be blank" do
> #create user with blank name
> assert user.valid?
> end
>
> It might save some typing to setup each test with a valid user, and
> inside the test change one attribute to something that isn't valid.
>
> Read section 3 and section 8 of the railsguide on testing here:
>
> http://guides.rubyonrails.org/testing.html
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
No comments:
Post a Comment