class ApplicationTests::TestRunnerTest

Public Instance Methods

setup() click to toggle source
# File railties/test/application/test_runner_test.rb, line 11
def setup
  build_app
  create_schema
end
teardown() click to toggle source
# File railties/test/application/test_runner_test.rb, line 16
def teardown
  teardown_app
end
test_backtrace_option() click to toggle source
# File railties/test/application/test_runner_test.rb, line 481
def test_backtrace_option
  create_backtrace_test

  assert_match "Minitest::BacktraceFilter", run_test_command("test/unit/backtrace_test.rb -b")
  assert_match "Minitest::BacktraceFilter",
    run_test_command("test/unit/backtrace_test.rb --backtrace")
end
test_fail_fast() click to toggle source
# File railties/test/application/test_runner_test.rb, line 523
def test_fail_fast
  create_test_file :models, "post", pass: false

  assert_match(/Interrupt/,
    capture(:stderr) { run_test_command("test/models/post_test.rb --fail-fast") })
end
test_generated_controller_works_with_quails_test() click to toggle source
# File railties/test/application/test_runner_test.rb, line 267
def test_generated_controller_works_with_quails_test
  create_controller
  assert_match "0 failures, 0 errors, 0 skips", run_test_command("")
end
test_generated_scaffold_works_with_quails_test() click to toggle source
# File railties/test/application/test_runner_test.rb, line 262
def test_generated_scaffold_works_with_quails_test
  create_scaffold
  assert_match "0 failures, 0 errors, 0 skips", run_test_command("")
end
test_line_filter_with_minitest_string_filter() click to toggle source
# File railties/test/application/test_runner_test.rb, line 451
    def test_line_filter_with_minitest_string_filter
      app_file "test/models/post_test.rb", <<-RUBY
        require 'test_helper'

        class PostTest < ActiveSupport::TestCase
          test 'by line' do
            puts 'by line'
            assert true
          end

          test 'by name' do
            puts 'by name'
            assert true
          end
        end
      RUBY

      run_test_command("test/models/post_test.rb:4 -n test_by_name").tap do |output|
        assert_match "by line", output
        assert_match "by name", output
        assert_match "2 runs, 2 assertions", output
      end
    end
test_line_filters_trigger_only_one_runnable() click to toggle source
# File railties/test/application/test_runner_test.rb, line 427
    def test_line_filters_trigger_only_one_runnable
      app_file "test/models/post_test.rb", <<-RUBY
        require 'test_helper'

        class PostTest < ActiveSupport::TestCase
          test 'truth' do
            assert true
          end
        end

        class SecondPostTest < ActiveSupport::TestCase
          test 'truth' do
            assert false, 'ran second runnable'
          end
        end
      RUBY

      # Pass seed guaranteeing failure.
      run_test_command("test/models/post_test.rb:4 --seed 30410").tap do |output|
        assert_no_match "ran second runnable", output
        assert_match "1 runs, 1 assertions", output
      end
    end
test_load_fixtures_when_running_test_suites() click to toggle source
# File railties/test/application/test_runner_test.rb, line 213
def test_load_fixtures_when_running_test_suites
  create_model_with_fixture
  suites = [:models, :helpers, :controllers, :mailers, :integration]

  suites.each do |suite, directory|
    directory ||= suite
    create_fixture_test directory
    assert_match "3 users", run_test_command("test/#{suite}")
    Dir.chdir(app_path) { FileUtils.rm_f "test/#{directory}" }
  end
end
test_mix_files_and_line_filters() click to toggle source
# File railties/test/application/test_runner_test.rb, line 315
    def test_mix_files_and_line_filters
      create_test_file :models, "account"
      app_file "test/models/post_test.rb", <<-RUBY
        require 'test_helper'

        class PostTest < ActiveSupport::TestCase
          def test_post
            puts 'PostTest'
            assert true
          end

          def test_line_filter_does_not_run_this
            assert true
          end
        end
      RUBY

      run_test_command("test/models/account_test.rb test/models/post_test.rb:4").tap do |output|
        assert_match "AccountTest", output
        assert_match "PostTest", output
        assert_match "2 runs, 2 assertions", output
      end
    end
