### Contribution: Setup and Run Tests Source: https://github.com/metaskills/minitest-spec-rails/blob/master/README.md Commands to set up the development environment and run the test suite locally. This includes installing dependencies, updating appraisal configurations, and executing tests against various Rails versions. ```shell $ bundle install $ bundle exec appraisal update $ bundle exec appraisal rake test ``` ```shell $ bundle exec appraisal rails_v6.0.x rake test $ bundle exec appraisal rails_v6.1.x rake test $ bundle exec appraisal rails_v7.0.x rake test ``` -------------------------------- ### Setup and Teardown Compatibility Source: https://github.com/metaskills/minitest-spec-rails/blob/master/README.md Shows how minitest-spec-rails supports multiple setup and teardown methods, including those defined by symbols or blocks, which are evaluated in the instance scope, similar to standard ActiveSupport callbacks. ```Ruby class ActiveSupportCallbackTest < ActiveSupport::TestCase setup :foo setup :bar before { @bat = 'biz' } it 'works' do expect(@foo).must_equal 'foo' expect(@bar).must_equal 'bar' expect(@bat).must_equal 'biz' end private def foo ; @foo = 'foo' ; end def bar ; @bar = 'bar' ; end end ``` -------------------------------- ### `mini_shoulda` Usage Example Source: https://github.com/metaskills/minitest-spec-rails/blob/master/README.md Provides an example of using the `mini_shoulda` aliases (`should`, `context`, `should_eventually`) for writing tests, mimicking the syntax of the Shoulda testing framework. ```Ruby class PostTests < ActiveSupport::TestCase setup { @post = Post.create! :title => 'Test Title', :body => 'Test body' } teardown { Post.delete_all } should 'work' do @post.must_be_instance_of Post end context 'with a user' do should_eventually 'have a user' do # ... end end end ``` -------------------------------- ### Example Minitest::Spec Test Case in Rails Source: https://github.com/metaskills/minitest-spec-rails/blob/master/README.md A practical example of a test case written using the Minitest::Spec DSL within a Rails application. It demonstrates defining a fixture using `let` and asserting object type. ```ruby require 'test_helper' class UserTest < ActiveSupport::TestCase let(:user_ken) { User.create! :email => 'ken@metaskills.net' } it 'works' do expect(user_ken).must_be_instance_of User end end ``` -------------------------------- ### Rails Test Case Subclassing Examples Source: https://github.com/metaskills/minitest-spec-rails/blob/master/README.md Provides examples of how to structure test files for different types of Rails components (Models, Controllers, Integration, Mailers) using appropriate `ActiveSupport::TestCase` subclasses. ```ruby # Model Test (or anything else not listed below) class UserTest < ActiveSupport::TestCase end # Controller Test class UsersControllerTest < ActionController::TestCase end # Integration Tests - Must use subclass style! class IntegrationTest < ActionDispatch::IntegrationTest end # Mailer Test class UserMailerTest < ActionMailer::TestCase end ``` -------------------------------- ### Minitest Assertion Style Examples Source: https://github.com/metaskills/minitest-spec-rails/blob/master/README.md Illustrates the interchangeability of Minitest::Unit and Minitest::Spec assertion styles within the same test suite. This allows for gradual migration from older styles. ```ruby # Minitest::Unit Assertion Style: assert_equal 100, foo # Minitest::Spec Assertion Style: expect(foo).must_equal 100 ``` -------------------------------- ### Basic Gem Installation for minitest-spec-rails Source: https://github.com/metaskills/minitest-spec-rails/blob/master/README.md A simple instruction to include the minitest-spec-rails gem in your project's dependencies. This is the most straightforward way to add the gem. ```ruby gem 'minitest-spec-rails' ``` -------------------------------- ### Using `minitest-matchers` Gem Source: https://github.com/metaskills/minitest-spec-rails/blob/master/README.md Demonstrates how to use the `minitest-matchers` gem for writing tests, specifically showing examples of `must have_valid` and `wont have_valid` assertions for attribute validation testing. ```Ruby describe Post do subject { Post.new } it { must have_valid(:title).when("Hello") } it { wont have_valid(:title).when("", nil, "Bad") } end ``` -------------------------------- ### Using `described_class` Helper Source: https://github.com/metaskills/minitest-spec-rails/blob/master/README.md Illustrates the `described_class` helper method, available as both a class and instance method, which returns the class currently being tested. It works across nested describe blocks, provided Rails naming conventions are followed. ```Ruby class UserTest < ActiveSupport::TestCase described_class # => User(id: integer, email: string) it 'works here' do described_class # => User(id: integer, email: string) end describe 'and' do it 'works here too' do described_class # => User(id: integer, email: string) end end end ``` -------------------------------- ### Basic Minitest Test Cases Source: https://github.com/metaskills/minitest-spec-rails/blob/master/README.md Demonstrates the basic structure for defining test cases using Minitest with Rails-specific test classes like ActionView::TestCase and ActiveJob::TestCase. ```Ruby class UsersHelperTest < ActionView::TestCase end class MyJobTest < ActiveJob::TestCase end ``` -------------------------------- ### Enabling `mini_shoulda` Feature Source: https://github.com/metaskills/minitest-spec-rails/blob/master/README.md Demonstrates how to enable the `mini_shoulda` feature in `config/environments/test.rb` to gain aliases for Shoulda's `context`, `should`, and `should_eventually` methods, facilitating migration from Shoulda. ```Ruby # In config/environments/test.rb config.minitest_spec_rails.mini_shoulda = true ``` -------------------------------- ### Replacing Shoulda Assertions with Minitest Source: https://github.com/metaskills/minitest-spec-rails/blob/master/README.md Shows common patterns for replacing Shoulda assertion methods with their Minitest equivalents, advocating for modern Minitest syntax over older assertion styles. ```Ruby assert_same_elements a, b # From expect(a.sort).must_equal b.sort # To assert_does_not_contain a, b # From expect(a).wont_include b # To ``` -------------------------------- ### Using `minitest-matchers-vaccine` Gem Source: https://github.com/metaskills/minitest-spec-rails/blob/master/README.md Illustrates the usage of the `minitest-matchers-vaccine` gem, which provides similar assertion capabilities to `minitest-matchers` but aims to avoid polluting tested objects. ```Ruby describe User do subject { User.new } it "should validate email" do must have_valid(:email).when("a@a.com", "foo@bar.com") wont have_valid(:email).when(nil, "", "foo", "foo@bar") end end ``` -------------------------------- ### Add minitest-spec-rails Gem for Rails 4.1 to 6.0 Source: https://github.com/metaskills/minitest-spec-rails/blob/master/README.md This snippet shows how to add the minitest-spec-rails gem to your Rails application's Gemfile for versions 4.1 through 6.0. It's placed within the `:test` group. ```ruby group :test do gem 'minitest-spec-rails' end ``` -------------------------------- ### Disable Mocha Deprecation Warnings Source: https://github.com/metaskills/minitest-spec-rails/blob/master/README.md Configures Mocha to disable deprecation warnings, ensuring compatibility with newer Minitest versions. This snippet should be placed in `application.rb` after `require 'rails/all'`. ```ruby require 'mocha/deprecation' Mocha::Deprecation.mode = :disabled ``` -------------------------------- ### Add minitest-spec-rails Gem for Rails 3.x or 4.0 Source: https://github.com/metaskills/minitest-spec-rails/blob/master/README.md This snippet demonstrates how to add a specific version of the minitest-spec-rails gem to your Rails application's Gemfile for compatibility with Rails 3.x or 4.0. It targets the '~> 4.7' version. ```ruby group :test do gem 'minitest-spec-rails', '~> 4.7' end ``` -------------------------------- ### Rails 3.0 Controller/Mailer Test Interface Source: https://github.com/metaskills/minitest-spec-rails/blob/master/README.md Specifies the `tests` interface for controller and mailer tests in Rails 3.0.x. This is a workaround for a potential `class_attribute` bug in Rails 3.0, ensuring assertions are correctly set up within sub `describe` blocks. ```ruby class UsersControllerTest < ActionController::TestCase tests UsersController end class UserMailerTest < ActionMailer::TestCase tests UserMailer end ``` -------------------------------- ### Minitest Assertion Renaming Source: https://github.com/metaskills/minitest-spec-rails/blob/master/README.md Highlights assertion method renames when migrating from Test::Unit to Minitest, specifically noting `assert_raise` becoming `assert_raises` and the absence of `assert_nothing_raised`. ```Ruby # Renamed: assert_raise -> assert_raises # Removed: assert_nothing_raised ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.