Class: LearnTest::Strategies::Mocha

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

Instance Attribute Summary

Attributes inherited from LearnTest::Strategy

#options, #runner

Instance Method Summary collapse

Methods included from JsStrategy

#has_js_dependency?, #js_package, #missing_dependencies?, #modules_missing?, #npm_install

Methods inherited from LearnTest::Strategy

#argv, #configure, #die, #initialize, #learn_oauth_token, #run_install, #user_id, #username

Constructor Details

This class inherits a constructor from LearnTest::Strategy

Instance Method Details

#check_dependenciesObject



18
19
20
# File 'lib/learn_test/strategies/mocha.rb', line 18

def check_dependencies
  Dependencies::NodeJS.new.execute
end

#cleanupObject



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

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

#detectObject



12
13
14
15
16
# File 'lib/learn_test/strategies/mocha.rb', line 12

def detect
  return false unless js_package

  (has_js_dependency?(:mocha) || in_browser?) ? true : false
end

#outputObject



53
54
55
# File 'lib/learn_test/strategies/mocha.rb', line 53

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

#push_results?Boolean

Returns:

  • (Boolean)


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

def push_results?
  !in_browser?
end

#resultsObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/learn_test/strategies/mocha.rb', line 34

def results
  @results ||= {
    username: username,
    github_user_id: user_id,
    learn_oauth_token: learn_oauth_token,
    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



22
23
24
# File 'lib/learn_test/strategies/mocha.rb', line 22

def run
  run_mocha
end

#service_endpointObject



8
9
10
# File 'lib/learn_test/strategies/mocha.rb', line 8

def service_endpoint
  '/e/flatiron_mocha'
end