smart_test 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3cd44eb5e122f43dec86a8b4e8a72bf44ac89396
4
+ data.tar.gz: e464ac036a680ea3ff5c57c36eb4fe95cd25ccf4
5
+ SHA512:
6
+ metadata.gz: ec3f0b65ef9f6e4bb277af737cc1884d8384993e915d1a15f5e7992b0f557ad602b2d0fef289f2ad1573e19d205c5eedc7b7c1975233a09df1885987bb80a5f9
7
+ data.tar.gz: 280f610a96202483656ec09062a07d6b459ecd264f27c92dd64121a271acaeab08c5eedd54e7253cd427cc2a100ad3540465bb9c2fe7ddb1a83c65aa16d08f28
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in smart_test.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Yu Wang
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # SmartTest
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'smart_test'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install smart_test
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/smart_test/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/smart_test ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "smart_test"
4
+
5
+ SmartTest::CLI.new.parse! ARGV
@@ -0,0 +1,72 @@
1
+ require "optparse"
2
+ require "smart_test/version"
3
+ require "smart_test/spec_runner"
4
+
5
+ module SmartTest
6
+ class CLI
7
+ def parse!(args)
8
+ options = {}
9
+ opts = OptionParser.new do |opt|
10
+ opt.banner = <<-EOS
11
+ Run test smartly
12
+
13
+ Usage: smart_test -d
14
+ smart_test -s
15
+ smart_test NUM
16
+ EOS
17
+
18
+ opt.on("--version", "Show version") do
19
+ puts VERSION
20
+ exit
21
+ end
22
+
23
+ opt.on("-n", "--number [NUM]", Integer, "Number of files") do |num|
24
+ options[:type] = :mtime
25
+ options[:param] = num || 1
26
+ end
27
+
28
+ opt.on("-s", "--show", "Show test files only") do
29
+ options[:show] = true
30
+ end
31
+
32
+ opt.on("-d", "--diff [STR]", "Diff param") do |str|
33
+ options[:type] = :diff
34
+ options[:param] = str
35
+ end
36
+ end
37
+
38
+ opts.parse! args
39
+
40
+ @runner = SpecRunner.new(Dir.pwd, options)
41
+
42
+ if @runner.files.empty?
43
+ puts "Not test files to run!"
44
+ return
45
+ end
46
+
47
+ if options[:show]
48
+ show_test_files
49
+ else
50
+ run
51
+ end
52
+ rescue NotGitRepoError
53
+ puts "Not a git repository!"
54
+ rescue NoTestFolderError
55
+ puts "No test folder found here. PWD: #{Dir.pwd}"
56
+ end
57
+
58
+ private
59
+
60
+ def run
61
+ puts @runner.cmd
62
+ @runner.run
63
+ end
64
+
65
+ def show_test_files
66
+ puts "Found test files:"
67
+ @runner.files.each do |file|
68
+ puts " #{file}"
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,7 @@
1
+ module SmartTest
2
+ class Diff
3
+ def initialize(content)
4
+ @content = content
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,23 @@
1
+ module SmartTest
2
+ class Filter
3
+ attr_reader :project
4
+
5
+ def initialize(project)
6
+ @project = project
7
+ end
8
+
9
+ def mtime(num)
10
+ project.test_files.map { |file| [file, File.mtime(file)] }.
11
+ sort_by(&:last).
12
+ last(num).
13
+ map &:first
14
+ end
15
+
16
+ def diff(str)
17
+ raise NotGitRepoError unless project.using_git?
18
+ `git diff #{str} --name-only`.split("\n").select { |file| project.test_file? file }
19
+ end
20
+
21
+ private
22
+ end
23
+ end
@@ -0,0 +1,27 @@
1
+ module SmartTest
2
+ class Project
3
+ attr_reader :root, :test_folder
4
+
5
+ def initialize(root, test_folder = "spec")
6
+ @root = root
7
+ @test_folder = test_folder
8
+ raise NoTestFolderError unless File.exists? File.join(root, test_folder)
9
+ end
10
+
11
+ def using_bundle?
12
+ @using_bundle ||= File.exists?(File.join root, "Gemfile")
13
+ end
14
+
15
+ def using_git?
16
+ @using_git ||= File.exists?(File.join root, ".git")
17
+ end
18
+
19
+ def test_files
20
+ Dir.glob "#{test_folder}/**/*_#{test_folder}.rb"
21
+ end
22
+
23
+ def test_file?(file)
24
+ file =~ /\A#{test_folder}\/.*#{test_folder}\.rb\Z/i
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ require "smart_test/project"
2
+ require "smart_test/filter"
3
+
4
+ module SmartTest
5
+ class SpecRunner
6
+ def initialize(root, options={})
7
+ @project = Project.new root
8
+ @filter = Filter.new @project
9
+ @options = {
10
+ type: :mtime,
11
+ param: 1
12
+ }.merge! options
13
+ end
14
+
15
+ def files
16
+ @files ||= @filter.send @options[:type], @options[:param]
17
+ end
18
+
19
+ def run
20
+ system cmd
21
+ end
22
+
23
+ def cmd
24
+ @cmd ||= "bundle exec rspec #{files.join(' ')}"
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module SmartTest
2
+ VERSION = "0.0.1"
3
+ end
data/lib/smart_test.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "smart_test/version"
2
+ require "smart_test/cli"
3
+
4
+ module SmartTest
5
+ NotGitRepoError = Class.new StandardError
6
+ NoTestFolderError = Class.new StandardError
7
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'smart_test/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "smart_test"
8
+ spec.version = SmartTest::VERSION
9
+ spec.authors = ["Yu Wang"]
10
+ spec.email = ["wangyuhere@gmail.com"]
11
+ spec.summary = %q{Run tests smartly.}
12
+ spec.description = %q{Find which tests need to be run based on files last modified at and git diff.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "pry"
25
+ end
File without changes
File without changes
@@ -0,0 +1,18 @@
1
+ require "spec_helper"
2
+
3
+ describe SmartTest::Project do
4
+ let(:root) { "./spec/fixtures/sample_project" }
5
+ let(:subject) { described_class.new root }
6
+
7
+ describe "#using_bundle?" do
8
+ it "checks Gemfile" do
9
+ expect(subject.using_bundle?).to be true
10
+ end
11
+ end
12
+
13
+ describe "#using_git?" do
14
+ it "checks .git" do
15
+ expect(subject.using_git?).to be true
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,2 @@
1
+ require "smart_test"
2
+
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: smart_test
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yu Wang
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Find which tests need to be run based on files last modified at and git
70
+ diff.
71
+ email:
72
+ - wangyuhere@gmail.com
73
+ executables:
74
+ - smart_test
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/smart_test
84
+ - lib/smart_test.rb
85
+ - lib/smart_test/cli.rb
86
+ - lib/smart_test/diff.rb
87
+ - lib/smart_test/filter.rb
88
+ - lib/smart_test/project.rb
89
+ - lib/smart_test/spec_runner.rb
90
+ - lib/smart_test/version.rb
91
+ - smart_test.gemspec
92
+ - spec/fixtures/sample_project/Gemfile
93
+ - spec/lib/smart_test/filter_spec.rb
94
+ - spec/lib/smart_test/project_spec.rb
95
+ - spec/spec_helper.rb
96
+ homepage: ''
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.2.2
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Run tests smartly.
120
+ test_files:
121
+ - spec/fixtures/sample_project/Gemfile
122
+ - spec/lib/smart_test/filter_spec.rb
123
+ - spec/lib/smart_test/project_spec.rb
124
+ - spec/spec_helper.rb