learn-test 2.4.2 → 2.5.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile +1 -1
- data/README.md +1 -1
- data/bin/learn-test +4 -0
- data/learn-test.gemspec +7 -8
- data/lib/learn_test.rb +14 -12
- data/lib/learn_test/client.rb +26 -0
- data/lib/learn_test/js_strategy.rb +23 -0
- data/lib/learn_test/reporter.rb +97 -0
- data/lib/learn_test/runner.rb +12 -34
- data/lib/learn_test/strategies/csharp_nunit.rb +4 -4
- data/lib/learn_test/strategies/jasmine.rb +5 -5
- data/lib/learn_test/strategies/java_junit.rb +3 -3
- data/lib/learn_test/strategies/mocha.rb +30 -35
- data/lib/learn_test/version.rb +1 -1
- data/spec/learn_test/reporter_spec.rb +147 -0
- metadata +44 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2deca35ab21ca4c10c2b5a887c1f416ee152ac7a
|
4
|
+
data.tar.gz: b10ba9993ef849bbcfff49633d78de098a8f5883
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b2752ed0ce36623f3546debebdca14ba91aa8b6ccfb40df648580e29f174087fe5483dd95c9344a7176cb9e0d4ee13d77d83719ddbf10fbd8d73fe637018884
|
7
|
+
data.tar.gz: bd4491c47abb520b0c8fda5ecd40de94014acc2be42034471612561898c1df9f612e5386cd87d29a7373a71dce40c61921a0d9693345b8166079f7d709cd1569
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
data/bin/learn-test
CHANGED
@@ -8,6 +8,10 @@ options = {}
|
|
8
8
|
OptionParser.new do |opts|
|
9
9
|
opts.banner = "Usage: learn [options]"
|
10
10
|
|
11
|
+
opts.on("-d", "--debug", "Output errors during results synchronization") do |d|
|
12
|
+
options[:debug] = d
|
13
|
+
end
|
14
|
+
|
11
15
|
opts.on("-n", "--[no-]color", "Turn off color output") do |c|
|
12
16
|
options[:color] = c
|
13
17
|
end
|
data/learn-test.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = LearnTest::VERSION
|
9
9
|
spec.authors = ["Flatiron School"]
|
10
10
|
spec.email = ["learn@flatironschool.com"]
|
11
|
-
spec.summary = %q{Runs RSpec, Jasmine, and Python Unit Test builds and pushes JSON output to Learn.}
|
11
|
+
spec.summary = %q{Runs RSpec, Jasmine, Karma, Mocha, and Python Unit Test builds and pushes JSON output to Learn.}
|
12
12
|
spec.homepage = "https://github.com/learn-co/learn-test"
|
13
13
|
spec.license = "MIT"
|
14
14
|
|
@@ -20,15 +20,14 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.add_development_dependency "bundler", "~> 1.7"
|
21
21
|
spec.add_development_dependency "rake", "~> 10.0"
|
22
22
|
spec.add_runtime_dependency "rspec", "~> 3.0"
|
23
|
-
spec.add_runtime_dependency "netrc"
|
23
|
+
spec.add_runtime_dependency "netrc", "~> 0.11.0"
|
24
24
|
spec.add_runtime_dependency "git", "~> 1.2"
|
25
25
|
spec.add_runtime_dependency "oj", "~> 2.9"
|
26
26
|
spec.add_runtime_dependency "faraday", "~> 0.9"
|
27
|
-
spec.add_runtime_dependency "crack"
|
28
|
-
spec.add_runtime_dependency "jasmine"
|
29
|
-
spec.add_runtime_dependency "colorize"
|
30
|
-
spec.add_runtime_dependency "webrick", "~> 1.3.1"
|
27
|
+
spec.add_runtime_dependency "crack", "~> 0.4.3"
|
28
|
+
spec.add_runtime_dependency "jasmine", "~> 2.6.0", '>= 2.6.0'
|
29
|
+
spec.add_runtime_dependency "colorize", "~> 0.8.1"
|
30
|
+
spec.add_runtime_dependency "webrick", "~> 1.3.1", '>= 1.3.1'
|
31
31
|
spec.add_runtime_dependency "rainbow", "= 1.99.2"
|
32
|
-
spec.add_runtime_dependency "selenium-webdriver", "~> 2.52.0"
|
32
|
+
spec.add_runtime_dependency "selenium-webdriver", "~> 2.52.0", '>= 2.52.0'
|
33
33
|
end
|
34
|
-
|
data/lib/learn_test.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'fileutils'
|
2
|
-
require 'faraday'
|
3
2
|
require 'oj'
|
4
3
|
require 'colorize'
|
5
4
|
|
@@ -14,19 +13,9 @@ require_relative 'learn_test/file_finder'
|
|
14
13
|
require_relative 'learn_test/runner'
|
15
14
|
|
16
15
|
require_relative 'learn_test/dependency'
|
17
|
-
require_relative 'learn_test/dependencies/nodejs'
|
18
|
-
require_relative 'learn_test/dependencies/phantomjs'
|
19
|
-
require_relative 'learn_test/dependencies/karma'
|
20
|
-
require_relative 'learn_test/dependencies/protractor'
|
21
|
-
require_relative 'learn_test/dependencies/java'
|
22
|
-
require_relative 'learn_test/dependencies/csharp'
|
23
|
-
require_relative 'learn_test/dependencies/ant'
|
24
|
-
require_relative 'learn_test/dependencies/imagemagick'
|
25
|
-
require_relative 'learn_test/dependencies/selenium_server'
|
26
|
-
require_relative 'learn_test/dependencies/firefox'
|
27
|
-
require_relative 'learn_test/dependencies/green_onion'
|
28
16
|
|
29
17
|
require_relative 'learn_test/strategy'
|
18
|
+
require_relative 'learn_test/js_strategy'
|
30
19
|
require_relative 'learn_test/strategies/jasmine'
|
31
20
|
require_relative 'learn_test/strategies/python_unittest'
|
32
21
|
require_relative 'learn_test/strategies/rspec'
|
@@ -38,4 +27,17 @@ require_relative 'learn_test/strategies/mocha'
|
|
38
27
|
require_relative 'learn_test/strategies/green_onion'
|
39
28
|
|
40
29
|
module LearnTest
|
30
|
+
module Dependencies
|
31
|
+
autoload :NodeJS, 'learn_test/dependencies/nodejs'
|
32
|
+
autoload :PhantomJS, 'learn_test/dependencies/phantomjs'
|
33
|
+
autoload :Karma, 'learn_test/dependencies/karma'
|
34
|
+
autoload :Protractor, 'learn_test/dependencies/protractor'
|
35
|
+
autoload :Java, 'learn_test/dependencies/java'
|
36
|
+
autoload :CSharp, 'learn_test/dependencies/csharp'
|
37
|
+
autoload :Ant, 'learn_test/dependencies/ant'
|
38
|
+
autoload :Imagemagick, 'learn_test/dependencies/imagemagick'
|
39
|
+
autoload :SeleniumDriver, 'learn_test/dependencies/selenium_server'
|
40
|
+
autoload :Firefox, 'learn_test/dependencies/firefox'
|
41
|
+
autoload :GreenOnion, 'learn_test/dependencies/green_onion'
|
42
|
+
end
|
41
43
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module LearnTest
|
5
|
+
class Client
|
6
|
+
SERVICE_URL = 'http://ironbroker-v2.flatironschool.com'.freeze
|
7
|
+
|
8
|
+
def initialize(service_url = SERVICE_URL)
|
9
|
+
@conn = Faraday.new(url: service_url) do |faraday|
|
10
|
+
faraday.adapter Faraday.default_adapter
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def post_results(endpoint, result)
|
15
|
+
@conn.post do |req|
|
16
|
+
req.url(endpoint)
|
17
|
+
req.headers['Content-Type'] = 'application/json'
|
18
|
+
req.body = JSON.dump(result)
|
19
|
+
end
|
20
|
+
|
21
|
+
true
|
22
|
+
rescue Faraday::Error
|
23
|
+
false
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module LearnTest
|
2
|
+
module JsStrategy
|
3
|
+
def js_package
|
4
|
+
@js_package ||= File.exist?('package.json') ? Oj.load(File.read('package.json'), symbol_keys: true) : nil
|
5
|
+
end
|
6
|
+
|
7
|
+
def has_js_dependency?(dep)
|
8
|
+
[:dependencies, :devDependencies].any? { |key| js_package[key] && js_package[key][dep] }
|
9
|
+
end
|
10
|
+
|
11
|
+
def missing_dependencies?
|
12
|
+
return true if !File.exist?("node_modules")
|
13
|
+
|
14
|
+
[:dependencies, :devDependencies, :peerDependencies].any? do |d|
|
15
|
+
(js_package[d] || {}).any? { |p, v| !File.exist?("node_modules/#{p}") }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def npm_install
|
20
|
+
run_install('npm install', npm_install: true) if missing_dependencies?
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
require_relative 'client'
|
5
|
+
|
6
|
+
module LearnTest
|
7
|
+
class Reporter
|
8
|
+
|
9
|
+
attr_accessor :output_path, :debug
|
10
|
+
|
11
|
+
def self.report(strategy, options = {})
|
12
|
+
reporter = new(strategy, options)
|
13
|
+
reporter.report
|
14
|
+
reporter.retry_failed_reports
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(strategy, options = {})
|
18
|
+
@strategy = strategy
|
19
|
+
@output_path = options[:output_path] || File.join(Dir.home, '.learn.debug')
|
20
|
+
@client = options[:client] || LearnTest::Client.new
|
21
|
+
@debug = options[:debug]
|
22
|
+
end
|
23
|
+
|
24
|
+
def failed_reports
|
25
|
+
return {} unless File.exists?(output_path)
|
26
|
+
JSON.load(File.read(output_path)) || {}
|
27
|
+
end
|
28
|
+
|
29
|
+
def retry_failed_reports
|
30
|
+
previous_reports = failed_reports
|
31
|
+
previous_reports.delete_if do |endpoint, results|
|
32
|
+
results.delete_if do |result|
|
33
|
+
!!client.post_results(endpoint, result)
|
34
|
+
end.empty?
|
35
|
+
end
|
36
|
+
|
37
|
+
if previous_reports.empty?
|
38
|
+
FileUtils.rm_f(output_path)
|
39
|
+
else
|
40
|
+
File.open(output_path, "w") do |file|
|
41
|
+
file.write("#{JSON.dump(previous_reports)}\n")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def report(out: STDOUT)
|
47
|
+
results = strategy.results
|
48
|
+
endpoint = strategy.service_endpoint
|
49
|
+
augment_results!(results)
|
50
|
+
|
51
|
+
unless client.post_results(endpoint, results)
|
52
|
+
if @debug
|
53
|
+
out.puts 'There was a problem connecting to Learn. Not pushing test results.'.red
|
54
|
+
end
|
55
|
+
save_failed_attempt(endpoint, results)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
attr_reader :strategy, :client
|
62
|
+
|
63
|
+
def save_failed_attempt(endpoint, results)
|
64
|
+
File.open(output_path, File::RDWR|File::CREAT, 0644) do |f|
|
65
|
+
if f.flock(File::LOCK_EX)
|
66
|
+
begin
|
67
|
+
reports = JSON.load(f)
|
68
|
+
reports ||= {}
|
69
|
+
reports[endpoint] ||= []
|
70
|
+
reports[endpoint] << results
|
71
|
+
|
72
|
+
f.rewind
|
73
|
+
f.write("#{JSON.dump(reports)}\n")
|
74
|
+
f.flush
|
75
|
+
f.truncate(f.pos)
|
76
|
+
ensure
|
77
|
+
f.flock(File::LOCK_UN)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def augment_results!(results)
|
84
|
+
if File.exist?("#{FileUtils.pwd}/.learn")
|
85
|
+
dot_learn = YAML.load(File.read("#{FileUtils.pwd}/.learn"))
|
86
|
+
|
87
|
+
if !dot_learn['github'].nil?
|
88
|
+
results[:github] = dot_learn['github']
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
results[:created_at] = Time.now
|
93
|
+
results[:ruby_platform] = RUBY_PLATFORM
|
94
|
+
results[:ide_container] = (ENV['IDE_CONTAINER'] == 'true')
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
data/lib/learn_test/runner.rb
CHANGED
@@ -3,7 +3,6 @@ require 'yaml'
|
|
3
3
|
module LearnTest
|
4
4
|
class Runner
|
5
5
|
attr_reader :repo, :options
|
6
|
-
SERVICE_URL = 'http://ironbroker-v2.flatironschool.com'
|
7
6
|
|
8
7
|
def initialize(repo, options = {})
|
9
8
|
@repo = repo
|
@@ -15,10 +14,13 @@ module LearnTest
|
|
15
14
|
strategy.check_dependencies
|
16
15
|
strategy.configure
|
17
16
|
strategy.run
|
18
|
-
if
|
19
|
-
|
17
|
+
if options[:debug]
|
18
|
+
report_and_clean
|
19
|
+
else
|
20
|
+
Process.detach(Process.fork do
|
21
|
+
report_and_clean
|
22
|
+
end)
|
20
23
|
end
|
21
|
-
strategy.cleanup unless keep_results?
|
22
24
|
end
|
23
25
|
|
24
26
|
def files
|
@@ -35,23 +37,14 @@ module LearnTest
|
|
35
37
|
|
36
38
|
private
|
37
39
|
|
38
|
-
def
|
39
|
-
|
40
|
-
dot_learn = YAML.load(File.read("#{FileUtils.pwd}/.learn"))
|
40
|
+
def report_and_clean
|
41
|
+
require_relative 'reporter'
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
end
|
43
|
+
if !help_option_present? && strategy.push_results? && !local_test_run?
|
44
|
+
LearnTest::Reporter.report(strategy, options)
|
45
45
|
end
|
46
46
|
|
47
|
-
|
48
|
-
results[:ide_container] = (ENV['IDE_CONTAINER'] == 'true')
|
49
|
-
end
|
50
|
-
|
51
|
-
def connection
|
52
|
-
@connection ||= Faraday.new(url: SERVICE_URL) do |faraday|
|
53
|
-
faraday.adapter Faraday.default_adapter
|
54
|
-
end
|
47
|
+
strategy.cleanup unless keep_results?
|
55
48
|
end
|
56
49
|
|
57
50
|
def strategies
|
@@ -64,25 +57,10 @@ module LearnTest
|
|
64
57
|
LearnTest::Strategies::Protractor,
|
65
58
|
LearnTest::Strategies::JavaJunit,
|
66
59
|
LearnTest::Strategies::Mocha,
|
67
|
-
LearnTest::Strategies::PythonUnittest
|
60
|
+
LearnTest::Strategies::PythonUnittest,
|
68
61
|
]
|
69
62
|
end
|
70
63
|
|
71
|
-
def push_results(strategy)
|
72
|
-
results = strategy.results
|
73
|
-
augment_results!(results)
|
74
|
-
|
75
|
-
begin
|
76
|
-
connection.post do |req|
|
77
|
-
req.url(strategy.service_endpoint)
|
78
|
-
req.headers['Content-Type'] = 'application/json'
|
79
|
-
req.body = Oj.dump(results, mode: :compat)
|
80
|
-
end
|
81
|
-
rescue Faraday::ConnectionFailed
|
82
|
-
puts 'There was a problem connecting to Learn. Not pushing test results.'.red
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
64
|
def help_option_present?
|
87
65
|
options.include?('-h') || options.include?('--help')
|
88
66
|
end
|
@@ -1,6 +1,3 @@
|
|
1
|
-
require 'crack'
|
2
|
-
require 'json'
|
3
|
-
|
4
1
|
module LearnTest
|
5
2
|
module Strategies
|
6
3
|
class CSharpNunit < LearnTest::Strategy
|
@@ -17,6 +14,9 @@ module LearnTest
|
|
17
14
|
end
|
18
15
|
|
19
16
|
def run
|
17
|
+
require 'crack'
|
18
|
+
require 'json'
|
19
|
+
|
20
20
|
system("dotnet test")
|
21
21
|
output
|
22
22
|
cleanup
|
@@ -44,7 +44,7 @@ module LearnTest
|
|
44
44
|
failure_count: output['test_run']['failed'],
|
45
45
|
}
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
def cleanup
|
49
49
|
FileUtils.rm("TestResult.xml") if File.exist?("TestResult.xml")
|
50
50
|
end
|
@@ -1,8 +1,3 @@
|
|
1
|
-
require 'crack'
|
2
|
-
require 'erb'
|
3
|
-
require 'yaml'
|
4
|
-
require 'json'
|
5
|
-
|
6
1
|
require_relative 'jasmine/initializer'
|
7
2
|
|
8
3
|
module LearnTest
|
@@ -21,6 +16,11 @@ module LearnTest
|
|
21
16
|
end
|
22
17
|
|
23
18
|
def run
|
19
|
+
require 'crack'
|
20
|
+
require 'erb'
|
21
|
+
require 'yaml'
|
22
|
+
require 'json'
|
23
|
+
|
24
24
|
if options[:init]
|
25
25
|
LearnTest::Jasmine::Initializer.run
|
26
26
|
else
|
@@ -1,6 +1,3 @@
|
|
1
|
-
require 'crack'
|
2
|
-
require 'json'
|
3
|
-
|
4
1
|
module LearnTest
|
5
2
|
module Strategies
|
6
3
|
class JavaJunit < LearnTest::Strategy
|
@@ -18,6 +15,9 @@ module LearnTest
|
|
18
15
|
end
|
19
16
|
|
20
17
|
def run
|
18
|
+
require 'crack'
|
19
|
+
require 'json'
|
20
|
+
|
21
21
|
clean_old_results
|
22
22
|
run_ant
|
23
23
|
make_json
|
@@ -1,27 +1,16 @@
|
|
1
1
|
module LearnTest
|
2
2
|
module Strategies
|
3
3
|
class Mocha < LearnTest::Strategy
|
4
|
+
include LearnTest::JsStrategy
|
5
|
+
|
4
6
|
def service_endpoint
|
5
7
|
'/e/flatiron_mocha'
|
6
8
|
end
|
7
9
|
|
8
10
|
def detect
|
9
|
-
|
10
|
-
return false if !package
|
11
|
-
|
12
|
-
if package[:scripts] && package[:scripts][:test]
|
13
|
-
return true if package[:scripts][:test].include?('mocha')
|
14
|
-
end
|
15
|
-
|
16
|
-
if package[:devDependencies] && package[:devDependencies][:mocha]
|
17
|
-
return true if (package[:devDependencies][:mocha].length > 0)
|
18
|
-
end
|
19
|
-
|
20
|
-
if package[:dependencies] && package[:dependencies][:mocha]
|
21
|
-
return true if (package[:dependencies][:mocha].length > 0)
|
22
|
-
end
|
11
|
+
return false if !js_package
|
23
12
|
|
24
|
-
|
13
|
+
(has_js_dependency?(:mocha) || in_browser?) ? true : false
|
25
14
|
end
|
26
15
|
|
27
16
|
def check_dependencies
|
@@ -32,8 +21,12 @@ module LearnTest
|
|
32
21
|
run_mocha
|
33
22
|
end
|
34
23
|
|
35
|
-
def
|
36
|
-
|
24
|
+
def cleanup
|
25
|
+
FileUtils.rm('.results.json') if File.exist?('.results.json')
|
26
|
+
end
|
27
|
+
|
28
|
+
def push_results?
|
29
|
+
!in_browser?
|
37
30
|
end
|
38
31
|
|
39
32
|
def results
|
@@ -55,26 +48,24 @@ module LearnTest
|
|
55
48
|
}
|
56
49
|
end
|
57
50
|
|
58
|
-
def
|
59
|
-
|
60
|
-
end
|
61
|
-
|
62
|
-
def missing_dependencies?(package)
|
63
|
-
return true if !File.exists?("node_modules")
|
64
|
-
|
65
|
-
[:dependencies, :devDependencies, :peerDependencies].any? do |d|
|
66
|
-
(package[d] || {}).any? { |p, v| !File.exists?("node_modules/#{p}") }
|
67
|
-
end
|
51
|
+
def output
|
52
|
+
@output ||= File.exist?('.results.json') ? Oj.load(File.read('.results.json'), symbol_keys: true) : nil
|
68
53
|
end
|
69
54
|
|
70
55
|
private
|
71
56
|
|
72
57
|
def run_mocha
|
73
|
-
|
58
|
+
npm_install
|
74
59
|
|
75
|
-
|
60
|
+
if in_browser?
|
61
|
+
exec("npm test")
|
62
|
+
else
|
63
|
+
run_node_based_mocha
|
64
|
+
end
|
65
|
+
end
|
76
66
|
|
77
|
-
|
67
|
+
def run_node_based_mocha
|
68
|
+
command = if (js_package[:scripts] && js_package[:scripts][:test] || "").include?(".results.json")
|
78
69
|
"npm test"
|
79
70
|
else
|
80
71
|
install_mocha_multi
|
@@ -84,15 +75,19 @@ module LearnTest
|
|
84
75
|
system(command)
|
85
76
|
end
|
86
77
|
|
78
|
+
def in_IDE?
|
79
|
+
ENV['IDE_CONTAINER'] == 'true'
|
80
|
+
end
|
81
|
+
|
82
|
+
def in_browser?
|
83
|
+
@in_browser ||= has_js_dependency?(:'learn-browser')
|
84
|
+
end
|
85
|
+
|
87
86
|
def install_mocha_multi
|
88
|
-
if !File.
|
87
|
+
if !File.exist?('node_modules/mocha-multi')
|
89
88
|
run_install('npm install mocha-multi', npm_install: true)
|
90
89
|
end
|
91
90
|
end
|
92
|
-
|
93
|
-
def npm_install(package)
|
94
|
-
run_install('npm install', npm_install: true) if missing_dependencies?(package)
|
95
|
-
end
|
96
91
|
end
|
97
92
|
end
|
98
93
|
end
|
data/lib/learn_test/version.rb
CHANGED
@@ -0,0 +1,147 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require_relative '../../lib/learn_test/reporter'
|
4
|
+
|
5
|
+
require 'tempfile'
|
6
|
+
require 'json'
|
7
|
+
|
8
|
+
describe LearnTest::Reporter do
|
9
|
+
let(:strategy) {
|
10
|
+
instance_spy(
|
11
|
+
LearnTest::Strategy,
|
12
|
+
service_endpoint: "test_endpoint",
|
13
|
+
results: { test: 'result' }
|
14
|
+
)
|
15
|
+
}
|
16
|
+
let(:client) { instance_spy(LearnTest::Client) }
|
17
|
+
|
18
|
+
def with_file(name, content = nil, &block)
|
19
|
+
file = Tempfile.new(name)
|
20
|
+
if content
|
21
|
+
file.write("#{JSON.dump(content)}\n")
|
22
|
+
file.flush
|
23
|
+
end
|
24
|
+
|
25
|
+
block.call(file)
|
26
|
+
ensure
|
27
|
+
file.close!
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#report' do
|
31
|
+
let(:reporter) { described_class.new(strategy, client: client) }
|
32
|
+
|
33
|
+
context "with debug flag and failed attempt posting results" do
|
34
|
+
it "outputs an error message" do
|
35
|
+
allow(client).to receive(:post_results).and_return(false)
|
36
|
+
reporter.debug = true
|
37
|
+
io = StringIO.new
|
38
|
+
|
39
|
+
reporter.report(out: io)
|
40
|
+
|
41
|
+
expect(io.string).to_not be_empty
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'posts results to the service endpoint' do
|
46
|
+
reporter.report
|
47
|
+
|
48
|
+
expect(client).to have_received(:post_results)
|
49
|
+
.with(strategy.service_endpoint, strategy.results)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'does not output an error message without debug' do
|
53
|
+
allow(client).to receive(:post_results).and_return(false)
|
54
|
+
io = StringIO.new
|
55
|
+
|
56
|
+
with_file('test_debug') do |tmp_file|
|
57
|
+
reporter.output_path = tmp_file.path
|
58
|
+
|
59
|
+
reporter.report(out: io)
|
60
|
+
|
61
|
+
expect(io.string).to be_empty
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'saves the failed attempt when the post results call fails' do
|
66
|
+
allow(client).to receive(:post_results).and_return(false)
|
67
|
+
|
68
|
+
with_file('test') do |tmp_file|
|
69
|
+
reporter.output_path = tmp_file.path
|
70
|
+
reporter.report
|
71
|
+
|
72
|
+
report = JSON.dump(strategy.results)
|
73
|
+
expect(File.exists?(tmp_file.path)).to be(true)
|
74
|
+
expect(reporter.failed_reports).to eq({
|
75
|
+
strategy.service_endpoint => [JSON.load(report)]
|
76
|
+
})
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'appends multiple failed attempts' do
|
81
|
+
allow(client).to receive(:post_results).and_return(false)
|
82
|
+
|
83
|
+
with_file('test') do |tmp_file|
|
84
|
+
reporter.output_path = tmp_file.path
|
85
|
+
|
86
|
+
reporter.report
|
87
|
+
reporter.report
|
88
|
+
|
89
|
+
report = JSON.dump(strategy.results)
|
90
|
+
json_report = JSON.load(report)
|
91
|
+
expect(File.exists?(tmp_file.path)).to be(true)
|
92
|
+
expect(reporter.failed_reports).to eq({
|
93
|
+
strategy.service_endpoint => [json_report, json_report]
|
94
|
+
})
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe '#retry_failed_reports' do
|
100
|
+
let(:reporter) { described_class.new(strategy, client: client) }
|
101
|
+
|
102
|
+
it 'deletes the output file when all reports are sent successfully' do
|
103
|
+
allow(client).to receive(:post_results).and_return(true)
|
104
|
+
reports = {hello: ["world"]}
|
105
|
+
with_file('retry_failed_reports', reports) do |file|
|
106
|
+
reporter.output_path = file.path
|
107
|
+
reporter.retry_failed_reports
|
108
|
+
|
109
|
+
expect(File.exists?(file.path)).to be(false)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'writes the remaining reports from the output file' do
|
114
|
+
allow(client).to receive(:post_results).and_return(true, false)
|
115
|
+
reports = {success: ["world"], failure: ["hello"]}
|
116
|
+
with_file('retry_failed_reports', reports) do |file|
|
117
|
+
reporter.output_path = file.path
|
118
|
+
reporter.retry_failed_reports
|
119
|
+
expect(File.exists?(file.path)).to be(true)
|
120
|
+
expect(reporter.failed_reports).to eq({"failure" => ["hello"]})
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe '#failed_reports' do
|
126
|
+
let(:path) { 'failed_reports' }
|
127
|
+
let(:reporter) { described_class.new(strategy, output_path: path) }
|
128
|
+
subject { reporter.failed_reports }
|
129
|
+
|
130
|
+
context 'with no file at location' do
|
131
|
+
it { is_expected.to eq({}) }
|
132
|
+
end
|
133
|
+
|
134
|
+
context 'with no content in the file' do
|
135
|
+
it { with_file(path) { is_expected.to eq({}) } }
|
136
|
+
end
|
137
|
+
|
138
|
+
context 'with returns the JSON contents of the file' do
|
139
|
+
it {
|
140
|
+
with_file(path, {hello: "world"}) do |file|
|
141
|
+
reporter.output_path = file.path
|
142
|
+
is_expected.to eq({"hello" => "world"})
|
143
|
+
end
|
144
|
+
}
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: learn-test
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.5.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Flatiron School
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -56,16 +56,16 @@ dependencies:
|
|
56
56
|
name: netrc
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 0.11.0
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 0.11.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: git
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -112,44 +112,50 @@ dependencies:
|
|
112
112
|
name: crack
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- - "
|
115
|
+
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
117
|
+
version: 0.4.3
|
118
118
|
type: :runtime
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- - "
|
122
|
+
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
124
|
+
version: 0.4.3
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: jasmine
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 2.6.0
|
129
132
|
- - ">="
|
130
133
|
- !ruby/object:Gem::Version
|
131
|
-
version:
|
134
|
+
version: 2.6.0
|
132
135
|
type: :runtime
|
133
136
|
prerelease: false
|
134
137
|
version_requirements: !ruby/object:Gem::Requirement
|
135
138
|
requirements:
|
139
|
+
- - "~>"
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: 2.6.0
|
136
142
|
- - ">="
|
137
143
|
- !ruby/object:Gem::Version
|
138
|
-
version:
|
144
|
+
version: 2.6.0
|
139
145
|
- !ruby/object:Gem::Dependency
|
140
146
|
name: colorize
|
141
147
|
requirement: !ruby/object:Gem::Requirement
|
142
148
|
requirements:
|
143
|
-
- - "
|
149
|
+
- - "~>"
|
144
150
|
- !ruby/object:Gem::Version
|
145
|
-
version:
|
151
|
+
version: 0.8.1
|
146
152
|
type: :runtime
|
147
153
|
prerelease: false
|
148
154
|
version_requirements: !ruby/object:Gem::Requirement
|
149
155
|
requirements:
|
150
|
-
- - "
|
156
|
+
- - "~>"
|
151
157
|
- !ruby/object:Gem::Version
|
152
|
-
version:
|
158
|
+
version: 0.8.1
|
153
159
|
- !ruby/object:Gem::Dependency
|
154
160
|
name: webrick
|
155
161
|
requirement: !ruby/object:Gem::Requirement
|
@@ -157,6 +163,9 @@ dependencies:
|
|
157
163
|
- - "~>"
|
158
164
|
- !ruby/object:Gem::Version
|
159
165
|
version: 1.3.1
|
166
|
+
- - ">="
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: 1.3.1
|
160
169
|
type: :runtime
|
161
170
|
prerelease: false
|
162
171
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -164,6 +173,9 @@ dependencies:
|
|
164
173
|
- - "~>"
|
165
174
|
- !ruby/object:Gem::Version
|
166
175
|
version: 1.3.1
|
176
|
+
- - ">="
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
version: 1.3.1
|
167
179
|
- !ruby/object:Gem::Dependency
|
168
180
|
name: rainbow
|
169
181
|
requirement: !ruby/object:Gem::Requirement
|
@@ -185,6 +197,9 @@ dependencies:
|
|
185
197
|
- - "~>"
|
186
198
|
- !ruby/object:Gem::Version
|
187
199
|
version: 2.52.0
|
200
|
+
- - ">="
|
201
|
+
- !ruby/object:Gem::Version
|
202
|
+
version: 2.52.0
|
188
203
|
type: :runtime
|
189
204
|
prerelease: false
|
190
205
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -192,6 +207,9 @@ dependencies:
|
|
192
207
|
- - "~>"
|
193
208
|
- !ruby/object:Gem::Version
|
194
209
|
version: 2.52.0
|
210
|
+
- - ">="
|
211
|
+
- !ruby/object:Gem::Version
|
212
|
+
version: 2.52.0
|
195
213
|
description:
|
196
214
|
email:
|
197
215
|
- learn@flatironschool.com
|
@@ -209,6 +227,7 @@ files:
|
|
209
227
|
- bin/learn-test
|
210
228
|
- learn-test.gemspec
|
211
229
|
- lib/learn_test.rb
|
230
|
+
- lib/learn_test/client.rb
|
212
231
|
- lib/learn_test/dependencies/ant.rb
|
213
232
|
- lib/learn_test/dependencies/csharp.rb
|
214
233
|
- lib/learn_test/dependencies/firefox.rb
|
@@ -223,9 +242,11 @@ files:
|
|
223
242
|
- lib/learn_test/dependency.rb
|
224
243
|
- lib/learn_test/file_finder.rb
|
225
244
|
- lib/learn_test/github_interactor.rb
|
245
|
+
- lib/learn_test/js_strategy.rb
|
226
246
|
- lib/learn_test/learn_oauth_token_parser.rb
|
227
247
|
- lib/learn_test/netrc_interactor.rb
|
228
248
|
- lib/learn_test/repo_parser.rb
|
249
|
+
- lib/learn_test/reporter.rb
|
229
250
|
- lib/learn_test/runner.rb
|
230
251
|
- lib/learn_test/strategies/csharp_nunit.rb
|
231
252
|
- lib/learn_test/strategies/green_onion.rb
|
@@ -276,6 +297,7 @@ files:
|
|
276
297
|
- spec/fixtures/rspec-unit-spec/lib/dog.rb
|
277
298
|
- spec/fixtures/rspec-unit-spec/spec/dog_spec.rb
|
278
299
|
- spec/fixtures/rspec-unit-spec/spec/spec_helper.rb
|
300
|
+
- spec/learn_test/reporter_spec.rb
|
279
301
|
- spec/lib/learn_test/strategies/mocha_spec.rb
|
280
302
|
- spec/repo_parser_spec.rb
|
281
303
|
- spec/spec_helper.rb
|
@@ -295,16 +317,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
295
317
|
version: '0'
|
296
318
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
297
319
|
requirements:
|
298
|
-
- - "
|
320
|
+
- - ">"
|
299
321
|
- !ruby/object:Gem::Version
|
300
|
-
version:
|
322
|
+
version: 1.3.1
|
301
323
|
requirements: []
|
302
324
|
rubyforge_project:
|
303
|
-
rubygems_version: 2.6.
|
325
|
+
rubygems_version: 2.6.11
|
304
326
|
signing_key:
|
305
327
|
specification_version: 4
|
306
|
-
summary: Runs RSpec, Jasmine, and Python Unit Test builds and pushes
|
307
|
-
Learn.
|
328
|
+
summary: Runs RSpec, Jasmine, Karma, Mocha, and Python Unit Test builds and pushes
|
329
|
+
JSON output to Learn.
|
308
330
|
test_files:
|
309
331
|
- spec/features/jasmine_jquery_fixtures_spec.rb
|
310
332
|
- spec/features/rspec_unit_spec.rb
|
@@ -315,6 +337,7 @@ test_files:
|
|
315
337
|
- spec/fixtures/rspec-unit-spec/lib/dog.rb
|
316
338
|
- spec/fixtures/rspec-unit-spec/spec/dog_spec.rb
|
317
339
|
- spec/fixtures/rspec-unit-spec/spec/spec_helper.rb
|
340
|
+
- spec/learn_test/reporter_spec.rb
|
318
341
|
- spec/lib/learn_test/strategies/mocha_spec.rb
|
319
342
|
- spec/repo_parser_spec.rb
|
320
343
|
- spec/spec_helper.rb
|