learn-test 3.2.4 → 3.3.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78b850c796efd54f383ea05c625ad8d5f6038d9dcf865b19fc21fd6dcad435fb
4
- data.tar.gz: 88336d0c6c787c1680b22453220a1046741f7ffaf06d97ce090b7fd4d02d4f25
3
+ metadata.gz: 8068b9ca6cd44a8bea55fbe7aff5ec5ee08f811e171021726a6e6364c250a210
4
+ data.tar.gz: 2e6ab893c0f4492cae089cb0c08f836a56486c5d3d3a1140cdf7b4172dc6fbff
5
5
  SHA512:
6
- metadata.gz: ed0abed1a972742bdbd28e05ca20218109f3834267ef560bf884b358e237107f6c294ecbda9248d570fe88c8f4014efb7cdc44bd6779b246acc59d639a35e80c
7
- data.tar.gz: c36adeff838bf630cc640df29e38f7a82de8e65c5aeff5f20a1c107b93d277c4af07ceb2703306d4306a5295237aec822a1f3105bfebfd7a7d64998be5a69700
6
+ metadata.gz: e409f578b4721d75066dc5430d7c725ca47df693487b1cda69149ba4db5d3ca0e7ae33e61e57150ec43c2aaeb1c3e03e5b66ee1d0ddbf281b3c26b8f423aa087
7
+ data.tar.gz: 4a05f33e6601662c068f6d10fb9d225c68f0d60b1edb90dcf195271f4594c426bcf80e99fb987fc49cc69d7f8e723be2fc16f16d4b467f10cd0af103dd043260
@@ -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
@@ -3,7 +3,9 @@
3
3
  source 'https://rubygems.org'
4
4
 
5
5
  group :test do
6
+ gem 'aruba', '~> 1.0.3'
6
7
  gem 'rspec_junit_formatter', '~> 0.4.1'
8
+ gem 'simplecov', require: false
7
9
  end
8
10
 
9
11
  gemspec
@@ -29,4 +29,5 @@ Gem::Specification.new do |spec|
29
29
  spec.add_runtime_dependency "faraday", "~> 1.0"
30
30
  spec.add_runtime_dependency "crack", "~> 0.4.3"
31
31
  spec.add_runtime_dependency "colorize", "~> 0.8.1"
32
+ spec.add_runtime_dependency "zeitwerk", "~> 2.4.0"
32
33
  end
@@ -3,42 +3,21 @@
3
3
  require 'fileutils'
4
4
  require 'oj'
5
5
  require 'colorize'
6
+ require 'zeitwerk'
6
7
 
7
- require_relative 'learn_test/version'
8
- require_relative 'learn_test/netrc_interactor'
9
- require_relative 'learn_test/git_wip'
10
- require_relative 'learn_test/github_interactor'
11
- require_relative 'learn_test/user_id_parser'
12
- require_relative 'learn_test/username_parser'
13
- require_relative 'learn_test/learn_oauth_token_parser'
14
- require_relative 'learn_test/repo_parser'
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
+ )
13
+ loader.setup
30
14
 
31
15
  module LearnTest
32
- module Dependencies
33
- autoload :NodeJS, 'learn_test/dependencies/nodejs'
34
- autoload :PhantomJS, 'learn_test/dependencies/phantomjs'
35
- autoload :Karma, 'learn_test/dependencies/karma'
36
- autoload :Protractor, 'learn_test/dependencies/protractor'
37
- autoload :Java, 'learn_test/dependencies/java'
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'
16
+ def self.root
17
+ File.dirname __dir__
18
+ end
19
+
20
+ def self.bin
21
+ File.join root, 'bin'
43
22
  end
