title: How to display controller error messages in your Rails tests?
body: <p>I am adding some tests (following <a href="http://guides.rubyonrails.org/v3.2/testing.html" rel="nofollow noreferrer">http://guides.rubyonrails.org/v3.2/testing.html</a>) and would like to add some feedback on my controller tests to show why my tests fail because I am missing some validation etc.</p>
  
  <p>Take this simple example:</p>
  
  <pre><code>test "should create article" do
    assert_difference('Article.count') do
      post articles_url, params: { article: { body: 'Rails is awesome!', title: 'Hello Rails' } }
    end
    assert_redirected_to article_path(Article.last)
  end
  </code></pre>
  
  <p>Lets say my <code>Article</code> model has a validation where <code>user_id</code> is required.  This test just fails.  I found another post on here with the following suggestion:</p>
  
  <pre><code>assert_equal([], assigns(:article).errors.full_messages)
  </code></pre>
  
  <p>I must be missing something or my inexperience with testing syntax etc. may be the issue because I can't get this to work - the <code>assigns(:article).errors.full_messages</code> is always <code>[]</code> even when the validation fails.  I am fine with the added assertion but I was also thinking to just add the error messages to the optional test failure message.</p>