learn-test 3.1.2 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/Gemfile +2 -0
- data/Rakefile +2 -1
- data/bin/learn-test +15 -14
- data/bin/learn-test-wip +359 -0
- data/learn-test.gemspec +9 -8
- data/lib/learn_test.rb +3 -0
- data/lib/learn_test/client.rb +2 -0
- data/lib/learn_test/dependencies/ant.rb +2 -0
- data/lib/learn_test/dependencies/csharp.rb +3 -1
- data/lib/learn_test/dependencies/imagemagick.rb +2 -0
- data/lib/learn_test/dependencies/java.rb +2 -0
- data/lib/learn_test/dependencies/karma.rb +2 -0
- data/lib/learn_test/dependencies/nodejs.rb +2 -0
- data/lib/learn_test/dependencies/phantomjs.rb +6 -4
- data/lib/learn_test/dependencies/protractor.rb +2 -0
- data/lib/learn_test/dependencies/selenium_server.rb +2 -0
- data/lib/learn_test/dependency.rb +4 -4
- data/lib/learn_test/file_finder.rb +2 -1
- data/lib/learn_test/git_wip.rb +23 -0
- data/lib/learn_test/github_interactor.rb +2 -1
- data/lib/learn_test/js_strategy.rb +3 -1
- data/lib/learn_test/learn_oauth_token_parser.rb +2 -0
- data/lib/learn_test/netrc_interactor.rb +2 -1
- data/lib/learn_test/repo_parser.rb +2 -0
- data/lib/learn_test/reporter.rb +14 -7
- data/lib/learn_test/runner.rb +5 -3
- data/lib/learn_test/strategies/csharp_nunit.rb +5 -3
- data/lib/learn_test/strategies/java_junit.rb +9 -8
- data/lib/learn_test/strategies/karma.rb +9 -5
- data/lib/learn_test/strategies/mocha.rb +10 -8
- data/lib/learn_test/strategies/protractor.rb +7 -6
- data/lib/learn_test/strategies/pytest.rb +13 -13
- data/lib/learn_test/strategies/pytest/requirements_checker.rb +14 -12
- data/lib/learn_test/strategies/rspec.rb +11 -10
- data/lib/learn_test/strategy.rb +5 -6
- data/lib/learn_test/user_id_parser.rb +2 -1
- data/lib/learn_test/username_parser.rb +3 -2
- data/lib/learn_test/version.rb +3 -1
- data/spec/features/rspec_unit_spec.rb +4 -2
- data/spec/fixtures/rspec-unit-spec/lib/dog.rb +3 -1
- data/spec/fixtures/rspec-unit-spec/spec/dog_spec.rb +4 -2
- data/spec/fixtures/rspec-unit-spec/spec/spec_helper.rb +2 -0
- data/spec/learn_test/git_spec.rb +40 -0
- data/spec/learn_test/reporter_spec.rb +69 -31
- data/spec/learn_test/username_parser_spec.rb +2 -0
- data/spec/lib/learn_test/strategies/mocha_spec.rb +21 -20
- data/spec/repo_parser_spec.rb +14 -12
- data/spec/spec_helper.rb +2 -0
- metadata +7 -2
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module LearnTest
|
2
4
|
module Strategies
|
3
5
|
class Mocha < LearnTest::Strategy
|
@@ -8,7 +10,7 @@ module LearnTest
|
|
8
10
|
end
|
9
11
|
|
10
12
|
def detect
|
11
|
-
return false
|
13
|
+
return false unless js_package
|
12
14
|
|
13
15
|
(has_js_dependency?(:mocha) || in_browser?) ? true : false
|
14
16
|
end
|
@@ -58,18 +60,18 @@ module LearnTest
|
|
58
60
|
npm_install
|
59
61
|
|
60
62
|
if in_browser?
|
61
|
-
exec(
|
63
|
+
exec('npm test')
|
62
64
|
else
|
63
65
|
run_node_based_mocha
|
64
66
|
end
|
65
67
|
end
|
66
68
|
|
67
69
|
def run_node_based_mocha
|
68
|
-
command = if (js_package[:scripts] && js_package[:scripts][:test] ||
|
69
|
-
|
70
|
+
command = if (js_package[:scripts] && js_package[:scripts][:test] || '').include?('.results.json')
|
71
|
+
'npm test'
|
70
72
|
else
|
71
73
|
install_mocha_multi
|
72
|
-
|
74
|
+
'node_modules/.bin/mocha -R mocha-multi --reporter-options spec=-,json=.results.json'
|
73
75
|
end
|
74
76
|
|
75
77
|
system(command)
|
@@ -84,9 +86,9 @@ module LearnTest
|
|
84
86
|
end
|
85
87
|
|
86
88
|
def install_mocha_multi
|
87
|
-
if
|
88
|
-
|
89
|
-
|
89
|
+
return if File.exist?('node_modules/mocha-multi')
|
90
|
+
|
91
|
+
run_install('npm install mocha-multi', npm_install: true)
|
90
92
|
end
|
91
93
|
end
|
92
94
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'open3'
|
2
4
|
|
3
5
|
module LearnTest
|
@@ -17,7 +19,7 @@ module LearnTest
|
|
17
19
|
end
|
18
20
|
|
19
21
|
def run
|
20
|
-
|
22
|
+
unless selenium_running?
|
21
23
|
stdin, stdout, stderr, wait_thr = Open3.popen3('webdriver-manager start')
|
22
24
|
@pid = wait_thr.pid
|
23
25
|
|
@@ -88,14 +90,14 @@ module LearnTest
|
|
88
90
|
|
89
91
|
def passing_count
|
90
92
|
@passing_count ||= output.inject(0) do |count, test|
|
91
|
-
count += 1 if test[:assertions].all?{ |a| a[:passed] }
|
93
|
+
count += 1 if test[:assertions].all? { |a| a[:passed] }
|
92
94
|
count
|
93
95
|
end
|
94
96
|
end
|
95
97
|
|
96
98
|
def failure_count
|
97
99
|
@failure_count ||= output.inject(0) do |count, test|
|
98
|
-
count += 1
|
100
|
+
count += 1 unless test[:assertions].all? { |a| a[:passed] }
|
99
101
|
count
|
100
102
|
end
|
101
103
|
end
|
@@ -114,14 +116,13 @@ module LearnTest
|
|
114
116
|
end
|
115
117
|
|
116
118
|
def selenium_running?
|
117
|
-
process = `ps aux | grep selenium`.split("\n").detect{ |p| p.include?('chromedriver') }
|
119
|
+
process = `ps aux | grep selenium`.split("\n").detect { |p| p.include?('chromedriver') }
|
118
120
|
if process
|
119
121
|
@selenium_pid = process.split[1].to_i
|
120
122
|
return true
|
121
123
|
end
|
122
|
-
|
124
|
+
false
|
123
125
|
end
|
124
|
-
|
125
126
|
end
|
126
127
|
end
|
127
128
|
end
|
@@ -1,10 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'crack'
|
2
4
|
require_relative 'pytest/requirements_checker'
|
3
5
|
|
4
6
|
module LearnTest
|
5
7
|
module Strategies
|
6
8
|
class Pytest < LearnTest::Strategy
|
7
|
-
|
8
9
|
def service_endpoint
|
9
10
|
'/e/flatiron_pytest'
|
10
11
|
end
|
@@ -22,18 +23,18 @@ module LearnTest
|
|
22
23
|
end
|
23
24
|
|
24
25
|
def output
|
25
|
-
@output ||= Crack::XML.parse(File.read('.results.xml'))[
|
26
|
+
@output ||= Crack::XML.parse(File.read('.results.xml'))['testsuite']
|
26
27
|
end
|
27
28
|
|
28
29
|
def test_files
|
29
30
|
# pytest will run all files of the form test_*.py or *_test.py
|
30
|
-
@test_files ||= Dir.glob(
|
31
|
+
@test_files ||= Dir.glob('**/test_*.py') + Dir.glob('**/*_test.py')
|
31
32
|
end
|
32
33
|
|
33
34
|
def results
|
34
|
-
failed_count = output[
|
35
|
-
skipped_count = output[
|
36
|
-
passed_count = output[
|
35
|
+
failed_count = output['failures'].to_i + output['errors'].to_i
|
36
|
+
skipped_count = output['skips'].to_i
|
37
|
+
passed_count = output['tests'].to_i - failed_count - skipped_count
|
37
38
|
{
|
38
39
|
username: username,
|
39
40
|
github_user_id: user_id,
|
@@ -43,10 +44,10 @@ module LearnTest
|
|
43
44
|
test_suite: [{
|
44
45
|
framework: 'pytest',
|
45
46
|
formatted_output: output.to_json,
|
46
|
-
duration: output[
|
47
|
+
duration: output['time']
|
47
48
|
}]
|
48
49
|
},
|
49
|
-
examples: output[
|
50
|
+
examples: output['tests'].to_i,
|
50
51
|
passing_count: passed_count,
|
51
52
|
pending_count: skipped_count,
|
52
53
|
failure_count: failed_count,
|
@@ -70,16 +71,15 @@ module LearnTest
|
|
70
71
|
# if there is a single test the `testcase` xml parse turns out a hash
|
71
72
|
# instead of an array with a single hash. this will make sure single
|
72
73
|
# tests have the same output structure (Array) as multiple tests
|
73
|
-
output[
|
74
|
+
output['testcase'] = [output['testcase']].flatten
|
74
75
|
|
75
|
-
output[
|
76
|
-
if example.has_key?(
|
77
|
-
errors << example.map{|k, v| "#{k}: #{v}"}
|
76
|
+
output['testcase'].reduce([]) do |errors, example|
|
77
|
+
if example.has_key?('failure')
|
78
|
+
errors << example.map { |k, v| "#{k}: #{v}" }
|
78
79
|
end
|
79
80
|
errors
|
80
81
|
end
|
81
82
|
end
|
82
|
-
|
83
83
|
end
|
84
84
|
end
|
85
85
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'open3'
|
2
4
|
|
3
5
|
module LearnTest
|
@@ -12,10 +14,10 @@ module LearnTest
|
|
12
14
|
|
13
15
|
class PythonChecker
|
14
16
|
def self.check
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
return unless !self.python_installed? || !self.correct_python_version?
|
18
|
+
|
19
|
+
puts 'Please install python 2.7.x or 3.x.x'
|
20
|
+
exit
|
19
21
|
end
|
20
22
|
|
21
23
|
def self.python_installed?
|
@@ -31,10 +33,10 @@ module LearnTest
|
|
31
33
|
|
32
34
|
class PipChecker
|
33
35
|
def self.check
|
34
|
-
if
|
35
|
-
|
36
|
-
|
37
|
-
|
36
|
+
return if self.pip_installed?
|
37
|
+
|
38
|
+
puts 'Please ensure pip is installed'
|
39
|
+
exit
|
38
40
|
end
|
39
41
|
|
40
42
|
def self.pip_installed?
|
@@ -44,10 +46,10 @@ module LearnTest
|
|
44
46
|
|
45
47
|
class PytestChecker
|
46
48
|
def self.check
|
47
|
-
if
|
48
|
-
|
49
|
-
|
50
|
-
|
49
|
+
return if self.pytest_installed?
|
50
|
+
|
51
|
+
puts 'Please ensure pytest is installed'
|
52
|
+
exit
|
51
53
|
end
|
52
54
|
|
53
55
|
def self.pytest_installed?
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module LearnTest
|
2
4
|
module Strategies
|
3
5
|
class Rspec < LearnTest::Strategy
|
@@ -11,8 +13,8 @@ module LearnTest
|
|
11
13
|
|
12
14
|
def configure
|
13
15
|
if format_option_present?
|
14
|
-
if dot_rspec.any? {|dot_opt| dot_opt.match(/--format|-f/)}
|
15
|
-
argv << dot_rspec.reject {|dot_opt| dot_opt.match(/--format|-f/)}
|
16
|
+
if dot_rspec.any? { |dot_opt| dot_opt.match(/--format|-f/) }
|
17
|
+
argv << dot_rspec.reject { |dot_opt| dot_opt.match(/--format|-f/) }
|
16
18
|
else
|
17
19
|
argv << dot_rspec
|
18
20
|
end
|
@@ -26,14 +28,14 @@ module LearnTest
|
|
26
28
|
end
|
27
29
|
|
28
30
|
if example_option_present?
|
29
|
-
argv << options[:example].map{|e| "--example #{e}"}.join(
|
31
|
+
argv << options[:example].map { |e| "--example #{e}" }.join(' ')
|
30
32
|
end
|
31
33
|
|
32
34
|
# Don't pass the test/local flag from learn binary to rspec runner.
|
33
|
-
argv.delete(
|
34
|
-
argv.delete(
|
35
|
-
argv.delete(
|
36
|
-
argv.delete(
|
35
|
+
argv.delete('--test')
|
36
|
+
argv.delete('-t')
|
37
|
+
argv.delete('-l')
|
38
|
+
argv.delete('--local')
|
37
39
|
end
|
38
40
|
|
39
41
|
def run
|
@@ -98,13 +100,12 @@ module LearnTest
|
|
98
100
|
def failures
|
99
101
|
if output
|
100
102
|
output[:examples].select do |example|
|
101
|
-
example[:status] ==
|
102
|
-
end.map { |ex| ex[:full_description] }.join(
|
103
|
+
example[:status] == 'failed'
|
104
|
+
end.map { |ex| ex[:full_description] }.join(';')
|
103
105
|
else
|
104
106
|
'A syntax error prevented RSpec from running.'
|
105
107
|
end
|
106
108
|
end
|
107
|
-
|
108
109
|
end
|
109
110
|
end
|
110
111
|
end
|
data/lib/learn_test/strategy.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module LearnTest
|
2
4
|
class Strategy
|
3
5
|
attr_reader :runner, :options
|
@@ -11,11 +13,9 @@ module LearnTest
|
|
11
13
|
raise NotImplementedError, 'you must add the service endpoint to the test strategy'
|
12
14
|
end
|
13
15
|
|
14
|
-
def check_dependencies
|
15
|
-
end
|
16
|
+
def check_dependencies; end
|
16
17
|
|
17
|
-
def configure
|
18
|
-
end
|
18
|
+
def configure; end
|
19
19
|
|
20
20
|
def run
|
21
21
|
raise NotImplementedError, 'you must implement how this strategy runs its tests'
|
@@ -33,8 +33,7 @@ module LearnTest
|
|
33
33
|
true
|
34
34
|
end
|
35
35
|
|
36
|
-
def cleanup
|
37
|
-
end
|
36
|
+
def cleanup; end
|
38
37
|
|
39
38
|
def username
|
40
39
|
@username ||= LearnTest::UsernameParser.get_username
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module LearnTest
|
2
4
|
class UsernameParser
|
3
5
|
def self.get_username
|
@@ -6,7 +8,7 @@ module LearnTest
|
|
6
8
|
user_id = parser.user_id
|
7
9
|
|
8
10
|
if !LearnTest::LearnOauthTokenParser.get_learn_oauth_token && (!username || user_id == 'none')
|
9
|
-
print
|
11
|
+
print 'Enter your github username: '
|
10
12
|
username = $stdin.gets.strip
|
11
13
|
user_id = LearnTest::GithubInteractor.get_user_id_for(username)
|
12
14
|
parser.write(username, user_id)
|
@@ -16,4 +18,3 @@ module LearnTest
|
|
16
18
|
end
|
17
19
|
end
|
18
20
|
end
|
19
|
-
|
data/lib/learn_test/version.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe 'Running a RSpec Unit Test' do
|
2
4
|
before(:all) do
|
3
5
|
# While it doesn't cause these tests to fail, nasty messages occur (and more)
|
4
6
|
# when either a ~/.netrc entry or file itself doesn't exist. This aims to correct that,
|
@@ -30,6 +32,6 @@ describe "Running a RSpec Unit Test" do
|
|
30
32
|
expect(output).to include('2 examples, 0 failures')
|
31
33
|
expect(output).to_not include('3 examples')
|
32
34
|
expect(output).to_not include('1 example')
|
33
|
-
end
|
35
|
+
end
|
34
36
|
end
|
35
37
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
describe LearnTest::GitWip do
|
4
|
+
subject { described_class }
|
5
|
+
|
6
|
+
let!(:working_branch) { 'develop' }
|
7
|
+
let!(:git_url) { 'https://github.com/learn-co/learn-test' }
|
8
|
+
let!(:git_base) { instance_double(Git::Base) }
|
9
|
+
|
10
|
+
context 'success' do
|
11
|
+
it 'should return the git url' do
|
12
|
+
expect(Git::Base).to receive(:open).with('./', { log: false }).and_return(git_base)
|
13
|
+
expect(git_base).to receive(:current_branch).and_return(working_branch)
|
14
|
+
|
15
|
+
expect(subject).to receive(:`).with(/learn-test-wip save ".+" -u &> \/dev\/null/ )
|
16
|
+
expect($?).to receive(:success?).and_return(true)
|
17
|
+
|
18
|
+
expect(git_base).to receive(:push).with('origin', "wip/#{working_branch}:refs/heads/wip")
|
19
|
+
expect(git_base).to receive_message_chain(:config, :[]).with('remote.origin.url').and_return("#{git_url}.git")
|
20
|
+
|
21
|
+
expect(subject.run!).to eq("#{git_url}/tree/wip")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'failure' do
|
26
|
+
it 'should return false on process error' do
|
27
|
+
allow(Git::Base).to receive(:open).and_return(git_base)
|
28
|
+
allow(git_base).to receive(:current_branch)
|
29
|
+
allow(subject).to receive(:`)
|
30
|
+
|
31
|
+
expect($?).to receive(:success?).and_return(false)
|
32
|
+
expect(subject.run!).to eq(false)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should return false on StandardError' do
|
36
|
+
expect(Git::Base).to receive(:open).and_raise(StandardError)
|
37
|
+
expect(subject.run!).to eq(false)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
require_relative '../../lib/learn_test/reporter'
|
@@ -6,14 +8,15 @@ require 'tempfile'
|
|
6
8
|
require 'json'
|
7
9
|
|
8
10
|
describe LearnTest::Reporter do
|
9
|
-
let(:
|
11
|
+
let!(:client) { instance_spy(LearnTest::Client) }
|
12
|
+
let!(:git_tree) { 'https://github.com/learn-co/learn-test/tree/wip' }
|
13
|
+
let!(:strategy) do
|
10
14
|
instance_spy(
|
11
15
|
LearnTest::Strategy,
|
12
|
-
service_endpoint:
|
16
|
+
service_endpoint: 'test_endpoint',
|
13
17
|
results: { test: 'result' }
|
14
18
|
)
|
15
|
-
|
16
|
-
let(:client) { instance_spy(LearnTest::Client) }
|
19
|
+
end
|
17
20
|
|
18
21
|
def with_file(name, content = nil, &block)
|
19
22
|
file = Tempfile.new(name)
|
@@ -30,36 +33,62 @@ describe LearnTest::Reporter do
|
|
30
33
|
describe '#report' do
|
31
34
|
let(:reporter) { described_class.new(strategy, client: client) }
|
32
35
|
|
33
|
-
context
|
34
|
-
it
|
36
|
+
context 'with debug flag and failed attempt posting results' do
|
37
|
+
it 'outputs an error message' do
|
35
38
|
allow(client).to receive(:post_results).and_return(false)
|
36
|
-
reporter.debug = true
|
37
|
-
io = StringIO.new
|
38
39
|
|
39
|
-
|
40
|
+
expect do
|
41
|
+
reporter.debug = true
|
42
|
+
reporter.report
|
43
|
+
end.to output(/Learn/i).to_stdout
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'sync with Github' do
|
48
|
+
it 'should not run LearnTest::GitWip, if :post_results fails' do
|
49
|
+
expect(client).to receive(:post_results).and_return(false)
|
50
|
+
expect(LearnTest::GitWip).to_not receive(:run!)
|
51
|
+
|
52
|
+
reporter.report
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should run LearnTest::GitWip.run!' do
|
56
|
+
expect(client).to receive(:post_results).and_return(true)
|
57
|
+
expect(LearnTest::GitWip).to receive(:run!).and_return(:git_tree)
|
58
|
+
|
59
|
+
reporter.report
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should not output an error message without debug' do
|
63
|
+
expect(client).to receive(:post_results).and_return(true)
|
64
|
+
expect(LearnTest::GitWip).to receive(:run!).and_return(false)
|
65
|
+
|
66
|
+
expect { reporter.report }.to_not output.to_stdout
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should output an error message with debug' do
|
70
|
+
expect(client).to receive(:post_results).and_return(true)
|
71
|
+
expect(LearnTest::GitWip).to receive(:run!).and_return(false)
|
40
72
|
|
41
|
-
expect
|
73
|
+
expect do
|
74
|
+
reporter.debug = true
|
75
|
+
reporter.report
|
76
|
+
end.to output(/Github/i).to_stdout
|
42
77
|
end
|
43
78
|
end
|
44
79
|
|
45
80
|
it 'posts results to the service endpoint' do
|
46
81
|
reporter.report
|
47
82
|
|
83
|
+
allow(LearnTest::GitWip).to receive(:run!).and_return(:git_tree)
|
84
|
+
|
48
85
|
expect(client).to have_received(:post_results)
|
49
86
|
.with(strategy.service_endpoint, strategy.results)
|
50
87
|
end
|
51
88
|
|
52
89
|
it 'does not output an error message without debug' do
|
53
|
-
|
54
|
-
|
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
|
90
|
+
expect(client).to receive(:post_results).and_return(false)
|
91
|
+
expect { reporter.report }.to_not output.to_stdout
|
63
92
|
end
|
64
93
|
|
65
94
|
it 'saves the failed attempt when the post results call fails' do
|
@@ -70,9 +99,9 @@ describe LearnTest::Reporter do
|
|
70
99
|
reporter.report
|
71
100
|
|
72
101
|
report = JSON.dump(strategy.results)
|
73
|
-
expect(File.
|
102
|
+
expect(File.exist?(tmp_file.path)).to be(true)
|
74
103
|
expect(reporter.failed_reports).to eq({
|
75
|
-
strategy.service_endpoint => [JSON.
|
104
|
+
strategy.service_endpoint => [JSON.parse(report)]
|
76
105
|
})
|
77
106
|
end
|
78
107
|
end
|
@@ -87,8 +116,9 @@ describe LearnTest::Reporter do
|
|
87
116
|
reporter.report
|
88
117
|
|
89
118
|
report = JSON.dump(strategy.results)
|
90
|
-
json_report = JSON.
|
91
|
-
|
119
|
+
json_report = JSON.parse(report)
|
120
|
+
|
121
|
+
expect(File.exist?(tmp_file.path)).to be(true)
|
92
122
|
expect(reporter.failed_reports).to eq({
|
93
123
|
strategy.service_endpoint => [json_report, json_report]
|
94
124
|
})
|
@@ -101,23 +131,30 @@ describe LearnTest::Reporter do
|
|
101
131
|
|
102
132
|
it 'deletes the output file when all reports are sent successfully' do
|
103
133
|
allow(client).to receive(:post_results).and_return(true)
|
104
|
-
|
134
|
+
allow(LearnTest::GitWip).to receive(:run!).and_return(:git_tree)
|
135
|
+
|
136
|
+
reports = { hello: ['world'] }
|
137
|
+
|
105
138
|
with_file('retry_failed_reports', reports) do |file|
|
106
139
|
reporter.output_path = file.path
|
107
140
|
reporter.retry_failed_reports
|
108
141
|
|
109
|
-
expect(File.
|
142
|
+
expect(File.exist?(file.path)).to be(false)
|
110
143
|
end
|
111
144
|
end
|
112
145
|
|
113
146
|
it 'writes the remaining reports from the output file' do
|
114
147
|
allow(client).to receive(:post_results).and_return(true, false)
|
115
|
-
|
148
|
+
allow(LearnTest::GitWip).to receive(:run!).and_return(:git_tree)
|
149
|
+
|
150
|
+
reports = { success: ['world'], failure: ['hello'] }
|
151
|
+
|
116
152
|
with_file('retry_failed_reports', reports) do |file|
|
117
153
|
reporter.output_path = file.path
|
118
154
|
reporter.retry_failed_reports
|
119
|
-
|
120
|
-
expect(
|
155
|
+
|
156
|
+
expect(File.exist?(file.path)).to be(true)
|
157
|
+
expect(reporter.failed_reports).to eq({ 'failure' => ['hello'] })
|
121
158
|
end
|
122
159
|
end
|
123
160
|
end
|
@@ -125,6 +162,7 @@ describe LearnTest::Reporter do
|
|
125
162
|
describe '#failed_reports' do
|
126
163
|
let(:path) { 'failed_reports' }
|
127
164
|
let(:reporter) { described_class.new(strategy, output_path: path) }
|
165
|
+
|
128
166
|
subject { reporter.failed_reports }
|
129
167
|
|
130
168
|
context 'with no file at location' do
|
@@ -137,9 +175,9 @@ describe LearnTest::Reporter do
|
|
137
175
|
|
138
176
|
context 'with returns the JSON contents of the file' do
|
139
177
|
it {
|
140
|
-
with_file(path, {hello:
|
178
|
+
with_file(path, { hello: 'world' }) do |file|
|
141
179
|
reporter.output_path = file.path
|
142
|
-
is_expected.to eq({
|
180
|
+
is_expected.to eq({ 'hello' => 'world' })
|
143
181
|
end
|
144
182
|
}
|
145
183
|
end
|