cobratest 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2ff70bef30e32aeb2861e2ed2418efd28c8fd884
4
- data.tar.gz: dfaf1f67eb5ad013669c2be46ea42ae139b06957
3
+ metadata.gz: 98315772b10093ce2a85ec8ba59f2574202e2aab
4
+ data.tar.gz: 1fd03ebe1f3e34155f7561d9d92ceefba7098e2e
5
5
  SHA512:
6
- metadata.gz: 984c0b3d3c4c794e22152532f508850222b58c2781c784b8a3075a604f66eac0882792ade3cb538f030b3089ea1700dd503bd2b9c794699d124a99c14f13aa61
7
- data.tar.gz: 76227aec01e1ef88b6a70024051051bd12cf183601227aa310d8488ca74f8fa94f99ab2a803dad9c02d3276b0f399cfe32b0478e210d360f3cb45b07fc183073
6
+ metadata.gz: 8c9c628f0dd3260bf5550b154b8912aa495dbf3beb6167edd98cfe1f1d1d64a78afec835fdee4a5719137dbcebe95d3ee4b0482a36d6df77bf50295f04e5bab2
7
+ data.tar.gz: 6d4161308e0ed7278ae531709d8c91edb21d9d46d28c9fe11aa3d44102b58093f953689cf08ebf912736f282d07946bb748a0a45cf931930f2cf59e10ca37a5b
data/README.md CHANGED
@@ -24,57 +24,63 @@ Or install it yourself as:
24
24
 
25
25
  Options are...
26
26
  -h, -H, --help Display this help message.
27
-
28
27
  -r, --results DEFAULT Display the directories of the components in need of running tests
28
+ -t, --test-runner RUNNER Choose a test runner
29
29
  -v, --verbose Verbose output of all parts of the calculation
30
+ -s, --since BRANCH Specify BRANCH target to calculate against
30
31
 
31
32
  ## Example
32
33
 
33
34
  There are sample #cbra folder structures in `spec/examples`. Here is an example run when changing a file in component `C`:
34
35
 
35
- ± |master ✗| → bin/cobratest ~/workspace/cobratest/spec/examples/letters/A
36
- /Users/stephan/workspace/cobratest/spec/examples/letters/B/test.sh
37
- /Users/stephan/workspace/cobratest/spec/examples/letters/C/test.sh
38
- /Users/stephan/workspace/cobratest/spec/examples/letters/A/test.sh
36
+ $ bin/cobratest ./cobratest/spec/examples/letters/A
37
+ ./cobratest/spec/examples/letters/B/test.sh
38
+ ./cobratest/spec/examples/letters/C/test.sh
39
+ ./cobratest/spec/examples/letters/A/test.sh
39
40
 
40
41
  This output can be used to run the necessary tests like so:
41
42
 
42
- bin/cobratest ~/workspace/cobratest/spec/examples/letters/A | xargs -n1 /bin/bash
43
+ bin/cobratest ./cobratest/spec/examples/letters/A | xargs -n1 /bin/bash
44
+
45
+ You can choose a different test runner like so:
46
+
47
+ $ bin/cobratest --test-runner 'myrunner --option 1' ./cobratest/spec/examples/letters/A
48
+ ./cobratest/spec/examples/letters/B/myrunner --option 1
49
+ ./cobratest/spec/examples/letters/C/myrunner --option 1
50
+ ./cobratest/spec/examples/letters/A/myrunner --option 1
43
51
 
44
52
  In verbose mode one can check the correctness of cobratest's calculation:
45
53
 
46
- ± |master ✗| → bin/cobratest -v ~/workspace/cobra/cobratest/spec/examples/letters/A
54
+ $ bin/cobratest -v ./cobra/cobratest/spec/examples/letters/A
47
55
  All components
