Class: LearnTest::RSpec::Runner
- Inherits:
-
Object
- Object
- LearnTest::RSpec::Runner
- Defined in:
- lib/learn_test/rspec/runner.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#formatted_results ⇒ Object
Returns the value of attribute formatted_results.
-
#json_output ⇒ Object
Returns the value of attribute json_output.
-
#keep_results ⇒ Object
Returns the value of attribute keep_results.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#parsed_output ⇒ Object
Returns the value of attribute parsed_output.
-
#repo_name ⇒ Object
readonly
Returns the value of attribute repo_name.
-
#user_id ⇒ Object
readonly
Returns the value of attribute user_id.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #check_options ⇒ Object
- #cleanup ⇒ Object
- #format_results ⇒ Object
-
#initialize(username, user_id, repo_name, options) ⇒ Runner
constructor
A new instance of Runner.
- #jsonify ⇒ Object
- #keep_results? ⇒ Boolean
- #push_results ⇒ Object
- #read_dot_rspec ⇒ Object
- #run ⇒ Object
- #run_rspec ⇒ Object
- #set_json_output ⇒ Object
Constructor Details
#initialize(username, user_id, repo_name, options) ⇒ Runner
Returns a new instance of Runner.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/learn_test/rspec/runner.rb', line 7 def initialize(username, user_id, repo_name, ) @username = username @user_id = user_id @repo_name = repo_name @options = @json_output = "" @parsed_output = nil @formatted_results = {} @connection = Faraday.new(url: SERVICE_URL) do |faraday| faraday.adapter Faraday.default_adapter end end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
5 6 7 |
# File 'lib/learn_test/rspec/runner.rb', line 5 def connection @connection end |
#formatted_results ⇒ Object
Returns the value of attribute formatted_results.
4 5 6 |
# File 'lib/learn_test/rspec/runner.rb', line 4 def formatted_results @formatted_results end |
#json_output ⇒ Object
Returns the value of attribute json_output.
4 5 6 |
# File 'lib/learn_test/rspec/runner.rb', line 4 def json_output @json_output end |
#keep_results ⇒ Object
Returns the value of attribute keep_results.
4 5 6 |
# File 'lib/learn_test/rspec/runner.rb', line 4 def keep_results @keep_results end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/learn_test/rspec/runner.rb', line 5 def @options end |
#parsed_output ⇒ Object
Returns the value of attribute parsed_output.
4 5 6 |
# File 'lib/learn_test/rspec/runner.rb', line 4 def parsed_output @parsed_output end |
#repo_name ⇒ Object (readonly)
Returns the value of attribute repo_name.
5 6 7 |
# File 'lib/learn_test/rspec/runner.rb', line 5 def repo_name @repo_name end |
#user_id ⇒ Object (readonly)
Returns the value of attribute user_id.
5 6 7 |
# File 'lib/learn_test/rspec/runner.rb', line 5 def user_id @user_id end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
5 6 7 |
# File 'lib/learn_test/rspec/runner.rb', line 5 def username @username end |
Instance Method Details
#check_options ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/learn_test/rspec/runner.rb', line 32 def = .include?('--format') || .include?('-f') if dot_rspec = read_dot_rspec if if dot_rspec.any? {|dot_opt| dot_opt.match(/--format|-f/)} << dot_rspec.reject {|dot_opt| dot_opt.match(/--format|-f/)} else << dot_rspec end end end if self..flatten! else .unshift('--format documentation') end # Don't pass the test/local flag from learn binary to rspec runner. .delete("--test") .delete("-t") .delete("-l") .delete("--local") self.keep_results = !!.delete('--keep') end |
#cleanup ⇒ Object
117 118 119 |
# File 'lib/learn_test/rspec/runner.rb', line 117 def cleanup FileUtils.rm('.results.json') unless keep_results? end |
#format_results ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/learn_test/rspec/runner.rb', line 79 def format_results self.formatted_results.merge!({ username: username, github_user_id: user_id, repo_name: repo_name, build: { test_suite: [{ framework: 'rspec', formatted_output: parsed_output, duration: parsed_output ? parsed_output[:summary][:duration] : nil }] }, examples: parsed_output ? parsed_output[:summary][:example_count] : 1, passing_count: parsed_output ? parsed_output[:summary][:example_count] - parsed_output[:summary][:failure_count] - parsed_output[:summary][:pending_count] : 0, pending_count: parsed_output ? parsed_output[:summary][:pending_count] : 0, failure_count: parsed_output ? parsed_output[:summary][:failure_count] : 1, failure_descriptions: if parsed_output parsed_output[:examples].select do |example| example[:status] == "failed" end.map { |ex| ex[:full_description] }.join(";") else 'A syntax error prevented RSpec from running.' end }) end |
#jsonify ⇒ Object
75 76 77 |
# File 'lib/learn_test/rspec/runner.rb', line 75 def jsonify self.parsed_output = json_output ? Oj.load(json_output, symbol_keys: true) : nil end |
#keep_results? ⇒ Boolean
121 122 123 |
# File 'lib/learn_test/rspec/runner.rb', line 121 def keep_results? keep_results end |
#push_results ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/learn_test/rspec/runner.rb', line 105 def push_results begin connection.post do |req| req.url SERVICE_ENDPOINT req.headers['Content-Type'] = 'application/json' req.body = Oj.dump(formatted_results, mode: :compat) end rescue Faraday::ConnectionFailed puts 'There was a problem connecting to Learn. Not pushing test results.' end end |
#read_dot_rspec ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/learn_test/rspec/runner.rb', line 59 def read_dot_rspec if File.exist?('.rspec') File.readlines('.rspec').map(&:strip) else nil end end |
#run ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/learn_test/rspec/runner.rb', line 20 def run run_rspec if !.include?('-h') && !.include?('--help') set_json_output jsonify format_results push_results cleanup end end |
#run_rspec ⇒ Object
67 68 69 |
# File 'lib/learn_test/rspec/runner.rb', line 67 def run_rspec system("rspec #{.join(' ')} --format j --out .results.json") end |
#set_json_output ⇒ Object
71 72 73 |
# File 'lib/learn_test/rspec/runner.rb', line 71 def set_json_output self.json_output = File.exists?('.results.json') ? File.read('.results.json') : nil end |