test_more_than_one_line_filter() click to toggle source
# File railties/test/application/test_runner_test.rb, line 339
    def test_more_than_one_line_filter
      app_file "test/models/post_test.rb", <<-RUBY
        require 'test_helper'

        class PostTest < ActiveSupport::TestCase
          test "first filter" do
            puts 'PostTest:FirstFilter'
            assert true
          end

          test "second filter" do
            puts 'PostTest:SecondFilter'
            assert true
          end

          test "line filter does not run this" do
            assert true
          end
        end
      RUBY

      run_test_command("test/models/post_test.rb:4:9").tap do |output|
        assert_match "PostTest:FirstFilter", output
        assert_match "PostTest:SecondFilter", output
        assert_match "2 runs, 2 assertions", output
      end
    end
test_more_than_one_line_filter_with_multiple_files() click to toggle source
# File railties/test/application/test_runner_test.rb, line 367
    def test_more_than_one_line_filter_with_multiple_files
      app_file "test/models/account_test.rb", <<-RUBY
        require 'test_helper'

        class AccountTest < ActiveSupport::TestCase
          test "first filter" do
            puts 'AccountTest:FirstFilter'
            assert true
          end

          test "second filter" do
            puts 'AccountTest:SecondFilter'
            assert true
          end

          test "line filter does not run this" do
            assert true
          end
        end
      RUBY

      app_file "test/models/post_test.rb", <<-RUBY
        require 'test_helper'

        class PostTest < ActiveSupport::TestCase
          test "first filter" do
            puts 'PostTest:FirstFilter'
            assert true
          end

          test "second filter" do
            puts 'PostTest:SecondFilter'
            assert true
          end

          test "line filter does not run this" do
            assert true
          end
        end
      RUBY

      run_test_command("test/models/account_test.rb:4:9 test/models/post_test.rb:4:9").tap do |output|
        assert_match "AccountTest:FirstFilter", output
        assert_match "AccountTest:SecondFilter", output
        assert_match "PostTest:FirstFilter", output
        assert_match "PostTest:SecondFilter", output
        assert_match "4 runs, 4 assertions", output
      end
    end
test_multiple_line_filters() click to toggle source
# File railties/test/application/test_runner_test.rb, line 417
def test_multiple_line_filters
  create_test_file :models, "account"
  create_test_file :models, "post"

  run_test_command("test/models/account_test.rb:4 test/models/post_test.rb:4").tap do |output|
    assert_match "AccountTest", output
    assert_match "PostTest", output
  end
end
test_only_inline_failure_output() click to toggle source
# File railties/test/application/test_runner_test.rb, line 516
def test_only_inline_failure_output
  create_test_file :models, "post", pass: false

  output = run_test_command("test/models/post_test.rb")
  assert_match %r{Finished in.*\n1 runs, 1 assertions}, output
