RSpec: How to test the content of a flash message in a request spec

Posted About 3 years ago. Visible to the public.

The ActionDispatch Show archive.org snapshot module of Rails gives you the helper method flash to access the flash messages in a response.

describe PostsController, type: :request do

  describe 'update' do

    it 'shows a success message on update' do
      post_record = create(:post)

      put "/posts/#{post_record.id}"

      # Same as @request.flash[:alert]
      expect(flash[:alert]).to eq('Post updated successfully.')
    end

  end


end
Last edit
10 months ago
Felix Eschey
License
Source code in this card is licensed under the MIT License.
Posted by Emanuel to makandra dev (2021-03-08 12:58)