Sha256: 83a774765e756fb660c26f1cda50748f5782320d5eaf41732facce7e84e56f8c

Contents?: true

Size: 1.62 KB

Versions: 12

Compression:

Stored size: 1.62 KB

Contents

# frozen_string_literal: true

module LearnTest
  class Strategy
    attr_reader :runner, :options

    def initialize(runner)
      @runner  = runner
      @options = runner.options
    end

    def service_endpoint
      raise NotImplementedError, 'you must add the service endpoint to the test strategy'
    end

    def check_dependencies; end

    def configure; end

    def run
      raise NotImplementedError, 'you must implement how this strategy runs its tests'
    end

    def output
      raise NotImplementedError, 'you must implement how the test gets its raw output'
    end

    def results
      output
    end

    def push_results?
      true
    end

    def cleanup; end

    def username
      @username ||= LearnTest::UsernameParser.get_username
    end

    def user_id
      @user_id ||= LearnTest::UserIdParser.get_user_id
    end

    def learn_oauth_token
      @learn_oauth_token ||= LearnTest::LearnOauthTokenParser.get_learn_oauth_token
    end

    def argv
      options[:argv]
    end

    def die(message)
      puts message.red
      exit
    end

    ##
    # npm_install option added to fix the proxying of the npm install progress
    # bar output.
    def run_install(command, npm_install: false)
      if npm_install
        system(command)
      else
        Open3.popen3(command) do |stdin, stdout, stderr, wait_thr|
          while out = stdout.gets do
            puts out
          end

          while err = stderr.gets do
            puts err
          end

          if wait_thr.value.exitstatus != 0
            die("There was an error running #{command}")
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
learn-test-3.2.4 lib/learn_test/strategy.rb
learn-test-3.2.3 lib/learn_test/strategy.rb
learn-test-3.2.2 lib/learn_test/strategy.rb
learn-test-3.2.1 lib/learn_test/strategy.rb
learn-test-3.2.1.pre.7 lib/learn_test/strategy.rb
learn-test-3.2.1.pre.6 lib/learn_test/strategy.rb
learn-test-3.2.1.pre.5 lib/learn_test/strategy.rb
learn-test-3.2.1.pre.4 lib/learn_test/strategy.rb
learn-test-3.2.1.pre.3 lib/learn_test/strategy.rb
learn-test-3.2.1.pre.2 lib/learn_test/strategy.rb
learn-test-3.2.1.pre.1 lib/learn_test/strategy.rb
learn-test-3.2.0 lib/learn_test/strategy.rb