ruby-on-railsrubytestingminitestshoulda

Refactoring test with shoulda, the minitest way


I was browsing shoulda matchers and context in order to refactor some text and make them more coincise and readable, but thorough, the documentation I could not find how to test this in specific:

(I'm following Hartl tutorial, and I'm trying to refactor in the Minitest way, not Rspec)

micropost_model

default_scope -> { order(created_at: :desc) }

has_one_attached :image

&

validates :image,   content_type: { in: %w[image/jpeg image/gif image/png],
                                      message: 'must be a valid image format' },
                    size: { less_than: 5.megabytes,
                            strong textmessage: 'should be less than 5MB' }

this:

user_test

user_model

attr_accessor :remember_token, :activation_token, :reset_token

before_save   :downcase_email
before_create :create_activation_digest

this:

routes

  resources :account_activations, only: [:edit]
  resources :password_resets,     only: %i[new create edit update]
  resources :microposts,          only: %i[create destroy]
  resources :relationships,       only: %i[create destroy]

Solution

  • In general here are the ways you can test the pieces you've posted:

    Hope that helps — let me know if you need more help.