last_hit 0.1.11 → 0.1.12

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
  SHA1:
3
- metadata.gz: 4ca55a8ac1827aeceb584041a728b3032d9cbe2e
4
- data.tar.gz: 61f9de1b8b5419b644b4785a6cc2107401fc5d02
3
+ metadata.gz: fec9a8651a90d144637c9c7e9dbe53dd9b4466e3
4
+ data.tar.gz: df1afbcd62db73a48163686141df6cba08184b88
5
5
  SHA512:
6
- metadata.gz: f9f01225c1a23f0f4ece3e0c96fb159f0644118bb185f7c7bc5f7ef38d7cde71c0f6dc12a6f62f3dcaf1f614a1b5331f46485db0b4ed94ef06047c4287d41da6
7
- data.tar.gz: fdd805e580e3ef64e8033d846ac448db15d7aa0db3dd24ee35aebde723c03bc9326b6e3a0b6f98f3ad809f237398c82d974d21016476eff3c7dd0ca3230df1ab
6
+ metadata.gz: 2f940eae70c68c66a661a17e064ace5f445fdfed06e7819793e1a62d900a346a780a6fdc2214b2063155ec91e3d2a75c58181ed82a8d239784f9115afd2072b5
7
+ data.tar.gz: 5f9ccb5c34cde694c1a560df469b00012fa5bfea36f98a73a5a08a92237612888806c8713293178a2e748e5786270cb8220037808ef1d9cd14d28a2d5a33a17d
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 TODO: Write your name
1
+ Copyright (c) 2014 Duc Le
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # LastHit
2
2
 
3
3
  You finish your features, push code to test servers and they fails after centuries wating? This gem will reduce your waiting time by running only relevant tests in your current branch before pushing. Then you can fix failed tests right before pushing them to the test server.
4
+ Currently, this gem works with GIT and rspec. In the future, the gem will support other Version Controls and other test frameworks.
4
5
 
5
6
  ## Installation
6
7
 
@@ -54,8 +55,6 @@ last_hit all_tests -b develop
54
55
  #=> 3 examples, 0 failures