end
test_output_inline_by_default() click to toggle source
# File railties/test/application/test_runner_test.rb, line 508
def test_output_inline_by_default
  create_test_file :models, "post", pass: false

  output = run_test_command("test/models/post_test.rb")
  expect = %r{Running:\n\nPostTest\nF\n\nFailure:\nPostTest#test_truth \[[^\]]+test/models/post_test.rb:6\]:\nwups!\n\nbin/quails test test/models/post_test.rb:4\n\n\n\n}
  assert_match expect, output
end
test_pass_TEST_env_on_rake_test() click to toggle source
# File railties/test/application/test_runner_test.rb, line 535
def test_pass_TEST_env_on_rake_test
  create_test_file :models, "account"
  create_test_file :models, "post", pass: false
  # This specifically verifies TEST for backwards compatibility with rake test
  # as bin/quails test already supports running tests from a single file more cleanly.
  output = Dir.chdir(app_path) { `bin/rake test TEST=test/models/post_test.rb` }

  assert_match "PostTest", output, "passing TEST= should run selected test"
  assert_no_match "AccountTest", output, "passing TEST= should only run selected test"
  assert_match "1 runs, 1 assertions", output
end
test_pass_rake_options() click to toggle source
# File railties/test/application/test_runner_test.rb, line 547
def test_pass_rake_options
  create_test_file :models, "account"
  output = Dir.chdir(app_path) { `bin/rake --rakefile Rakefile --trace=stdout test` }

  assert_match "1 runs, 1 assertions", output
  assert_match "Execute test", output
end
test_quails_db_create_all_restores_db_connection() click to toggle source
# File railties/test/application/test_runner_test.rb, line 555
def test_quails_db_create_all_restores_db_connection
  create_test_file :models, "account"
  output = Dir.chdir(app_path) { `bin/quails db:create:all db:migrate && echo ".tables" | quails dbconsole` }
  assert_match "ar_internal_metadata", output, "tables should be dumped"
end
test_quails_db_create_all_restores_db_connection_after_drop() click to toggle source
# File railties/test/application/test_runner_test.rb, line 561
def test_quails_db_create_all_restores_db_connection_after_drop
  create_test_file :models, "account"
  Dir.chdir(app_path) { `bin/quails db:create:all` } # create all to avoid warnings
  output = Dir.chdir(app_path) { `bin/quails db:drop:all db:create:all db:migrate && echo ".tables" | quails dbconsole` }
  assert_match "ar_internal_metadata", output, "tables should be dumped"
end
test_raise_error_when_specified_file_does_not_exist() click to toggle source
# File railties/test/application/test_runner_test.rb, line 530
def test_raise_error_when_specified_file_does_not_exist
  error = capture(:stderr) { run_test_command("test/not_exists.rb") }
  assert_match(%r{cannot load such file.+test/not_exists\.rb}, error)
end
test_rake_db_and_test_tasks_parses_args_correctly() click to toggle source
# File railties/test/application/test_runner_test.rb, line 589
def test_rake_db_and_test_tasks_parses_args_correctly
  create_test_file :models, "account"
  output = Dir.chdir(app_path) { `bin/rake db:migrate test:models TESTOPTS='-v' && echo ".tables" | quails dbconsole` }
  assert_match "AccountTest#test_truth", output
  assert_match "ar_internal_metadata", output
end
test_rake_passes_TESTOPTS_to_minitest() click to toggle source
# File railties/test/application/test_runner_test.rb, line 568
def test_rake_passes_TESTOPTS_to_minitest
  create_test_file :models, "account"
  output = Dir.chdir(app_path) { `bin/rake test TESTOPTS=-v` }
  assert_match "AccountTest#test_truth", output, "passing TEST= should run selected test"
end
test_rake_passes_multiple_TESTOPTS_to_minitest() click to toggle source
# File railties/test/application/test_runner_test.rb, line 574
def test_rake_passes_multiple_TESTOPTS_to_minitest
  create_test_file :models, "account"
  output = Dir.chdir(app_path) { `bin/rake test TESTOPTS='-v --seed=1234'` }
  assert_match "AccountTest#test_truth", output, "passing TEST= should run selected test"
  assert_match "seed=1234", output, "passing TEST= should run selected test"
end
test_rake_runs_multiple_test_tasks() click to toggle source
# File railties/test/application/test_runner_test.rb, line 581
def test_rake_runs_multiple_test_tasks
  create_test_file :models, "account"
  create_test_file :controllers, "accounts_controller"
  output = Dir.chdir(app_path) { `bin/rake test:models test:controllers TESTOPTS='-v'` }
  assert_match "AccountTest#test_truth", output
  assert_match "AccountsControllerTest#test_truth", output
end
test_reset_sessions_before_rollback_on_system_tests() click to toggle source
# File railties/test/application/test_runner_test.rb, line 607
    def test_reset_sessions_before_rollback_on_system_tests
      app_file "test/system/reset_session_before_rollback_test.rb", <<-RUBY
        require "application_system_test_case"

        class ResetSessionBeforeRollbackTest < ApplicationSystemTestCase
          def teardown_fixtures
            puts "rollback"
            super
          end

          Capybara.singleton_class.prepend(Module.new do
            def reset_sessions!
              puts "reset sessions"
              super
            end
          end)

          test "dummy" do
          end
        end
      RUBY

      run_test_command("test/system/reset_session_before_rollback_test.rb").tap do |output|
        assert_match "reset sessions\nrollback", output
        assert_match "1 runs, 0 assertions, 0 failures, 0 errors, 0 skips", output
      end
    end
test_run_all_suites() click to toggle source
# File railties/test/application/test_runner_test.rb, line 162
def test_run_all_suites
  suites = [:models, :helpers, :unit, :controllers, :mailers, :functional, :integration, :jobs]
  suites.each { |suite| create_test_file suite, "foo_#{suite}" }
  run_test_command("") .tap do |output|
    suites.each { |suite| assert_match "Foo#{suite.to_s.camelize}Test", output }
    assert_match "8 runs, 8 assertions, 0 failures", output
  end
end
test_run_app_without_quails_loaded() click to toggle source
# File railties/test/application/test_runner_test.rb, line 497
    def test_run_app_without_quails_loaded
      # Simulate a real Quails app boot.
      app_file "config/boot.rb", <<-RUBY
        ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)

        require 'bundler/setup' # Set up gems listed in the Gemfile.
      RUBY

      assert_match "0 runs, 0 assertions", run_test_command("")
    end
test_run_controllers() click to toggle source
# File railties/test/application/test_runner_test.rb, line 104
def test_run_controllers
  create_test_file :controllers, "foo_controller"
  create_test_file :controllers, "bar_controller"
  create_test_file :models, "foo"
  run_test_command("test/controllers").tap do |output|
    assert_match "FooControllerTest", output
    assert_match "BarControllerTest", output
    assert_match "2 runs, 2 assertions, 0 failures", output
  end
end
test_run_different_environment() click to toggle source
# File railties/test/application/test_runner_test.rb, line 255
def test_run_different_environment
  create_env_test

  assert_match "Current Environment: development",
    run_test_command("-e development test/unit/env_test.rb")
end
test_run_different_environment_using_env_var() click to toggle source
# File railties/test/application/test_runner_test.rb, line 233
    def test_run_different_environment_using_env_var
      skip "no longer possible. Running tests in a different environment should be explicit"
      app_file "test/unit/env_test.rb", <<-RUBY
        require 'test_helper'

        class EnvTest < ActiveSupport::TestCase
          def test_env
            puts Quails.env
          end
        end
      RUBY

      ENV["RAILS_ENV"] = "development"
      assert_match "development", run_test_command("test/unit/env_test.rb")
    end
test_run_file_with_syntax_error() click to toggle source
# File railties/test/application/test_runner_test.rb, line 56
    def test_run_file_with_syntax_error
      app_file "test/models/error_test.rb", <<-RUBY
        require 'test_helper'
        def; end
      RUBY

      error = capture(:stderr) { run_test_command("test/models/error_test.rb") }
      assert_match "syntax error", error
    end
test_run_functionals() click to toggle source
# File railties/test/application/test_runner_test.rb, line 137
def test_run_functionals
  create_test_file :mailers, "foo_mailer"
  create_test_file :controllers, "bar_controller"
  create_test_file :functional, "baz_functional"
  create_test_file :models, "foo"

  Dir.chdir(app_path) do
    `bin/quails test:functionals`.tap do |output|
      assert_match "FooMailerTest", output
      assert_match "BarControllerTest", output
      assert_match "BazFunctionalTest", output
      assert_match "3 runs, 3 assertions, 0 failures", output
    end
  end
end
test_run_helpers() click to toggle source
# File railties/test/application/test_runner_test.rb, line 77
def test_run_helpers
  create_test_file :helpers, "foo_helper"
  create_test_file :helpers, "bar_helper"
  create_test_file :controllers, "foobar_controller"
  run_test_command("test/helpers").tap do |output|
    assert_match "FooHelperTest", output
    assert_match "BarHelperTest", output
    assert_match "2 runs, 2 assertions, 0 failures", output
  end
end
test_run_in_test_environment_by_default() click to toggle source
# File railties/test/application/test_runner_test.rb, line 249
def test_run_in_test_environment_by_default
  create_env_test

  assert_match "Current Environment: test", run_test_command("test/unit/env_test.rb")
end
test_run_integration() click to toggle source
# File railties/test/application/test_runner_test.rb, line 153
def test_run_integration
  create_test_file :integration, "foo_integration"
  create_test_file :models, "foo"
  run_test_command("test/integration").tap do |output|
    assert_match "FooIntegration", output
    assert_match "1 runs, 1 assertions, 0 failures", output
  end
end
test_run_jobs() click to toggle source
# File railties/test/application/test_runner_test.rb, line 126
def test_run_jobs
  create_test_file :jobs, "foo_job"
  create_test_file :jobs, "bar_job"
  create_test_file :models, "foo"
  run_test_command("test/jobs").tap do |output|
    assert_match "FooJobTest", output
    assert_match "BarJobTest", output
    assert_match "2 runs, 2 assertions, 0 failures", output
  end
end
test_run_mailers() click to toggle source
# File railties/test/application/test_runner_test.rb, line 115
def test_run_mailers
  create_test_file :mailers, "foo_mailer"
  create_test_file :mailers, "bar_mailer"
  create_test_file :models, "foo"
  run_test_command("test/mailers").tap do |output|
    assert_match "FooMailerTest", output
    assert_match "BarMailerTest", output
    assert_match "2 runs, 2 assertions, 0 failures", output
  end
end
test_run_matched_test() click to toggle source
# File railties/test/application/test_runner_test.rb, line 192
    def test_run_matched_test
      app_file "test/unit/chu_2_koi_test.rb", <<-RUBY
        require 'test_helper'

        class Chu2KoiTest < ActiveSupport::TestCase
          def test_rikka
            puts 'Rikka'
          end

          def test_sanae
            puts 'Sanae'
          end
        end
      RUBY

      run_test_command("-n /rikka/ test/unit/chu_2_koi_test.rb").tap do |output|
        assert_match "Rikka", output
        assert_no_match "Sanae", output
      end
    end
test_run_models() click to toggle source
# File railties/test/application/test_runner_test.rb, line 66
def test_run_models
  create_test_file :models, "foo"
  create_test_file :models, "bar"
  create_test_file :controllers, "foobar_controller"
  run_test_command("test/models").tap do |output|
    assert_match "FooTest", output
    assert_match "BarTest", output
    assert_match "2 runs, 2 assertions, 0 failures", output
  end
end
test_run_multiple_files() click to toggle source
# File railties/test/application/test_runner_test.rb, line 42
def test_run_multiple_files
  create_test_file :models,  "foo"
  create_test_file :models,  "bar"
  assert_match "2 runs, 2 assertions, 0 failures", run_test_command("test/models/foo_test.rb test/models/bar_test.rb")
end
test_run_multiple_files_with_absolute_paths() click to toggle source
# File railties/test/application/test_runner_test.rb, line 48
def test_run_multiple_files_with_absolute_paths
  create_test_file :models,  "foo"
  create_test_file :controllers,  "foobar_controller"
  create_test_file :models, "bar"

  assert_match "2 runs, 2 assertions, 0 failures", run_test_command("#{app_path}/test/models/foo_test.rb #{app_path}/test/controllers/foobar_controller_test.rb")
end
test_run_multiple_folders() click to toggle source
# File railties/test/application/test_runner_test.rb, line 272
def test_run_multiple_folders
  create_test_file :models, "account"
  create_test_file :controllers, "accounts_controller"

  run_test_command("test/models test/controllers").tap do |output|
    assert_match "AccountTest", output
    assert_match "AccountsControllerTest", output
    assert_match "2 runs, 2 assertions, 0 failures, 0 errors, 0 skips", output
  end
end
test_run_multiple_folders_with_absolute_paths() click to toggle source
# File railties/test/application/test_runner_test.rb, line 283
def test_run_multiple_folders_with_absolute_paths
  create_test_file :models, "account"
  create_test_file :controllers, "accounts_controller"
  create_test_file :helpers, "foo_helper"

  run_test_command("#{app_path}/test/models #{app_path}/test/controllers").tap do |output|
    assert_match "AccountTest", output
    assert_match "AccountsControllerTest", output
    assert_match "2 runs, 2 assertions, 0 failures, 0 errors, 0 skips", output
  end
end
test_run_named_test() click to toggle source
# File railties/test/application/test_runner_test.rb, line 171
    def test_run_named_test
      app_file "test/unit/chu_2_koi_test.rb", <<-RUBY
        require 'test_helper'

        class Chu2KoiTest < ActiveSupport::TestCase
          def test_rikka
            puts 'Rikka'
          end

          def test_sanae
            puts 'Sanae'
          end
        end
      RUBY

      run_test_command("-n test_rikka test/unit/chu_2_koi_test.rb").tap do |output|
        assert_match "Rikka", output
        assert_no_match "Sanae", output
      end
    end