44
23
  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,88 @@
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
+ PREFIX = 'refs/wip/'
14
+
15
+ attr_reader :working_branch, :wip_branch
16
+
17
+ def initialize(base:, message:)
18
+ @base = base
19
+ @message = message
20
+ @success = nil
21
+
22
+ current_branch = @base.current_branch
23
+
24
+ raise NoCommitsError, 'master' if current_branch.nil? # TODO: Swap to `main`?
25
+
26
+ @tmp = Tempfile.new(TEMPFILE)
27
+ @working_branch = Branch.new(base: @base, name: current_branch)
28
+ @wip_branch = Branch.new(base: @base, name: "#{PREFIX}#{current_branch}")
29
+ end
30
+
31
+ def process!
32
+ if @wip_branch.last_revision
33
+ merge = @base.merge_base(@wip_branch.last_revision, @working_branch.last_revision)
34
+
35
+ @wip_branch.parent = if merge == @working_branch.last_revision
36
+ @wip_branch.last_revision
37
+ else
38
+ @working_branch.last_revision
39
+ end
40
+ else
41
+ @wip_branch.parent = @working_branch.last_revision
42
+ end
43
+
44
+ new_tree = build_new_tree(@wip_branch.parent)
45
+ @base.diff(new_tree, @wip_branch.parent)
46
+
47
+ # tree_diff = @base.diff(new_tree, @wip_branch.parent)
48
+ # raise NoChangesError, @wip_branch if tree_diff.count.zero?
49
+
50
+ commit = @base.commit_tree(new_tree, parent: @wip_branch.parent)
51
+
52
+ @base.lib.send(:command, 'update-ref', ['-m', @message, @wip_branch, commit.objectish])
53
+
54
+ @success = true
55
+ ensure
56
+ cleanup
57
+ end
58
+
59
+ def success?
60
+ @success
61
+ end
62
+
63
+ private
64
+
65
+ def build_new_tree(wip_parent)
66
+ index = "#{@tmp.path}-index"
67
+
68
+ FileUtils.rm(index, force: true)
69
+ FileUtils.cp("#{@base.dir.path}/.git/index", index)
70
+
71
+ @base.read_tree(wip_parent)
72
+ @base.lib.send(:command, 'add', ['--update', '--', '.'])
73
+ @base.add(all: true)
74
+
75
+ new_tree_obj = @base.write_tree
76
+
77
+ FileUtils.rm(index, force: true)
78
+
79
+ new_tree_obj
80
+ end
81
+
82
+ def cleanup
83
+ FileUtils.rm("#{@tmp.path}-*", force: true)
84
+ end
85
+ end
86
+ end
87
+ end
88
+ 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(NoCommitsError::REGEX) ? NoCommitsError.new(@name) : e
21
+ end
22
+
23
+ raise unless e.message.match(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
@@ -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
- if client.post_results(endpoint, results)
54
- if !LearnTest::GitWip.run! && @debug
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.load(File.read("#{FileUtils.pwd}/.learn"))
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']
@@ -63,7 +63,7 @@ module LearnTest
63
63
  if npm_install
64
64
  system(command)
65
65
  else
66
- Open3.popen3(command) do |stdin, stdout, stderr, wait_thr|
66
+ Open3.popen3(command) do |_, stdout, stderr, wait_thr|
67
67
  while out = stdout.gets do
68
68
  puts out
69
69
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LearnTest
4
- VERSION = '3.2.4'
4
+ VERSION = '3.3.0.pre.1'
5
5
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- describe 'Running a RSpec Unit Test' do
4
- before(:all) do
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,22 @@ 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
+ run_command_and_stop 'git init'
16
+ run_command_and_stop 'git add .'
17
+ run_command_and_stop 'git commit -m "Initial Commit"'
18
+ end
19
+
20
+ def run(flags = '')
21
+ run_command_and_stop("#{File.join(LearnTest.bin, 'learn-test')} #{flags}")
22
+ last_command_started.output
23
+ end
24
+
12
25
  context 'a basic rspec unit test' do
13
26
  it 'runs the spec with 0 failures' do
14
- output = `cd ./spec/fixtures/rspec-unit-spec && ./../../../bin/learn-test --local --test`
27
+ output = run('--local --test')
15
28
 
16
29
  expect(output).to include('3 examples, 0 failures')
17
30
  expect(output).to_not include('1 failures')
@@ -20,14 +33,14 @@ describe 'Running a RSpec Unit Test' do
20
33
 
21
34
  context 'with the --example flag' do
22
35
  it 'runs only the appropriate tests' do
23
- output = `cd ./spec/fixtures/rspec-unit-spec && ./../../../bin/learn-test --local --test --example multiple`
36
+ output = run('--local --test --example multiple')
24
37
 
25
38
  expect(output).to include('1 example, 0 failures')
26
39
  expect(output).to_not include('2 examples')
27
40
  end
28
41
 
29
- it 'accepts multiple examples' do
30
- output = `cd ./spec/fixtures/rspec-unit-spec && ./../../../bin/learn-test --local --test --example multiple --example accepts`
42
+ it 'accepts multiple examples' do
43
+ output = run(' --local --test --example multiple --example accepts')
31
44
 
32
45
  expect(output).to include('2 examples, 0 failures')
33
46
  expect(output).to_not include('3 examples')
@@ -0,0 +1 @@
1
+ {"version":"3.9.2","examples":[{"id":"./spec/dog_spec.rb[1:1]","description":"runs the spec spec correctly","full_description":"Dog runs the spec spec correctly","status":"passed","file_path":"./spec/dog_spec.rb","line_number":6,"run_time":0.000423,"pending_message":null},{"id":"./spec/dog_spec.rb[1:2]","description":"has multiple specs","full_description":"Dog has multiple specs","status":"passed","file_path":"./spec/dog_spec.rb","line_number":10,"run_time":4.8e-05,"pending_message":null},{"id":"./spec/dog_spec.rb[1:3]","description":"accepts more than one example","full_description":"Dog accepts more than one example","status":"passed","file_path":"./spec/dog_spec.rb","line_number":14,"run_time":3.6e-05,"pending_message":null}],"summary":{"duration":0.001252,"example_count":3,"failure_count":0,"pending_count":0,"errors_outside_of_examples_count":0},"summary_line":"3 examples, 0 failures"}
@@ -1,95 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # This file was generated by the `rspec --init` command. Conventionally, all
4
- # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
- # The generated `.rspec` file contains `--require spec_helper` which will cause
6
- # this file to always be loaded, without a need to explicitly require it in any
7
- # files.
8
- #
9
- # Given that it is always loaded, you are encouraged to keep this file as
10
- # light-weight as possible. Requiring heavyweight dependencies from this file
11
- # will add to the boot time of your test suite on EVERY test run, even for an
12
- # individual file that may not need all of that loaded. Instead, consider making
13
- # a separate helper file that requires the additional dependencies and performs
14
- # the additional setup, and require it from the spec files that actually need
15
- # it.
16
- #
17
- # The `.rspec` file also contains a few flags that are not defaults but that
18
- # users commonly want.
19
- #
20
- # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
21
3
  require_relative '../lib/dog'
22
4
 
23
5
  RSpec.configure do |config|
24
- # rspec-expectations config goes here. You can use an alternate
25
- # assertion/expectation library such as wrong or the stdlib/minitest
26
- # assertions if you prefer.
27
6
  config.expect_with :rspec do |expectations|
28
- # This option will default to `true` in RSpec 4. It makes the `description`
29
- # and `failure_message` of custom matchers include text for helper methods
30
- # defined using `chain`, e.g.:
31
- # be_bigger_than(2).and_smaller_than(4).description
32
- # # => "be bigger than 2 and smaller than 4"
33
- # ...rather than:
34
- # # => "be bigger than 2"
35
7
  expectations.include_chain_clauses_in_custom_matcher_descriptions = true
36
8
  end
37
9
 
38
- # rspec-mocks config goes here. You can use an alternate test double
39
- # library (such as bogus or mocha) by changing the `mock_with` option here.
40
10
  config.mock_with :rspec do |mocks|
41
- # Prevents you from mocking or stubbing a method that does not exist on
42
- # a real object. This is generally recommended, and will default to
43
- # `true` in RSpec 4.
44
11
  mocks.verify_partial_doubles = true
45
12
  end
46
-
47
- # The settings below are suggested to provide a good initial experience
48
- # with RSpec, but feel free to customize to your heart's content.
49
- =begin
50
- # These two settings work together to allow you to limit a spec run
51
- # to individual examples or groups you care about by tagging them with
52
- # `:focus` metadata. When nothing is tagged with `:focus`, all examples
53
- # get run.
54
- config.filter_run :focus
55
- config.run_all_when_everything_filtered = true
56
-
57
- # Limits the available syntax to the non-monkey patched syntax that is
58
- # recommended. For more details, see:
59
- # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
60
- # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
61
- # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
62
- config.disable_monkey_patching!
63
-
64
- # This setting enables warnings. It's recommended, but in some cases may
65
- # be too noisy due to issues in dependencies.
66
- config.warnings = true
67
-
68
- # Many RSpec users commonly either run the entire suite or an individual
69
- # file, and it's useful to allow more verbose output when running an
70
- # individual spec file.
71
- if config.files_to_run.one?
72
- # Use the documentation formatter for detailed output,
73
- # unless a formatter has already been configured
74
- # (e.g. via a command-line flag).
75
- config.default_formatter = 'doc'
76
- end
77
-
78
- # Print the 10 slowest examples and example groups at the
79
- # end of the spec run, to help surface which specs are running
80
- # particularly slow.
81
- config.profile_examples = 10
82
-
83
- # Run specs in random order to surface order dependencies. If you find an
84
- # order dependency and want to debug it, you can fix the order by providing
85
- # the seed, which is printed after each run.
86
- # --seed 1234
87
- config.order = :random
88
-
89
- # Seed global randomization in this process using the `--seed` CLI option.
90
- # Setting this allows you to use `--seed` to deterministically reproduce
91
- # test failures related to randomization by passing the same `--seed` value
92
- # as the one that triggered the failure.
93
- Kernel.srand config.seed
94
- =end
95
13
  end