Skip to content

Instantly share code, notes, and snippets.

@yourivdlans
Last active April 24, 2019 12:06
Show Gist options
  • Save yourivdlans/2c6ec0bdfcf0c41d20a9e5dafaed7e04 to your computer and use it in GitHub Desktop.
Save yourivdlans/2c6ec0bdfcf0c41d20a9e5dafaed7e04 to your computer and use it in GitHub Desktop.
Rails 6 + Shoulda matchers + minitest-matchers_vaccine
gem install rails -v 6.0.0.beta3
rails _6.0.0.beta3_ new shoulda-matchers_test
bin/rails g scaffold User username:string
rails db:migrate RAILS_ENV=test
# Add the following gems to the test group
gem 'shoulda-matchers', git: 'https://github.com/thoughtbot/shoulda-matchers.git' # Required for Rails 6 (https://github.com/thoughtbot/shoulda-matchers/pull/1193)
gem 'minitest-matchers_vaccine'
# Add some validation to the user model, see user.rb
# Update the user test, see user_test.rb
bin/rails test test/models/user_test.rb # Fails because of an "undefined method `validate_presence_of'"
# Uncomment the fourth line in user_test.rb to include the ActiveModel matchers manually.
bin/rails test test/models/user_test.rb # Success
class User < ApplicationRecord
validates :username, presence: true
end
require 'test_helper'
class UserTest < ActiveSupport::TestCase
# include Shoulda::Matchers::ActiveModel
setup do
@subject = User.new
end
test 'validations and associations' do
must validate_presence_of(:username)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment