class ApplicationTests::RunnerTest

Public Instance Methods

setup() click to toggle source
# File railties/test/application/runner_test.rb, line 11
    def setup
      build_app

      # Lets create a model so we have something to play with
      app_file "app/models/user.rb", <<-MODEL
      class User
        def self.count
          42
        end
      end
      MODEL
    end
teardown() click to toggle source
# File railties/test/application/runner_test.rb, line 24
def teardown
  teardown_app
end
test_default_environment() click to toggle source
# File railties/test/application/runner_test.rb, line 107
def test_default_environment
  assert_match "development", Dir.chdir(app_path) { `bin/quails runner "puts Quails.env"` }
end
test_environment_with_quails_env() click to toggle source
# File railties/test/application/runner_test.rb, line 123
def test_environment_with_quails_env
  with_quails_env "production" do
    assert_match "production", Dir.chdir(app_path) { `bin/quails runner "puts Quails.env"` }
  end
end
test_environment_with_rack_env() click to toggle source
# File railties/test/application/runner_test.rb, line 129
def test_environment_with_rack_env
  with_rack_env "production" do
    assert_match "production", Dir.chdir(app_path) { `bin/quails runner "puts Quails.env"` }
  end
end
test_no_minitest_loaded_in_production_mode() click to toggle source
# File railties/test/application/runner_test.rb, line 56
    def test_no_minitest_loaded_in_production_mode
      app_file "bin/print_features.rb", <<-SCRIPT
      p $LOADED_FEATURES.grep(/minitest/)
      SCRIPT
      assert_match "[]", Dir.chdir(app_path) {
        `RAILS_ENV=production bin/quails runner "bin/print_features.rb"`
      }
    end
test_passes_extra_args_to_file() click to toggle source
# File railties/test/application/runner_test.rb, line 81
    def test_passes_extra_args_to_file
      app_file "bin/program_name.rb", <<-SCRIPT
      p ARGV
      SCRIPT

      assert_match %w( a b ).to_s, Dir.chdir(app_path) { `bin/quails runner "bin/program_name.rb" a b` }
    end
test_runner_detects_bad_script_name() click to toggle source
# File railties/test/application/runner_test.rb, line 117
def test_runner_detects_bad_script_name
  output = Dir.chdir(app_path) { `bin/quails runner "iuiqwiourowe" 2>&1` }
  assert_not $?.success?
  assert_match "undefined local variable or method `iuiqwiourowe' for", output
end
test_runner_detects_syntax_errors() click to toggle source
# File railties/test/application/runner_test.rb, line 111
def test_runner_detects_syntax_errors
  output = Dir.chdir(app_path) { `bin/quails runner "puts 'hello world" 2>&1` }
  assert_not $?.success?
  assert_match "unterminated string meets end of file", output
end
test_should_include_runner_in_shebang_line_in_help() click to toggle source
# File railties/test/application/runner_test.rb, line 32
def test_should_include_runner_in_shebang_line_in_help
  assert_match "/quails runner", Dir.chdir(app_path) { `bin/quails runner --help` }
end
test_should_include_runner_in_shebang_line_in_help_without_option() click to toggle source
# File railties/test/application/runner_test.rb, line 28
def test_should_include_runner_in_shebang_line_in_help_without_option
  assert_match "/quails runner", Dir.chdir(app_path) { `bin/quails runner` }
end
test_should_run_file() click to toggle source
# File railties/test/application/runner_test.rb, line 48
    def test_should_run_file
      app_file "bin/count_users.rb", <<-SCRIPT
      puts User.count
      SCRIPT

      assert_match "42", Dir.chdir(app_path) { `bin/quails runner "bin/count_users.rb"` }
    end
test_should_run_ruby_statement() click to toggle source
# File railties/test/application/runner_test.rb, line 36
def test_should_run_ruby_statement
  assert_match "42", Dir.chdir(app_path) { `bin/quails runner "puts User.count"` }
end
test_should_run_stdin() click to toggle source
# File railties/test/application/runner_test.rb, line 89
    def test_should_run_stdin
      app_file "bin/count_users.rb", <<-SCRIPT
      puts User.count
      SCRIPT

      assert_match "42", Dir.chdir(app_path) { `cat bin/count_users.rb | bin/quails runner -` }
    end
test_should_set_argv_when_running_code() click to toggle source
# File railties/test/application/runner_test.rb, line 40
def test_should_set_argv_when_running_code
  output = Dir.chdir(app_path) {
    # Both long and short args, at start and end of ARGV
    `bin/quails runner "puts ARGV.join(',')" --foo a1 -b a2 a3 --moo`
  }
  assert_equal "--foo,a1,-b,a2,a3,--moo", output.chomp
end
test_should_set_dollar_0_to_file() click to toggle source
# File railties/test/application/runner_test.rb, line 65
    def test_should_set_dollar_0_to_file
      app_file "bin/dollar0.rb", <<-SCRIPT
      puts $0
      SCRIPT

      assert_match "bin/dollar0.rb", Dir.chdir(app_path) { `bin/quails runner "bin/dollar0.rb"` }
    end
test_should_set_dollar_program_name_to_file() click to toggle source
# File railties/test/application/runner_test.rb, line 73
    def test_should_set_dollar_program_name_to_file
      app_file "bin/program_name.rb", <<-SCRIPT
      puts $PROGRAM_NAME
      SCRIPT

      assert_match "bin/program_name.rb", Dir.chdir(app_path) { `bin/quails runner "bin/program_name.rb"` }
    end
test_with_hook() click to toggle source
# File railties/test/application/runner_test.rb, line 97
    def test_with_hook
      add_to_config <<-RUBY
        runner do |app|
          app.config.ran = true
        end
      RUBY

      assert_match "true", Dir.chdir(app_path) { `bin/quails runner "puts Quails.application.config.ran"` }
    end