Last Updated: February 25, 2016
·
531
· keppy

Minitest styles

If you write minitests with the Design Rationale in mind you can use both the assertion and spec style tests in the same class structure:

require 'minitest_helper'
describe "Client photo integration" do
  before do
    @client = create(:client)
    @photo = create(:photo, :client_id => @client.id)
  end

  def test_photo_client
    assert_equal @photo.client, @client
  end

  describe "client with many photos integration" do
    before do
      @client_with_photos = create(:client_with_photos)
      sign_in(@client_with_photos)
    end
  end
end

By using the implicit class structure to add functionality to our tests as we go we can build from simple to complex and test everything incrementally. From here we can test to see if the signed in client's home page shows the correct photos and test against all other instance variables in the describe block.