How to configure minitest for integration tests using the unit style
-
09-12-2019 - |
Question
I found resources for configuring Rails to use Minitest. Most of the resources, unfortunately, assume the use of Minitest Spec for all the test types or, in the best case, at least for the integration test.
I may be "vintage", but I feel the assertions ala test:unit work better for me than the rspec style. I would use MiniTest::Unit declaration style, together with Capybara, to run the integration tests.
I am interested in seeing an example of minitest_helper.rb and some_model_integration_test.rb to understand the relevant configuration elements I need to put in place to make the integration test work nicely with Capybara.
Can somebody explain how to configure Rails for this?
Solution
My articles_integration_test.rb
:
require 'test_helper'
class ArticlesIntegrationTest < IntegrationTest
def test_shows_article_title
article = Article.create!(title: 'Foo bar')
visit article_path(article)
assert page.has_content?('Foo bar')
end
end
My test_helper.rb
:
ENV["RAILS_ENV"] = "test"
require File.expand_path("../../config/environment", __FILE__)
require "minitest/autorun"
require "capybara/rails"
require "active_support/testing/setup_and_teardown"
class IntegrationTest < MiniTest::Unit::TestCase
include Rails.application.routes.url_helpers
include Capybara::DSL
end