Skip to content
  • Lucas Mazza's avatar
    564b1620
    Make `assert_difference` return the result of the yielded block. · 564b1620
    Lucas Mazza authored
    With this we can perform new assertions on the returned value without having
    to cache it with an outer variable or wrapping all subsequent assertions inside
    the `assert_difference` block.
    
    Before:
    
    ```
    post = nil
    assert_difference -> { Post.count }, 1 do
      Post.create
    end
    
    assert_predicate post, :persisted?
    ```
    
    Now:
    
    ```
    post = assert_difference -> { Post.count } do
      Post.create
    end
    
    assert_predicate post, :persisted?
    ```
    564b1620
    Make `assert_difference` return the result of the yielded block.
    Lucas Mazza authored
    With this we can perform new assertions on the returned value without having
    to cache it with an outer variable or wrapping all subsequent assertions inside
    the `assert_difference` block.
    
    Before:
    
    ```
    post = nil
    assert_difference -> { Post.count }, 1 do
      Post.create
    end
    
    assert_predicate post, :persisted?
    ```
    
    Now:
    
    ```
    post = assert_difference -> { Post.count } do
      Post.create
    end
    
    assert_predicate post, :persisted?
    ```
Loading