55
56
  ```
56
57
 
57
- `develop` is your base branch
58
-
59
58
  ## Contributing
60
59
 
61
60
  1. Fork it ( https://github.com/[my-github-username]/last_hit/fork )
@@ -0,0 +1,35 @@
1
+ require 'last_hit/file_filter'
2
+
3
+ class LastHit
4
+ module Checker
5
+ def self.check(files)
6
+ test_files = FileFilter::Spec.filter(files)
7
+ ruby_files = FileFilter::Ruby.filter(files)
8
+ results = filter(ruby_files, test_files)
9
+ if results.length > 0
10
+ $stdout.puts 'There are some changed files without tests'
11
+ results.each { |r| $stdout.puts r }
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def self.filter(ruby_files, test_files)
18
+ ruby_files.select do |file|
19
+ not_contain?(file, test_files)
20
+ end
21
+ end
22
+
23
+ def self.not_contain?(file, test_files)
24
+ test_name = get_test_name(file)
25
+ test_files.each do |test_file|
26
+ return false if test_file.include?(test_name)
27
+ end
28
+ true
29
+ end
30
+
31
+ def self.get_test_name(file)
32
+ file.gsub('.rb', '_spec.rb').split('/').last(2).join('/')
33
+ end
34
+ end
35
+ end
data/lib/last_hit/cli.rb CHANGED
@@ -40,5 +40,13 @@ test_command: 'bundle exec rspec'
40
40
  Cli.load_config(options[:config])
41
41
  LastHit.new.all_tests(options[:base])
42
42
  end
43
+
44
+ desc 'check', 'Check if any tests missing for modified files'
45
+ method_option :base, aliases: '-b', desc: 'Base branch for compare', type: :string
46
+ method_option :config, aliases: '-C', desc: 'Path to the config file', type: :string, default: CONFIG_PATH
47
+ def check
48
+ Cli.load_config(options[:config])
49
+ LastHit.new.check(options[:base])
50
+ end
43
51
  end
44
52
  end
@@ -0,0 +1,22 @@
1
+ class LastHit
2
+ module FileFilter
3
+ class Ruby
4
+ RUBY_REGEX = /\A.+_spec.rb\z/
5
+
6
+ class << self
7
+ def filter(files)
8
+ files.select { |file| match?(file) }
9
+ end
10
+
11
+ def match?(file)
12
+ return false if Spec.match?(file)
13
+ ['app', 'lib'].each do |dr|
14
+ regex = /#{dr}\/.+\.rb/
15
+ return true if file =~ regex
16
+ end
17
+ false
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -5,7 +5,11 @@ class LastHit
5
5
 
6
6
  class << self
7
7
  def filter(files)
8
- files.select { |file| file =~ SPEC_REGEX }
8
+ files.select { |file| match?(file) }
9
+ end
10
+
11
+ def match?(file)
12
+ file =~ SPEC_REGEX
9
13
  end
10
14
  end
11
15
  end
@@ -1,4 +1,5 @@
1
1
  require 'last_hit/file_filter/spec'
2
+ require 'last_hit/file_filter/ruby'
2
3
 
3
4
  class LastHit
4
5
  module FileFilter
@@ -1,3 +1,3 @@
1
1
  class LastHit
2
- VERSION = "0.1.11"
2
+ VERSION = "0.1.12"
3
3
  end
data/lib/last_hit.rb CHANGED
@@ -5,6 +5,7 @@ require 'last_hit/rc_adapter'
5
5
  require 'last_hit/file_filter'
6
6
 
7
7
  require 'last_hit/test_handler'
8
+ require 'last_hit/checker'
8
9
 
9
10
  require 'last_hit/cli'
10
11
 
@@ -20,10 +21,20 @@ class LastHit
20
21
  process(files)
21
22
  end
22
23
 
24
+ def check(base_branch)
25
+ base_branch = Configure.base_branch if base_branch.nil?
26
+ files = RcAdapter::Git.current_branch_files(base_branch)
27
+ check(files)
28
+ end
29
+
23
30
  private
24
31
 
25
32
  def process(files)
26
33
  tests = FileFilter::Spec.filter(files)
27
34
  TestHandler.run(tests)
28
35
  end
36
+
37
+ def check(files)
38
+ Checker.check(files)
39
+ end
29
40
  end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe LastHit::Checker do
4
+ describe '.filter' do
5
+ let(:checker) { LastHit::Checker }
6
+ let(:ruby_files) { [
7
+ 'app/models/user.rb',
8
+ 'app/models/post.rb',
9
+ 'lib/signin.rb',
10
+ 'lib/publish.rb'
11
+ ] }
12
+ let(:test_files) { [
13
+ 'spec/models/user_spec.rb',
14
+ 'spec/lib/signin_spec.rb'
15
+ ] }
16
+ let(:no_test_files) { [
17
+ 'app/models/post.rb',
18
+ 'lib/publish.rb'
19
+ ] }
20
+
21
+ it 'return ruby files that do not have tests' do
22
+ results = checker.send(:filter, ruby_files, test_files)
23
+ expect(results).to match_array(no_test_files)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe LastHit::FileFilter::Ruby do
4
+ describe '.filter' do
5
+ let(:files) { [
6
+ 'app/models/user.rb',
7
+ 'service/author.rb',
8
+ 'lib/post.rb',
9
+ 'spec/service/user_spec.rb'
10
+ ] }
11
+ let(:ruby_files) { [
12
+ 'app/models/user.rb',
13
+ 'lib/post.rb'
14
+ ] }
15
+
16
+ it 'return files with extension is spec' do
17
+ expect(LastHit::FileFilter::Ruby.filter(files)).to match_array(ruby_files)
18
+ end
19
+ end
20
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: last_hit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Duc Le
@@ -84,16 +84,20 @@ files:
84
84
  - bin/setup
85
85
  - last_hit.gemspec
86
86
  - lib/last_hit.rb
87
+ - lib/last_hit/checker.rb
87
88
  - lib/last_hit/cli.rb
88
89
  - lib/last_hit/configure.rb
89
90
  - lib/last_hit/file_filter.rb
91
+ - lib/last_hit/file_filter/ruby.rb
90
92
  - lib/last_hit/file_filter/spec.rb
91
93
  - lib/last_hit/rc_adapter.rb
92
94
  - lib/last_hit/rc_adapter/git.rb
93
95
  - lib/last_hit/test_handler.rb
94
96
  - lib/last_hit/version.rb
95
- - spec/file_filter/spec_spec.rb
96
- - spec/rc_adapter/git_spec.rb
97
+ - spec/last_hit/checker_spec.rb
98
+ - spec/last_hit/file_filter/ruby_spec.rb
99
+ - spec/last_hit/file_filter/spec_spec.rb
100
+ - spec/last_hit/rc_adapter/git_spec.rb
97
101
  - spec/spec_helper.rb
98
102
  homepage: https://github.com/lmduc/last_hit
99
103
  licenses:
@@ -121,6 +125,8 @@ specification_version: 4
121
125
  summary: Help you to reduce the time waiting for the test servers by running some
122
126
  relevant tests before pushing
123
127
  test_files:
124
- - spec/file_filter/spec_spec.rb
125
- - spec/rc_adapter/git_spec.rb
128
+ - spec/last_hit/checker_spec.rb
129
+ - spec/last_hit/file_filter/ruby_spec.rb
130
+ - spec/last_hit/file_filter/spec_spec.rb
131
+ - spec/last_hit/rc_adapter/git_spec.rb
126
132
  - spec/spec_helper.rb