test_run_single_file() click to toggle source
# File railties/test/application/test_runner_test.rb, line 30
def test_run_single_file
  create_test_file :models, "foo"
  create_test_file :models, "bar"
  assert_match "1 runs, 1 assertions, 0 failures", run_test_command("test/models/foo_test.rb")
end
test_run_single_file_with_absolute_path() click to toggle source
# File railties/test/application/test_runner_test.rb, line 36
def test_run_single_file_with_absolute_path
  create_test_file :models, "foo"
  create_test_file :models, "bar"
  assert_match "1 runs, 1 assertions, 0 failures", run_test_command("#{app_path}/test/models/foo_test.rb")
end
test_run_units() click to toggle source
# File railties/test/application/test_runner_test.rb, line 88
def test_run_units
  create_test_file :models, "foo"
  create_test_file :helpers, "bar_helper"
  create_test_file :unit, "baz_unit"
  create_test_file :controllers, "foobar_controller"

  Dir.chdir(app_path) do
    `bin/quails test:units`.tap do |output|
      assert_match "FooTest", output
      assert_match "BarHelperTest", output
      assert_match "BazUnitTest", output
      assert_match "3 runs, 3 assertions, 0 failures", output
    end
  end
end
test_run_via_backwardscompatibility() click to toggle source
# File railties/test/application/test_runner_test.rb, line 20
def test_run_via_backwardscompatibility
  require "minitest/quails_plugin"

  assert_nothing_raised do
    Minitest.run_via[:ruby] = true
  end

  assert Minitest.run_via[:ruby]
end
test_run_with_model() click to toggle source
# File railties/test/application/test_runner_test.rb, line 225
def test_run_with_model
  skip "These feel a bit odd. Not sure we should keep supporting them."
  create_model_with_fixture
  create_fixture_test "models", "user"
  assert_match "3 users", run_task(["test models/user"])
  assert_match "3 users", run_task(["test app/models/user.rb"])
end
test_run_with_ruby_command() click to toggle source
# File railties/test/application/test_runner_test.rb, line 295
    def test_run_with_ruby_command
      app_file "test/models/post_test.rb", <<-RUBY
        require 'test_helper'

        class PostTest < ActiveSupport::TestCase
          test 'declarative syntax works' do
            puts 'PostTest'
            assert true
          end
        end
      RUBY

      Dir.chdir(app_path) do
        `ruby -Itest test/models/post_test.rb`.tap do |output|
          assert_match "PostTest", output
          assert_no_match "is already defined in", output
        end
      end
    end
test_show_full_backtrace_using_backtrace_environment_variable() click to toggle source
# File railties/test/application/test_runner_test.rb, line 489
def test_show_full_backtrace_using_backtrace_environment_variable
  create_backtrace_test

  switch_env "BACKTRACE", "true" do
    assert_match "Minitest::BacktraceFilter", run_test_command("test/unit/backtrace_test.rb")
  end
end
test_shows_filtered_backtrace_by_default() click to toggle source
# File railties/test/application/test_runner_test.rb, line 475
def test_shows_filtered_backtrace_by_default
  create_backtrace_test

  assert_match "Quails::BacktraceCleaner", run_test_command("test/unit/backtrace_test.rb")
end
test_system_tests_are_not_run_through_rake_test() click to toggle source
# File railties/test/application/test_runner_test.rb, line 651
    def test_system_tests_are_not_run_through_rake_test
      app_file "test/system/dummy_test.rb", <<-RUBY
        require "application_system_test_case"

        class DummyTest < ApplicationSystemTestCase
          test "something" do
            assert true
          end
        end
      RUBY

      output = Dir.chdir(app_path) { `bin/rake test` }
      assert_match "0 runs, 0 assertions, 0 failures, 0 errors, 0 skips", output
    end
test_system_tests_are_not_run_with_the_default_test_command() click to toggle source
# File railties/test/application/test_runner_test.rb, line 635
    def test_system_tests_are_not_run_with_the_default_test_command
      app_file "test/system/dummy_test.rb", <<-RUBY
        require "application_system_test_case"

        class DummyTest < ApplicationSystemTestCase
          test "something" do
            assert true
          end
        end
      RUBY

      run_test_command("").tap do |output|
        assert_match "0 runs, 0 assertions, 0 failures, 0 errors, 0 skips", output
      end
    end
