Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 0b1de8b665
Fetching contributors…

Cannot retrieve contributors at this time

file 130 lines (103 sloc) 3.585 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
require 'socket'
begin
  require 'testrbl' # before bundler is setup so it does not need to be in the Gemfile
rescue LoadError
end

ROOT_PATH = File.expand_path('../spec/dummy', __FILE__)

Zeus::Server.define! do
  stage :boot do

    action do
      ENV_PATH = File.expand_path('config/environment', ROOT_PATH)
      BOOT_PATH = File.expand_path('config/boot', ROOT_PATH)
      APP_PATH = File.expand_path('config/application', ROOT_PATH)

      require BOOT_PATH
      require 'rails/all'
    end

    stage :default_bundle do
      action { Bundler.require(:default) }

      stage :development_environment do
        action do
          Bundler.require(:development)
          Rails.env = ENV['RAILS_ENV'] = "development"
          require APP_PATH
          Rails.application.require_environment!
        end

        command :generate, :g do
          begin
            require 'rails/generators'
            Rails.application.load_generators
          rescue LoadError # Rails 3.0 doesn't require this block to be run, but 3.2+ does
          end
          require 'rails/commands/generate'
        end

        command :runner, :r do
          require 'rails/commands/runner'
        end

        command :console, :c do
          require 'rails/commands/console'
          Rails::Console.start(Rails.application)
        end

        command :server, :s do
          require 'rails/commands/server'
          server = Rails::Server.new
          Dir.chdir(Rails.application.root)
          server.start
        end

        stage :prerake do
          action do
            require 'rake'
            load 'Rakefile'
          end

          command :rake do
            Rake.application.run
          end

        end
      end

      stage :test_environment do
        action do
          Bundler.require(:test)

          Rails.env = ENV['RAILS_ENV'] = 'test'
          require APP_PATH

          $rails_rake_task = 'yup' # lie to skip eager loading
          Rails.application.require_environment!
          $rails_rake_task = nil
          $LOAD_PATH.unshift(ROOT_PATH) unless $LOAD_PATH.include?(ROOT_PATH)

          if Dir.exist?(ROOT_PATH + "/test")
            test = File.join(ROOT_PATH, 'test')
            $LOAD_PATH.unshift(test) unless $LOAD_PATH.include?(test)
          end

          if Dir.exist?(ROOT_PATH + "/spec")
            spec = File.join(ROOT_PATH, 'spec')
            $LOAD_PATH.unshift(spec) unless $LOAD_PATH.include?(spec)
          end

        end

        if Dir.exist?(ROOT_PATH + "/test")
          stage :test_helper do
            action { require 'test_helper' }

            command :testrb do
              argv = ARGV

              # try to find patter by line using testrbl
              if defined?(Testrbl) && argv.size == 1 and argv.first =~ /^\S+:\d+$/
                file, line = argv.first.split(':')
                argv = [file, '-n', "/#{Testrbl.send(:pattern_from_file, File.readlines(file), line)}/"]
                puts "using -n '#{argv[2]}'" # let users copy/paste or adjust the pattern
              end

              runner = Test::Unit::AutoRunner.new(true)
              if runner.process_args(argv)
                exit runner.run
              else
                abort runner.options.banner + " tests..."
              end
            end
          end
        end

        stage :spec_helper do
          action { require File.join(ROOT_PATH, '..', 'spec_helper') }

          command :rspec do
            exit RSpec::Core::Runner.run(ARGV)
          end
        end

      end

    end
  end
end
Something went wrong with that request. Please try again.