Sha256: 5cba837e944ad14e34e5a5ffde81423c688592f502020ddef88682b27e713960

Contents?: true

Size: 1021 Bytes

Versions: 2

Compression:

Stored size: 1021 Bytes

Contents

module RailsTestServing
  module Client
    extend self

    # Setting this variable to true inhibits #run_tests.
    @@disabled = false

    def disable
      @@disabled = true
      yield
    ensure
      @@disabled = false
    end

    def tests_on_exit
      !Test::Unit.run?
    end

    def tests_on_exit=(yes)
      Test::Unit.run = !yes
    end

    def run_tests
      return if @@disabled
      run_tests!
    end

  private

    def run_tests!
      handle_process_lifecycle do
        server = DRbObject.new_with_uri(RailsTestServing.service_uri)
        begin
          puts(server.run($0, ARGV))
        rescue DRb::DRbConnError
          raise ServerUnavailable
        end
      end
    end

    def handle_process_lifecycle
      Client.tests_on_exit = false
      begin
        yield
      rescue ServerUnavailable, InvalidArgumentPattern
        Client.tests_on_exit = true
      else
        # TODO exit with a status code reflecting the result of the tests
        exit 0
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
Roman2K-rails-test-serving-0.1.4.1 lib/rails_test_serving/client.rb
rails-test-serving-0.1.4.2 lib/rails_test_serving/client.rb