Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure minitest for integration tests using the unit style

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?

like image 960
Topo Avatar asked Mar 09 '12 00:03

Topo


1 Answers

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
like image 151
Lee Jarvis Avatar answered Oct 11 '22 18:10

Lee Jarvis