Class: LearnTest::Strategies::Mocha

Inherits:
LearnTest::Strategy show all
Defined in:
lib/learn_test/strategies/mocha.rb

Instance Attribute Summary

Attributes inherited from LearnTest::Strategy

#options, #runner

Instance Method Summary collapse

Methods inherited from LearnTest::Strategy

#argv, #configure, #die, #initialize, #push_results?, #run_install, #user_id, #username

Constructor Details

This class inherits a constructor from LearnTest::Strategy

Instance Method Details

#check_dependenciesObject



27
28
29
# File 'lib/learn_test/strategies/mocha.rb', line 27

def check_dependencies
  Dependencies::NodeJS.new.execute
end

#cleanupObject



57
58
59
# File 'lib/learn_test/strategies/mocha.rb', line 57

def cleanup
  FileUtils.rm('.results.json') if File.exist?('.results.json')
end

#detectObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/learn_test/strategies/mocha.rb', line 8

def detect
  package = File.exists?('package.json') ? Oj.load(File.read('package.json'), symbol_keys: true) : nil
  return false if !package

  if package[:scripts] && package[:scripts][:test]
    return true if package[:scripts][:test].include?('mocha')
  end

  if package[:devDependencies] && package[:devDependencies][:mocha]
    return true if (package[:devDependencies][:mocha].length > 0)
  end

  if package[:dependencies] && package[:dependencies][:mocha]
    return true if (package[:dependencies][:mocha].length > 0)
  end

  return false
end

#outputObject



35
36
37
# File 'lib/learn_test/strategies/mocha.rb', line 35

def output
  @output ||= File.exists?('.results.json') ? Oj.load(File.read('.results.json'), symbol_keys: true) : nil
end

#resultsObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/learn_test/strategies/mocha.rb', line 39

def results
  @results ||= {
    username: username,
    github_user_id: user_id,
    repo_name: runner.repo,
    build: {
      test_suite: [{
        framework: 'mocha',
        formatted_output: output,
        duration: output[:stats]
      }]
    },
    examples: output[:stats][:tests],
    passing_count: output[:stats][:passes],
    failure_count: output[:stats][:failures]
  }
end

#runObject



31
32
33
# File 'lib/learn_test/strategies/mocha.rb', line 31

def run
  run_mocha
end

#service_endpointObject



4
5
6
# File 'lib/learn_test/strategies/mocha.rb', line 4

def service_endpoint
  '/e/flatiron_mocha'
end