48
- B /Users/stephan/workspace/cobra/cobratest/spec/examples/letters/B
49
- C /Users/stephan/workspace/cobra/cobratest/spec/examples/letters/C
50
- D /Users/stephan/workspace/cobra/cobratest/spec/examples/letters/D
51
- E1 /Users/stephan/workspace/cobra/cobratest/spec/examples/letters/E1
52
- E2 /Users/stephan/workspace/cobra/cobratest/spec/examples/letters/E2
53
- F /Users/stephan/workspace/cobra/cobratest/spec/examples/letters/F
54
- A /Users/stephan/workspace/cobra/cobratest/spec/examples/letters/A
56
+ B ./cobra/cobratest/spec/examples/letters/B
57
+ C ./cobra/cobratest/spec/examples/letters/C
58
+ D ./cobra/cobratest/spec/examples/letters/D
59
+ E1 ./cobra/cobratest/spec/examples/letters/E1
60
+ E2 ./cobra/cobratest/spec/examples/letters/E2
61
+ F ./cobra/cobratest/spec/examples/letters/F
62
+ A ./cobra/cobratest/spec/examples/letters/A
55
63
 
56
64
  Changes since last commit
57
- /Users/stephan/workspace/cobra/cobratest/README.md
58
- /Users/stephan/workspace/cobra/cobratest/spec/examples/letters/C/Gemfile
65
+ ./cobra/cobratest/README.md
66
+ ./cobra/cobratest/spec/examples/letters/C/Gemfile
59
67
 
60
68
  Directly affected components
61
- C /Users/stephan/workspace/cobra/cobratest/spec/examples/letters/C
69
+ C ./cobra/cobratest/spec/examples/letters/C
62
70
 
63
71
  Transitively affected components
64
- B /Users/stephan/workspace/cobra/cobratest/spec/examples/letters/B
65
- C /Users/stephan/workspace/cobra/cobratest/spec/examples/letters/C
66
- A /Users/stephan/workspace/cobra/cobratest/spec/examples/letters/A
72
+ B ./cobra/cobratest/spec/examples/letters/B
73
+ C ./cobra/cobratest/spec/examples/letters/C
74
+ A ./cobra/cobratest/spec/examples/letters/A
67
75
 
68
76
  Test scripts to run
69
- /Users/stephan/workspace/cobra/cobratest/spec/examples/letters/B/test.sh
70
- /Users/stephan/workspace/cobra/cobratest/spec/examples/letters/C/test.sh
71
- /Users/stephan/workspace/cobra/cobratest/spec/examples/letters/A/test.sh
77
+ ./cobra/cobratest/spec/examples/letters/B/test.sh
78
+ ./cobra/cobratest/spec/examples/letters/C/test.sh
79
+ ./cobra/cobratest/spec/examples/letters/A/test.sh
72
80
 
73
81
  ## Todos
74
- * make algorithm work for structures where a gem is in a sub folder of another gem (only the inner gem should be diectly affected)
82
+ * make algorithm work for structures where a gem is in a sub folder of another gem (only the inner gem should be directly affected)
75
83
  * allow for other test runners to be specified
76
- * optionally check for changes since origin/master
77
- * optionally allow branch to compare against to be specified
78
84
 
79
85
  ## License
80
86
 
data/bin/cobratest CHANGED
@@ -1,47 +1,49 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
3
  require_relative "../lib/cobratest"
4
+ require "optparse"
4
5
 
5
- def help_text
6
- <<-USAGE
7
- cobratest [OPTION] [application path]
6
+ options = {
7
+ display: "results",
8
+ path: nil
9
+ }
8
10
 
9
- Test runner employing the structure of Component-based Ruby/Rails apps to optimize what needs to run.
11
+ instructions = OptionParser.new do |opts|
12
+ opts.banner = "cobratest [OPTION] [application path]\n\n"
13
+ opts.separator "Test runner employing the structure of Component-based Ruby/Rails apps to optimize what needs to run.\n\n"
14
+ opts.separator "Options are...\n"
10
15
 
11
- Options are...
12
- -h, -H, --help Display this help message.
16
+ opts.on("-h", "-H", "--help", "Display this help message.") do
17
+ puts opts
18
+ exit
19
+ end
13
20
 
