jeudi 2 juillet 2015

How minitest testing framework works in rails?

I just started to learn testing with minitest but it sounds very confusing to me. What does this statement means?

test 'should not save simulations without name' do
 post = Post.new
 assert !post.save, 'Saved the simulations without a name'
end

Post Model

class Post < ActiveRecord::Base
  validates_presence_of :name , :type
  belongs_to :user
  before_create :check_validation
  validates :type,  :inclusion => { :in => 1..10, :message => 'The row must be between 1 and 10' }

 private
 def check_validation(data, type)
  ....
 end

What would be the minitest method for following conditions:

  • check if name, type parameter exist when creating a new object of Post class. How can I do it post_test class?
  • Is this test method are checking the presence of name in post?
  • How can I test check_Validation through PostTest class?
  • How to check throw error if posts is not belong to users?

I have already created post.yml file and user.yml file. How to proceed again. I tried to read ruby official documentation but it is not very helpful.

Thanks in adnvance

Aucun commentaire:

Enregistrer un commentaire