How to test a model with a lot of attributes and validation in Ruby on Rails?

Hi I have a user model with many attributes and validation that are required for login. I want to develop my application using test development, but it's hard for me to write simple tests to check, such as the lack of emails, unique emails, the correct email address.

So what is the best way to start writing tests?

+3
source share
2 answers

Shoulda ( http://github.com/thoughtbot/shoulda/wiki/Usage ) will make it easy to check such ActiveRecord checks.

  should_not_allow_values_for :email, "blah", "b lah" 
  should_allow_values_for :email, "a@b.com", "asdf@asdf.com" 

, , , .

+2

, , . . ( rSpec):

obj_under_test = MyModel.new(@valid_attributes)
object_under_test.email = nil
obj_under_test.should_not be_valid

@valid_attributes . . FactoryGirl, Machinist, Fixjour . , , - :

/ , . ( "", BDD). , , " ", " , ", " " ..

0

Source: https://habr.com/ru/post/1770457/


All Articles