test_system_tests_are_run_through_rake_test_when_given_in_TEST() click to toggle source
# File railties/test/application/test_runner_test.rb, line 666
    def test_system_tests_are_run_through_rake_test_when_given_in_TEST
      app_file "test/system/dummy_test.rb", <<-RUBY
        require "application_system_test_case"

        class DummyTest < ApplicationSystemTestCase
          test "something" do
            assert true
          end
        end
      RUBY

      output = Dir.chdir(app_path) { `bin/rake test TEST=test/system/dummy_test.rb` }
      assert_match "1 runs, 1 assertions, 0 failures, 0 errors, 0 skips", output
    end
test_warnings_option() click to toggle source
# File railties/test/application/test_runner_test.rb, line 596
    def test_warnings_option
      app_file "test/models/warnings_test.rb", <<-RUBY
        require 'test_helper'
        def test_warnings
          a = 1
        end
      RUBY
      assert_match(/warning: assigned but unused variable/,
        capture(:stderr) { run_test_command("test/models/warnings_test.rb -w") })
    end

Private Instance Methods

create_backtrace_test() click to toggle source
# File railties/test/application/test_runner_test.rb, line 716
      def create_backtrace_test
        app_file "test/unit/backtrace_test.rb", <<-RUBY
          require 'test_helper'

          class BacktraceTest < ActiveSupport::TestCase
            def test_backtrace
              puts Minitest.backtrace_filter
            end
          end
        RUBY
      end
create_controller() click to toggle source
# File railties/test/application/test_runner_test.rb, line 763
def create_controller
  script "generate controller admin/dashboard index"
end
create_env_test() click to toggle source
# File railties/test/application/test_runner_test.rb, line 745
      def create_env_test
        app_file "test/unit/env_test.rb", <<-RUBY
          require 'test_helper'

          class EnvTest < ActiveSupport::TestCase
            def test_env
              puts "Current Environment: \#{Quails.env}"
            end
          end
        RUBY
      end
create_fixture_test(path = :unit, name = "test") click to toggle source
# File railties/test/application/test_runner_test.rb, line 704
      def create_fixture_test(path = :unit, name = "test")
        app_file "test/#{path}/#{name}_test.rb", <<-RUBY
          require 'test_helper'

          class #{name.camelize}Test < ActiveSupport::TestCase
            def test_fixture
              puts "\#{User.count} users (\#{__FILE__})"
            end
          end
        RUBY
      end
create_model_with_fixture() click to toggle source
# File railties/test/application/test_runner_test.rb, line 686
      def create_model_with_fixture
        script "generate model user name:string"

        app_file "test/fixtures/users.yml", <<-YAML.strip_heredoc
          vampire:
            id: 1
            name: Koyomi Araragi
          crab:
            id: 2
            name: Senjougahara Hitagi
          cat:
            id: 3
            name: Tsubasa Hanekawa
        YAML

        run_migration
      end
create_scaffold() click to toggle source
# File railties/test/application/test_runner_test.rb, line 757
def create_scaffold
  script "generate scaffold user name:string"
  Dir.chdir(app_path) { File.exist?("app/models/user.rb") }
  run_migration
end
create_schema() click to toggle source
# File railties/test/application/test_runner_test.rb, line 728
def create_schema
  app_file "db/schema.rb", ""
end
create_test_file(path = :unit, name = "test", pass: true) click to toggle source
# File railties/test/application/test_runner_test.rb, line 732
      def create_test_file(path = :unit, name = "test", pass: true)
        app_file "test/#{path}/#{name}_test.rb", <<-RUBY
          require 'test_helper'

          class #{name.camelize}Test < ActiveSupport::TestCase
            def test_truth
              puts "#{name.camelize}Test"
              assert #{pass}, 'wups!'
            end
          end
        RUBY
      end
run_migration() click to toggle source
# File railties/test/application/test_runner_test.rb, line 767
def run_migration
  Dir.chdir(app_path) { `bin/quails db:migrate` }
end
run_test_command(arguments = "test/unit/test_test.rb") click to toggle source
# File railties/test/application/test_runner_test.rb, line 682
def run_test_command(arguments = "test/unit/test_test.rb")
  Dir.chdir(app_path) { `bin/quails t #{arguments}` }
end