Class: LearnTest::Strategy

Inherits:
Object
  • Object
show all
Defined in:
lib/learn_test/strategy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runner) ⇒ Strategy

Returns a new instance of Strategy.



5
6
7
8
# File 'lib/learn_test/strategy.rb', line 5

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

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/learn_test/strategy.rb', line 3

def options
  @options
end

#runnerObject (readonly)

Returns the value of attribute runner.



3
4
5
# File 'lib/learn_test/strategy.rb', line 3

def runner
  @runner
end

Instance Method Details

#argvObject



51
52
53
# File 'lib/learn_test/strategy.rb', line 51

def argv
  options[:argv]
end

#check_dependenciesObject



14
15
# File 'lib/learn_test/strategy.rb', line 14

def check_dependencies
end

#cleanupObject



36
37
# File 'lib/learn_test/strategy.rb', line 36

def cleanup
end

#configureObject



17
18
# File 'lib/learn_test/strategy.rb', line 17

def configure
end

#die(message) ⇒ Object



55
56
57
58
# File 'lib/learn_test/strategy.rb', line 55

def die(message)
  puts message.red
  exit
end

#learn_oauth_tokenObject



47
48
49
# File 'lib/learn_test/strategy.rb', line 47

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

#outputObject

Raises:

  • (NotImplementedError)


24
25
26
# File 'lib/learn_test/strategy.rb', line 24

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

#push_results?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/learn_test/strategy.rb', line 32

def push_results?
  true
end

#resultsObject



28
29
30
# File 'lib/learn_test/strategy.rb', line 28

def results
  output
end

#runObject

Raises:

  • (NotImplementedError)


20
21
22
# File 'lib/learn_test/strategy.rb', line 20

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

#run_install(command, npm_install: false) ⇒ Object

npm_install option added to fix the proxying of the npm install progress bar output.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/learn_test/strategy.rb', line 63

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

#service_endpointObject

Raises:

  • (NotImplementedError)


10
11
12
# File 'lib/learn_test/strategy.rb', line 10

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

#user_idObject



43
44
45
# File 'lib/learn_test/strategy.rb', line 43

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

#usernameObject



39
40
41
# File 'lib/learn_test/strategy.rb', line 39

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