Class: LearnTest::Strategies::Rspec

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

Instance Attribute Summary

Attributes inherited from LearnTest::Strategy

#options, #runner

Instance Method Summary collapse

Methods inherited from LearnTest::Strategy

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

Constructor Details

This class inherits a constructor from LearnTest::Strategy

Instance Method Details

#cleanupObject



59
60
61
# File 'lib/learn_test/strategies/rspec.rb', line 59

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

#configureObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/learn_test/strategies/rspec.rb', line 12

def configure
  if format_option_present?
    if dot_rspec.any? {|dot_opt| dot_opt.match(/--format|-f/)}
      argv << dot_rspec.reject {|dot_opt| dot_opt.match(/--format|-f/)}
    else
      argv << dot_rspec
    end
    argv.flatten!
  else
    argv.unshift('--format documentation')
  end

  # Don't pass the test/local flag from learn binary to rspec runner.
  argv.delete("--test")
  argv.delete("-t")
  argv.delete("-l")
  argv.delete("--local")
end

#detectObject



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

def detect
  runner.files.include?('spec') && (spec_files.include?('spec_helper.rb') || spec_files.include?('rails_helper.rb'))
end

#outputObject



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

def 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
56
57
# File 'lib/learn_test/strategies/rspec.rb', line 39

def results
  {
    username: username,
    github_user_id: user_id,
    repo_name: runner.repo,
    build: {
      test_suite: [{
        framework: 'rspec',
        formatted_output: output,
        duration: output ? output[:summary][:duration] : nil
      }]
    },
    examples: output ? output[:summary][:example_count] : 1,
    passing_count: output ? output[:summary][:example_count] - output[:summary][:failure_count] - output[:summary][:pending_count] : 0,
    pending_count: output ? output[:summary][:pending_count] : 0,
    failure_count: output ? output[:summary][:failure_count] : 1,
    failure_descriptions: failures
  }
end

#runObject



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

def run
  system("#{bundle_command}rspec #{argv.join(' ')} --format j --out .results.json")
end

#service_endpointObject



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

def service_endpoint
  '/e/flatiron_rspec'
end