Class: LearnLab::Test::Strategy

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

Overview

Base class for all test tools. Extracted from the ‘learn-test` gem with some modifications (i.e. this doesn’t talk to Ironboard).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runner, out = $stdout) ⇒ Strategy

Returns a new instance of Strategy.

[View source]

11
12
13
14
15
16
# File 'lib/learn_lab/test/strategy.rb', line 11

def initialize(runner, out=$stdout)
  @runner = runner
  @options = runner.options
  @out = out
  @fs = LearnLab.file_system
end

Instance Attribute Details

#fsObject (readonly)

Returns the value of attribute fs.


9
10
11
# File 'lib/learn_lab/test/strategy.rb', line 9

def fs
  @fs
end

#optionsObject (readonly)

Returns the value of attribute options.


9
10
11
# File 'lib/learn_lab/test/strategy.rb', line 9

def options
  @options
end

#outObject (readonly)

Returns the value of attribute out.


9
10
11
# File 'lib/learn_lab/test/strategy.rb', line 9

def out
  @out
end

#runnerObject (readonly)

Returns the value of attribute runner.


9
10
11
# File 'lib/learn_lab/test/strategy.rb', line 9

def runner
  @runner
end

Instance Method Details

#check_dependenciesObject

[View source]

18
# File 'lib/learn_lab/test/strategy.rb', line 18

def check_dependencies; end

#cleanupObject

[View source]

55
56
57
# File 'lib/learn_lab/test/strategy.rb', line 55

def cleanup
  fs.rm(result_file_path) if result_file?
end

#outputObject

rubocop:enable Metrics/MethodLength

[View source]

49
50
51
52
53
# File 'lib/learn_lab/test/strategy.rb', line 49

def output
  return unless result_file?

  fs.read_json_file(result_file_path)
end

#parserObject

Raises:

  • (NotImplementedError)
[View source]

26
27
28
# File 'lib/learn_lab/test/strategy.rb', line 26

def parser
  raise NotImplementedError.new('you must define a parser')
end

#result_filenameObject

[View source]

59
60
61
# File 'lib/learn_lab/test/strategy.rb', line 59

def result_filename
  '.results.json'
end

#resultsObject

rubocop:disable Metrics/MethodLength

[View source]

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/learn_lab/test/strategy.rb', line 31

def results
  {
    repo_name: runner.repo,
    build: {
      test_suite: [{
        framework: parser.framework,
        formatted_output: output,
        duration: parser.duration
      }]
    },
    example_count: parser.example_count,
    passing_count: parser.passing_count,
    pending_count: parser.pending_count,
    failure_count: parser.failure_count
  }
end

#runObject

Raises:

  • (NotImplementedError)
[View source]

20
21
22
23
24
# File 'lib/learn_lab/test/strategy.rb', line 20

def run
  raise NotImplementedError.new(
    'you must implement how this strategy runs its tests'
  )
end