14
- -r, --results DEFAULT Display the directories of the components in need of running tests
15
- -v, --verbose Verbose output of all parts of the calculation
16
- USAGE
17
- end
21
+ opts.on("-r", "--results", "DEFAULT Display the directories of the components in need of running tests") do
22
+ options[:display] = "results"
23
+ end
18
24
 
19
- option = "-r"
20
- path = nil
21
-
22
- case ARGV.size
23
- when 0
24
- when 1
25
- if ARGV[0].start_with? "-"
26
- option = ARGV[0]
27
- else
28
- path = ARGV[0]
29
- end
30
- when 2
31
- option = ARGV[0]
32
- path = ARGV[1]
33
- else
34
- puts "Incorrect invocation. Please see help:\n\n"
35
- puts help_text
36
- exit 1
25
+ opts.on("-t", "--test-runner RUNNER", "Choose a test runner") do |runner|
26
+ options[:runner] = runner
27
+ end
28
+
29
+ opts.on("-v", "--verbose", "Verbose output of all parts of the calculation") do
30
+ options[:display] = "verbose"
31
+ end
32
+
33
+ opts.on("-s", "--since BRANCH", "Specify BRANCH target to calculate against") do |branch|
34
+ options[:since] = branch
35
+ end
37
36
  end
38
37
 
39
- if option
40
- if %w(--help -h -H).include? option
41
- puts help_text
42
- elsif %w(-r --results).include? option
43
- Cbratest::Runner.new(false).run path
44
- elsif %w(-v --verbose).include? option
45
- Cbratest::Runner.new(true).run path
38
+ begin
39
+ instructions.parse!
40
+ if ARGV.size >= 1
41
+ Cbratest::Runner.new(options).run ARGV[0]
42
+ else
43
+ raise OptionParser::MissingArgument.new("Must specify the application path")
46
44
  end
45
+ rescue OptionParser::InvalidOption, OptionParser::MissingArgument => error
46
+ puts error
47
+ puts instructions
48
+ exit
47
49
  end
data/cobratest.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'cobratest'
7
- spec.version = '0.1.2'
7
+ spec.version = '0.1.3'
8
8
  spec.authors = ['Stephan Hagemann']
9
9
  spec.email = ['stephan.hagemann@gmail.com']
10
10
  spec.summary = %q{A test selector for your component-based Rails application}
@@ -31,6 +31,6 @@ Gem::Specification.new do |spec|
31
31
 
32
32
  spec.add_dependency 'bundler', '~> 1.13'
33
33
 
34
- spec.add_development_dependency 'rake'
34
+ spec.add_development_dependency 'rake', '~> 12.0'
35
35
  spec.add_development_dependency 'rspec', '~> 3.5'
36
36
  end
data/lib/cobratest.rb CHANGED
@@ -8,8 +8,10 @@ module Cbratest
8
8
  require_relative "cobratest/tests_to_run_selector"
9
9
 
10
10
  class Runner
11
- def initialize(verbose_output)
12
- @verbose_output = verbose_output
11
+ def initialize(opts)
12
+ @verbose_output = opts[:display] == "verbose"
13
+ @since = opts[:since] || "current branch"
14
+ @test_runner = opts[:runner] || "test.sh"
13
15
  end
14
16
 
15
17
  def run(root_path)
@@ -21,13 +23,15 @@ module Cbratest
21
23
  components = cobra_deps << app.to_s
22
24
  outputs component_out(components.to_a)
23
25
 
24
-
25
- outputs "\nChanges since last commit"
26
+ outputs "\nChanges since last commit on #{@since}"
26
27
  root_dir = `cd "#{path}" && git rev-parse --show-toplevel`.chomp
27
- changes = `cd "#{root_dir}" && git status -s -u`.split("\n").map { |file| File.join(root_dir, file.sub(/^.../, "")) }
28
+ if @since != "current branch"
29
+ changes = `cd "#{root_dir}" && git diff --name-only #{@since}`.split("\n").map { |file| File.join(root_dir, file) }
30
+ else
31
+ changes = `cd "#{root_dir}" && git status -s -u`.split("\n").map { |file| File.join(root_dir, file.sub(/^.../, "")) }
32
+ end
28
33
  outputs changes
