learn-test 3.2.2 → 3.3.0.pre.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +27 -0
- data/Gemfile +2 -0
- data/learn-test.gemspec +1 -0
- data/lib/learn_test.rb +15 -34
- data/lib/learn_test/git.rb +19 -0
- data/lib/learn_test/git/wip/base.rb +87 -0
- data/lib/learn_test/git/wip/branch.rb +36 -0
- data/lib/learn_test/git/wip/error.rb +23 -0
- data/lib/learn_test/repo_parser.rb +1 -1
- data/lib/learn_test/reporter.rb +23 -12
- data/lib/learn_test/runner.rb +6 -9
- data/lib/learn_test/strategies/none.rb +6 -10
- data/lib/learn_test/strategy.rb +1 -1
- data/lib/learn_test/version.rb +1 -1
- data/spec/features/rspec_unit_spec.rb +20 -6
- data/spec/fixtures/rspec-unit-spec/.results.json +1 -0
- data/spec/fixtures/rspec-unit-spec/spec/spec_helper.rb +0 -82
- data/spec/learn_test/git/wip/base_spec.rb +89 -0
- data/spec/learn_test/git/wip/branch_spec.rb +121 -0
- data/spec/learn_test/git/wip/error_spec.rb +41 -0
- data/spec/learn_test/git_spec.rb +38 -32
- data/spec/learn_test/reporter_spec.rb +44 -16
- data/spec/lib/learn_test/strategies/none_spec.rb +7 -30
- data/spec/spec_helper.rb +10 -0
- data/spec/support/git.rb +17 -0
- metadata +38 -12
- data/bin/learn-test-wip +0 -249
- data/lib/learn_test/git_wip.rb +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a1a864132415df805ab19a42f9a8c5d3892602742fca35cf3a8aff5ae5e7a97
|
4
|
+
data.tar.gz: 62fcb6feb51b50944d9622fb4306d815125c9338efc1be888775037e853b6d70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52ab71e5a63eec57aba9391d97255d4aca85e62c9adae8dadb7f02efb0591d6f3d0637a203fca5b1c47fb27cd627c935d837b2e05f55f79f0b7dc1ebbcf025d7
|
7
|
+
data.tar.gz: 94c627e54f10bbb7ae74f482c4d806ccba4de548b6530843524d950c6a5da3286d5e2e422a70a242daa1e51f66181950c991927e5f0eac38af874195bf176e23
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
Layout/EmptyLinesAroundAttributeAccessor:
|
2
|
+
Enabled: true
|
3
|
+
|
4
|
+
Layout/FirstHashElementIndentation:
|
5
|
+
EnforcedStyle: consistent
|
6
|
+
|
7
|
+
Layout/SpaceAroundMethodCallOperator:
|
8
|
+
Enabled: true
|
9
|
+
|
10
|
+
Lint/RaiseException:
|
11
|
+
Enabled: true
|
12
|
+
|
13
|
+
Metrics/AbcSize:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Metrics/BlockLength:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Metrics/MethodLength:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Metrics/PerceivedComplexity:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
# TODO: Add top-level module documentation
|
26
|
+
Style/Documentation:
|
27
|
+
Enabled: false
|
data/Gemfile
CHANGED
data/learn-test.gemspec
CHANGED
data/lib/learn_test.rb
CHANGED
@@ -3,42 +3,23 @@
|
|
3
3
|
require 'fileutils'
|
4
4
|
require 'oj'
|
5
5
|
require 'colorize'
|
6
|
+
require 'zeitwerk'
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
require_relative 'learn_test/file_finder'
|
16
|
-
require_relative 'learn_test/runner'
|
17
|
-
|
18
|
-
require_relative 'learn_test/dependency'
|
19
|
-
|
20
|
-
require_relative 'learn_test/strategy'
|
21
|
-
require_relative 'learn_test/js_strategy'
|
22
|
-
require_relative 'learn_test/strategies/rspec'
|
23
|
-
require_relative 'learn_test/strategies/karma'
|
24
|
-
require_relative 'learn_test/strategies/protractor'
|
25
|
-
require_relative 'learn_test/strategies/java_junit'
|
26
|
-
require_relative 'learn_test/strategies/csharp_nunit'
|
27
|
-
require_relative 'learn_test/strategies/mocha'
|
28
|
-
require_relative 'learn_test/strategies/pytest'
|
29
|
-
require_relative 'learn_test/strategies/none'
|
8
|
+
loader = Zeitwerk::Loader.for_gem
|
9
|
+
loader.inflector.inflect(
|
10
|
+
'csharp' => 'CSharp',
|
11
|
+
'csharp_nunit' => 'CSharpNunit',
|
12
|
+
'nodejs' => 'NodeJS',
|
13
|
+
'phantomjs' => 'PhantomJS'
|
14
|
+
)
|
15
|
+
loader.setup
|
30
16
|
|
31
17
|
module LearnTest
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
autoload :CSharp, 'learn_test/dependencies/csharp'
|
39
|
-
autoload :Ant, 'learn_test/dependencies/ant'
|
40
|
-
autoload :Imagemagick, 'learn_test/dependencies/imagemagick'
|
41
|
-
autoload :SeleniumServer, 'learn_test/dependencies/selenium_server'
|
42
|
-
autoload :Pytest, 'learn_test/dependencies/pytest'
|
18
|
+
def self.root
|
19
|
+
File.dirname __dir__
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.bin
|
23
|
+
File.join root, 'bin'
|
43
24
|
end
|
44
25
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'git'
|
4
|
+
|
5
|
+
module LearnTest
|
6
|
+
module Git
|
7
|
+
def self.open(directory: './', options: {})
|
8
|
+
Base.open(directory, options)
|
9
|
+
end
|
10
|
+
|
11
|
+
class Base < ::Git::Base
|
12
|
+
def wip(message:)
|
13
|
+
wip = Wip::Base.new(base: self, message: message)
|
14
|
+
wip.process!
|
15
|
+
wip
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
require 'git'
|
5
|
+
require 'logger'
|
6
|
+
require 'tempfile'
|
7
|
+
|
8
|
+
module LearnTest
|
9
|
+
module Git
|
10
|
+
module Wip
|
11
|
+
class Base < ::Git::Path
|
12
|
+
TEMPFILE = '.wip'
|
13
|
+
|
14
|
+
attr_reader :working_branch, :wip_branch
|
15
|
+
|
16
|
+
def initialize(base:, message:)
|
17
|
+
@base = base
|
18
|
+
@message = message
|
19
|
+
@success = nil
|
20
|
+
|
21
|
+
current_branch = @base.current_branch
|
22
|
+
|
23
|
+
raise NoCommitsError, 'master' if current_branch.nil? # TODO: Swap to `main`?
|
24
|
+
|
25
|
+
@tmp = Tempfile.new(TEMPFILE)
|
26
|
+
@working_branch = Branch.new(base: @base, name: current_branch)
|
27
|
+
@wip_branch = Reference.new(base: @base, name: current_branch)
|
28
|
+
end
|
29
|
+
|
30
|
+
def process!
|
31
|
+
if @wip_branch.last_revision
|
32
|
+
merge = @base.merge_base(@wip_branch.last_revision, @working_branch.last_revision)
|
33
|
+
|
34
|
+
@wip_branch.parent = if merge == @working_branch.last_revision
|
35
|
+
@wip_branch.last_revision
|
36
|
+
else
|
37
|
+
@working_branch.last_revision
|
38
|
+
end
|
39
|
+
else
|
40
|
+
@wip_branch.parent = @working_branch.last_revision
|
41
|
+
end
|
42
|
+
|
43
|
+
new_tree = build_new_tree(@wip_branch.parent)
|
44
|
+
@base.diff(new_tree, @wip_branch.parent)
|
45
|
+
|
46
|
+
# tree_diff = @base.diff(new_tree, @wip_branch.parent)
|
47
|
+
# raise LearnTest::Git::Wip::NoChangesError, @wip_branch if tree_diff.count.zero?
|
48
|
+
|
49
|
+
commit = @base.commit_tree(new_tree, parent: @wip_branch.parent)
|
50
|
+
|
51
|
+
@base.lib.send(:command, 'update-ref', ['-m', @message, @wip_branch, commit.objectish])
|
52
|
+
|
53
|
+
@success = true
|
54
|
+
ensure
|
55
|
+
cleanup
|
56
|
+
end
|
57
|
+
|
58
|
+
def success?
|
59
|
+
@success
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def build_new_tree(wip_parent)
|
65
|
+
index = "#{@tmp.path}-index"
|
66
|
+
|
67
|
+
FileUtils.rm(index, force: true)
|
68
|
+
FileUtils.cp("#{@base.dir.path}/.git/index", index)
|
69
|
+
|
70
|
+
@base.read_tree(wip_parent)
|
71
|
+
@base.lib.send(:command, 'add', ['--update', '--', '.'])
|
72
|
+
@base.add(all: true)
|
73
|
+
|
74
|
+
new_tree_obj = @base.write_tree
|
75
|
+
|
76
|
+
FileUtils.rm(index, force: true)
|
77
|
+
|
78
|
+
new_tree_obj
|
79
|
+
end
|
80
|
+
|
81
|
+
def cleanup
|
82
|
+
FileUtils.rm("#{@tmp.path}-*", force: true)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LearnTest
|
4
|
+
module Git
|
5
|
+
module Wip
|
6
|
+
class Branch
|
7
|
+
attr_accessor :parent
|
8
|
+
|
9
|
+
def initialize(base:, name:)
|
10
|
+
@base = base
|
11
|
+
@name = name
|
12
|
+
end
|
13
|
+
|
14
|
+
def last_revision(raise_no_commits: false)
|
15
|
+
@last_revision ||= begin
|
16
|
+
begin
|
17
|
+
@base.revparse(@name)
|
18
|
+
rescue ::Git::GitExecuteError => e
|
19
|
+
if raise_no_commits
|
20
|
+
raise e.message.match(LearnTest::Git::Wip::NoCommitsError::REGEX) ? LearnTest::Git::Wip::NoCommitsError.new(@name) : e
|
21
|
+
end
|
22
|
+
|
23
|
+
raise unless e.message.match(LearnTest::Git::Wip::NoCommitsError::REGEX)
|
24
|
+
|
25
|
+
false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_s
|
31
|
+
@name
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LearnTest
|
4
|
+
module Git
|
5
|
+
module Wip
|
6
|
+
class Error < StandardError; end
|
7
|
+
|
8
|
+
class NoChangesError < Error
|
9
|
+
def initialize(branch)
|
10
|
+
super "No changes found on `#{branch}`"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class NoCommitsError < Error
|
15
|
+
REGEX = /unknown revision or path not in the working tree/i.freeze
|
16
|
+
|
17
|
+
def initialize(branch)
|
18
|
+
super "Branch `#{branch}` doesn't have any commits. Please commit and try again."
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -6,7 +6,7 @@ module LearnTest
|
|
6
6
|
class RepoParser
|
7
7
|
def self.get_repo
|
8
8
|
begin
|
9
|
-
repo = Git.open(FileUtils.pwd)
|
9
|
+
repo = ::Git.open(FileUtils.pwd)
|
10
10
|
rescue
|
11
11
|
puts "You don't appear to be in a Learn lesson's directory. Please enter 'learn open' or cd to an appropriate directory and try again."
|
12
12
|
die
|
data/lib/learn_test/reporter.rb
CHANGED
@@ -3,9 +3,6 @@
|
|
3
3
|
require 'fileutils'
|
4
4
|
require 'json'
|
5
5
|
|
6
|
-
require_relative 'client'
|
7
|
-
require_relative 'git_wip'
|
8
|
-
|
9
6
|
module LearnTest
|
10
7
|
class Reporter
|
11
8
|
attr_accessor :output_path, :debug
|
@@ -50,16 +47,30 @@ module LearnTest
|
|
50
47
|
endpoint = strategy.service_endpoint
|
51
48
|
augment_results!(results)
|
52
49
|
|
53
|
-
|
54
|
-
|
55
|
-
puts 'There was a problem connecting to Github. Not pushing current branch state.'.red
|
56
|
-
end
|
57
|
-
else
|
58
|
-
if @debug
|
59
|
-
puts 'There was a problem connecting to Learn. Not pushing test results.'.red
|
60
|
-
end
|
50
|
+
unless client.post_results(endpoint, results)
|
51
|
+
puts 'There was a problem connecting to Learn. Not pushing test results.'.red if @debug
|
61
52
|
|
62
53
|
save_failed_attempt(endpoint, results)
|
54
|
+
return
|
55
|
+
end
|
56
|
+
|
57
|
+
logger = @debug ? Logger.new(STDOUT, level: Logger::DEBUG) : false
|
58
|
+
repo = LearnTest::Git.open(options: { log: logger })
|
59
|
+
|
60
|
+
res = repo.wip(message: 'Automatic test submission')
|
61
|
+
|
62
|
+
unless res.success?
|
63
|
+
puts 'There was a problem creating your WIP branch. Not pushing current branch state.'.red if @debug
|
64
|
+
return
|
65
|
+
end
|
66
|
+
|
67
|
+
begin
|
68
|
+
repo.push('origin', "#{res.wip_branch}:refs/heads/fis-wip", { force: true })
|
69
|
+
rescue ::Git::GitExecuteError => e
|
70
|
+
if @debug
|
71
|
+
puts 'There was a problem connecting to GitHub. Not pushing current branch state.'.red
|
72
|
+
puts e.message
|
73
|
+
end
|
63
74
|
end
|
64
75
|
end
|
65
76
|
|
@@ -89,7 +100,7 @@ module LearnTest
|
|
89
100
|
|
90
101
|
def augment_results!(results)
|
91
102
|
if File.exist?("#{FileUtils.pwd}/.learn")
|
92
|
-
dot_learn = YAML.
|
103
|
+
dot_learn = YAML.safe_load(File.read("#{FileUtils.pwd}/.learn"))
|
93
104
|
|
94
105
|
unless dot_learn['github'].nil?
|
95
106
|
results[:github] = dot_learn['github']
|
data/lib/learn_test/runner.rb
CHANGED
@@ -9,7 +9,6 @@ module LearnTest
|
|
9
9
|
def initialize(repo, options = {})
|
10
10
|
@repo = repo
|
11
11
|
@options = options
|
12
|
-
die unless strategy
|
13
12
|
end
|
14
13
|
|
15
14
|
def run
|
@@ -34,7 +33,11 @@ module LearnTest
|
|
34
33
|
end
|
35
34
|
|
36
35
|
def strategy
|
37
|
-
@strategy
|
36
|
+
return @strategy if @strategy
|
37
|
+
|
38
|
+
detected = strategies.map { |s| s.new(self) }.detect(&:detect)
|
39
|
+
|
40
|
+
@strategy = detected || LearnTest::Strategies::None.new(self)
|
38
41
|
end
|
39
42
|
|
40
43
|
private
|
@@ -57,8 +60,7 @@ module LearnTest
|
|
57
60
|
LearnTest::Strategies::Protractor,
|
58
61
|
LearnTest::Strategies::JavaJunit,
|
59
62
|
LearnTest::Strategies::Mocha,
|
60
|
-
LearnTest::Strategies::Pytest
|
61
|
-
LearnTest::Strategies::None
|
63
|
+
LearnTest::Strategies::Pytest
|
62
64
|
]
|
63
65
|
end
|
64
66
|
|
@@ -69,10 +71,5 @@ module LearnTest
|
|
69
71
|
def local_test_run?
|
70
72
|
options.include?('-h') || options.include?('--local')
|
71
73
|
end
|
72
|
-
|
73
|
-
def die
|
74
|
-
puts "This directory doesn't appear to have any specs in it."
|
75
|
-
exit
|
76
|
-
end
|
77
74
|
end
|
78
75
|
end
|
@@ -7,12 +7,12 @@ module LearnTest
|
|
7
7
|
'/e/flatiron_none'
|
8
8
|
end
|
9
9
|
|
10
|
-
def detect
|
11
|
-
runner.files.include?('.canvas')
|
12
|
-
end
|
13
|
-
|
14
10
|
def run
|
15
|
-
puts
|
11
|
+
puts <<~MSG
|
12
|
+
This directory doesn't appear to have any specs in it, so there’s no test to run.
|
13
|
+
|
14
|
+
If you are working on Canvas, this assignment has been submitted. You can resubmit by running `learn test` again.
|
15
|
+
MSG
|
16
16
|
end
|
17
17
|
|
18
18
|
def results
|
@@ -22,11 +22,7 @@ module LearnTest
|
|
22
22
|
learn_oauth_token: learn_oauth_token,
|
23
23
|
repo_name: runner.repo,
|
24
24
|
build: {
|
25
|
-
test_suite: [{
|
26
|
-
framework: 'none',
|
27
|
-
formatted_output: '',
|
28
|
-
duration: nil
|
29
|
-
}]
|
25
|
+
test_suite: [{ framework: 'none' }]
|
30
26
|
},
|
31
27
|
examples: 0,
|
32
28
|
passing_count: 0,
|
data/lib/learn_test/strategy.rb
CHANGED
data/lib/learn_test/version.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
describe 'Running a RSpec Unit Test' do
|
4
|
-
before
|
3
|
+
describe 'Running a RSpec Unit Test', type: :aruba do
|
4
|
+
before :all do
|
5
5
|
# While it doesn't cause these tests to fail, nasty messages occur (and more)
|
6
6
|
# when either a ~/.netrc entry or file itself doesn't exist. This aims to correct that,
|
7
7
|
# and will only ever be called once.
|
@@ -9,9 +9,23 @@ describe 'Running a RSpec Unit Test' do
|
|
9
9
|
LearnTest::UsernameParser.get_username
|
10
10
|
end
|
11
11
|
|
12
|
+
before :each do
|
13
|
+
copy '%/rspec-unit-spec', 'example'
|
14
|
+
cd 'example'
|
15
|
+
|
16
|
+
git_init
|
17
|
+
git_add
|
18
|
+
git_commit 'Initial Commit'
|
19
|
+
end
|
20
|
+
|
21
|
+
def run(flags = '')
|
22
|
+
run_command_and_stop("#{File.join(LearnTest.bin, 'learn-test')} #{flags}")
|
23
|
+
last_command_started.output
|
24
|
+
end
|
25
|
+
|
12
26
|
context 'a basic rspec unit test' do
|
13
27
|
it 'runs the spec with 0 failures' do
|
14
|
-
output =
|
28
|
+
output = run('--local --test')
|
15
29
|
|
16
30
|
expect(output).to include('3 examples, 0 failures')
|
17
31
|
expect(output).to_not include('1 failures')
|
@@ -20,14 +34,14 @@ describe 'Running a RSpec Unit Test' do
|
|
20
34
|
|
21
35
|
context 'with the --example flag' do
|
22
36
|
it 'runs only the appropriate tests' do
|
23
|
-
output =
|
37
|
+
output = run('--local --test --example multiple')
|
24
38
|
|
25
39
|
expect(output).to include('1 example, 0 failures')
|
26
40
|
expect(output).to_not include('2 examples')
|
27
41
|
end
|
28
42
|
|
29
|
-
|
30
|
-
output =
|
43
|
+
it 'accepts multiple examples' do
|
44
|
+
output = run(' --local --test --example multiple --example accepts')
|
31
45
|
|
32
46
|
expect(output).to include('2 examples, 0 failures')
|
33
47
|
expect(output).to_not include('3 examples')
|