quick-rspec 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +53 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/quick-rspec.rb +93 -0
- data/lib/tasks/quick_rspec.rake +40 -0
- data/quick-rspec.gemspec +34 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1c59dfc88645a56cb8df0beefc55100f90b71dac
|
4
|
+
data.tar.gz: a01971a8adc9b7a409eb42b3ba7948167f3ea1a7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1f760909519c88a15f62e08af92a56219847d8b90120dba755283477b457b2b952edf22ba4570b235f367bd942e42b5bcce6bb810cba0791fa79036d1bcfa96f
|
7
|
+
data.tar.gz: dcd4885654a90200621da3458309ebc5d580f9c875cb2e1b1663ca1a1729b0a148f9b8a0f98aac0c67fe94689ab25ec306bb5ed129ad5ccaf375e8bce0823008
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.3.1
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Dmitry Silchenko
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# quick-rspec
|
2
|
+
|
3
|
+
`quick-rspec` runs only specs related to changed files
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'quick-rspec', require: false, group: [:test, :development]
|
11
|
+
```
|
12
|
+
|
13
|
+
Add this line at the end of your `config/application.rb`
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
require 'quick-rspec'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Run whole test scope to collect statistics (to detect what everyone test checks):
|
26
|
+
|
27
|
+
```
|
28
|
+
rspec
|
29
|
+
```
|
30
|
+
|
31
|
+
Then when you made changes (when you have not committed files) run
|
32
|
+
|
33
|
+
```
|
34
|
+
rake quick_rspec
|
35
|
+
```
|
36
|
+
|
37
|
+
to run limited scope of tests.
|
38
|
+
|
39
|
+
```
|
40
|
+
rake quick_rspec DRY=yes
|
41
|
+
```
|
42
|
+
|
43
|
+
will show you information about specs that should be run to check your changes.
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/desofto/quick-rspec
|
48
|
+
|
49
|
+
|
50
|
+
## License
|
51
|
+
|
52
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
53
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "pq_unlogged"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/quick-rspec.rb
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'coverage'
|
4
|
+
|
5
|
+
class QuickRspec < Rails::Railtie
|
6
|
+
rake_tasks do
|
7
|
+
Dir[File.join(File.dirname(__FILE__),'tasks/*.rake')].each { |f| load f }
|
8
|
+
end
|
9
|
+
|
10
|
+
class << self
|
11
|
+
@@coverage = {}
|
12
|
+
@@last_cover = {}
|
13
|
+
|
14
|
+
def start
|
15
|
+
Coverage.start
|
16
|
+
end
|
17
|
+
|
18
|
+
def collect_stats(example)
|
19
|
+
spec = "#{example.metadata[:rerun_file_path]}[#{example.metadata[:scoped_id]}]"
|
20
|
+
root = Rails.root.to_s
|
21
|
+
result = {}
|
22
|
+
cover = Coverage.peek_result
|
23
|
+
cover.each do |path, coverage|
|
24
|
+
next unless path =~ %r{^#{Regexp.escape(root)}}i
|
25
|
+
next if path =~ %r{^#{Regexp.escape(root)}\/spec\/}i
|
26
|
+
last_cover = @@last_cover[path]
|
27
|
+
path = QuickRspec.relevant_path(path)
|
28
|
+
coverage = coverage.each_with_index.map.map do |count, index|
|
29
|
+
count -= last_cover[index] if count.present? && last_cover.present? && last_cover[index].present?
|
30
|
+
index if count&.positive?
|
31
|
+
end
|
32
|
+
coverage.compact!
|
33
|
+
next unless coverage.any?
|
34
|
+
result[path] = coverage
|
35
|
+
end
|
36
|
+
@@coverage[spec] = result
|
37
|
+
@@last_cover = cover
|
38
|
+
end
|
39
|
+
|
40
|
+
def relevant_path(path)
|
41
|
+
path = Rails.root.join(path).to_s
|
42
|
+
path[Rails.root.to_s.length + 1..-1]
|
43
|
+
end
|
44
|
+
|
45
|
+
def load_stats
|
46
|
+
@@coverage = begin
|
47
|
+
JSON.parse(File.read(Rails.root.join('tmp/quick_rspec.new.json')))
|
48
|
+
rescue Errno::ENOENT
|
49
|
+
begin
|
50
|
+
JSON.parse(File.read(Rails.root.join('tmp/quick_rspec.json')))
|
51
|
+
rescue Errno::ENOENT
|
52
|
+
{}
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def save_stats
|
58
|
+
File.open(Rails.root.join('tmp/quick_rspec.new.json'), 'w+') do |f|
|
59
|
+
f.write @@coverage.to_json
|
60
|
+
end
|
61
|
+
File.open(Rails.root.join('tmp/quick_rspec.stats'), 'w+') do |f|
|
62
|
+
@@coverage.each do |spec_name, coverage|
|
63
|
+
f.write "#{spec_name}:\n"
|
64
|
+
coverage.each do |path, lines|
|
65
|
+
f.write " #{path}:\n"
|
66
|
+
f.write " #{lines}\n"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def where_tested(file)
|
73
|
+
@@coverage.map do |spec, coverage|
|
74
|
+
next unless file.in? coverage.keys
|
75
|
+
spec
|
76
|
+
end.compact
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
if Rails.env.test?
|
82
|
+
QuickRspec.load_stats
|
83
|
+
|
84
|
+
QuickRspec.start
|
85
|
+
|
86
|
+
RSpec.configure do |config|
|
87
|
+
config.after(:each) do |example|
|
88
|
+
QuickRspec.collect_stats(example)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
at_exit { QuickRspec.save_stats }
|
93
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
desc 'Runs rspec for recently changed files'
|
3
|
+
task quick_rspec: :environment do
|
4
|
+
dry = ENV['DRY'].present?
|
5
|
+
|
6
|
+
QuickRspec.load_stats
|
7
|
+
|
8
|
+
changed = []
|
9
|
+
specs = []
|
10
|
+
|
11
|
+
files = `git diff --name-only`.split("\n")
|
12
|
+
files.reject! { |file| file =~ %r{^tmp\/}i }
|
13
|
+
|
14
|
+
files.each do |file|
|
15
|
+
next if file =~ %r{^tmp\/}i
|
16
|
+
if file =~ %r{^spec\/}i
|
17
|
+
specs << file
|
18
|
+
else
|
19
|
+
changed << file
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
run_all = false
|
24
|
+
specs += files.map do |file|
|
25
|
+
files = QuickRspec.where_tested(file)
|
26
|
+
run_all ||= files.empty?
|
27
|
+
files
|
28
|
+
end.flatten.compact
|
29
|
+
specs.uniq!
|
30
|
+
|
31
|
+
puts "Changed files:\n#{changed.map { |file| " #{file}" }.join("\n")}\n"
|
32
|
+
|
33
|
+
if run_all
|
34
|
+
puts "It requires to run all tests\n\n"
|
35
|
+
system('rspec') unless dry
|
36
|
+
else
|
37
|
+
puts "Run specs:\n#{specs.map { |file| " #{file}" }.join("\n")}\n\n"
|
38
|
+
system("rspec #{specs.join(' ')}") unless dry
|
39
|
+
end
|
40
|
+
end
|
data/quick-rspec.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.required_ruby_version = '>= 2.3'
|
7
|
+
spec.name = "quick-rspec"
|
8
|
+
spec.version = "0.1.4"
|
9
|
+
spec.authors = ["Dmitry Silchenko"]
|
10
|
+
spec.email = ["dmitry@desofto.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Runs only specs related to changed files}
|
13
|
+
spec.description = %q{Runs only specs related to changed files}
|
14
|
+
spec.homepage = "https://github.com/desofto/quick-rspec"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
spec.add_development_dependency "rails", "~> 4.2"
|
33
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: quick-rspec
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dmitry Silchenko
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-30 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.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
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: rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.2'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '4.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: Runs only specs related to changed files
|
70
|
+
email:
|
71
|
+
- dmitry@desofto.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".ruby-version"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- bin/console
|
83
|
+
- bin/setup
|
84
|
+
- lib/quick-rspec.rb
|
85
|
+
- lib/tasks/quick_rspec.rake
|
86
|
+
- quick-rspec.gemspec
|
87
|
+
homepage: https://github.com/desofto/quick-rspec
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata:
|
91
|
+
allowed_push_host: https://rubygems.org
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '2.3'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.6.11
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: Runs only specs related to changed files
|
112
|
+
test_files: []
|