Understanding assert_difference in Ruby on Rails

后端 未结 4 1287
日久生厌
日久生厌 2021-02-13 02:43

Could anyone please explain what this test code does? :

assert_difference(\'Post.count\') do
    post :create, :post => { :title => \'Hi\', :body => \'T         


        
4条回答
  •  灰色年华
    2021-02-13 03:34

    This assertion is to verify the certain/specified difference in the first argument. 1st argument should be a string i.e "Post.count". Second argument has a default value 1, you can specify other numbers also, even negetive numbers. for more details visit: http://api.rubyonrails.org/classes/ActiveSupport/Testing/Assertions.html

提交回复
热议问题