29
34
 
30
-
31
35
  outputs "\nDirectly affected components"
32
36
  affected = AffectedComponentFinder.new.find(components, changes)
33
37
  outputs affected_out(affected)
@@ -37,7 +41,7 @@ module Cbratest
37
41
  outputs affected_out(all_affected)
38
42
 
39
43
  outputs "\nTest scripts to run"
40
- outputs all_in_need_of_running = TestsToRunSelector.new.list(all_affected), true
44
+ outputs all_in_need_of_running = TestsToRunSelector.new(@test_runner).list(all_affected), true
41
45
  end
42
46
 
43
47
  private
@@ -14,13 +14,6 @@ module Cbratest
14
14
  {name: name, options: {path: @root_path}}
15
15
  end
16
16
 
17
- def cobra_dependencies
18
- dirdep = direct_dependencies
19
- transitive_cobra_dependencies.select do |dep|
20
- dirdep.include?(dep[:name]) || dep[:options][:direct]
21
- end
22
- end
23
-
24
17
  def transitive_cobra_dependencies
25
18
  gem_dependencies.inject([]) do |memo, dep|
26
19
  if !!dep[:options][:path]
@@ -34,24 +27,11 @@ module Cbratest
34
27
 
35
28
  private
36
29
 
37
- def raw_gemspec
38
- path = File.expand_path(File.join(@root_path, "#{underscore(name)}.gemspec"))
39
- File.exist?(path) ? File.read(path) : ""
40
- end
41
-
42
- def direct_dependencies
43
- raw_gemspec.split("\n").inject([]) do |memo, line|
44
- match = line.match(/add_(?:development_)?dependency\s+["']([^'"]+)["']/)
45
- memo << match[1] if match
46
- memo
47
- end
48
- end
49
-
50
30
  def gem_dependencies
51
31
  gemfile_path = File.join(@root_path, "Gemfile")
52
32
  lockfile_path = File.join(@root_path, "Gemfile.lock")
53
33
  ::Bundler::Definition.build(gemfile_path, lockfile_path, nil).dependencies.inject([]) do |memo, dep|
54
- path = dep.source.path.to_s if dep.source && dep.source.is_a_path?
34
+ path = dep.source.path.to_s if dep.source && dep.source.path?
55
35
  if path == "."
56
36
  path = nil
57
37
  elsif path && !path.match(/#{dep.name}/)
@@ -61,13 +41,5 @@ module Cbratest
61
41
  memo
62
42
  end
63
43
  end
64
-
65
- def underscore(string)
66
- string.gsub(/::/, '/').
67
- gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
68
- gsub(/([a-z\d])([A-Z])/, '\1_\2').
69
- tr("-", "_").
70
- downcase
71
- end
72
44
  end
73
45
  end
@@ -1,10 +1,16 @@
1
1
  module Cbratest
2
2
  class TestsToRunSelector
3
+ attr_reader :suffix
4
+
5
+ def initialize(suffix = 'test.sh')
6
+ @suffix = suffix
7
+ end
8
+
3
9
  def list(affected)
4
10
  affected.keys.inject([]) do |memo, key|
5
- memo << File.join(key[:options][:path], "test.sh") if affected[key]
11
+ memo << File.join(key[:options][:path], suffix) if affected[key]
6
12
  memo
7
13
  end
8
14
  end
9
15
  end
10
- end
16
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cobratest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephan Hagemann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-06 00:00:00.000000000 Z
11
+ date: 2018-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '12.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '12.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -94,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
94
  version: '0'
95
95
  requirements: []
96
96
  rubyforge_project:
97
- rubygems_version: 2.6.10
97
+ rubygems_version: 2.6.13
98
98
  signing_key:
99
99
  specification_version: 4
100
100
  summary: A test selector for your component-based Rails application