grspec 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: eced9037a075dc99d729dcb057ddc59de7be11724cf8c4a58f821a11cda7fa8a
4
+ data.tar.gz: 7bb920bcc0f1b34d52cc0a2ad2bc7a4a5f23ae57bd5efaf13e371acc7c3c96a0
5
+ SHA512:
6
+ metadata.gz: 554dc73dcaf89a468dae7709fba983eea4a6e84a81994c3c5f8857541f7e92a70f861f817c17b188d00583be7a4e2583d87808ce8f5baedc4a758793a8b237fb
7
+ data.tar.gz: a5a381134e882e02c71c04268fbe2dd67b8ec9567e855272444629ccf79eaef919fd01ac6fed5b1636c1d54fef6a839b512f1fff1dc8641c88e1f5b9433b7bca
data/bin/grspec ADDED
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'find_changed_files'
4
+ require 'find_matching_specs'
5
+ require 'spec_runner'
6
+
7
+ # handle args
8
+ git_diff_args = ARGV.join(' ')
9
+
10
+ # get changed files
11
+ changed_files = FindChangedFiles.new(ARGV).call
12
+
13
+ # match specs
14
+ matching_specs = FindMatchingSpecs.new(changed_files).call
15
+
16
+ # debug info
17
+ puts
18
+ puts "Changed files:"
19
+ puts changed_files
20
+ puts
21
+ puts "Matching specs:"
22
+ puts matching_specs
23
+ puts
24
+
25
+ # run specs
26
+ SpecRunner.run(matching_specs)
@@ -0,0 +1,22 @@
1
+ class FindChangedFiles
2
+ GIT_DIFF_COMMAND = 'git diff'.freeze
3
+ GIT_DIFF_OPTIONS = '--name-only'.freeze
4
+
5
+ def initialize(args)
6
+ @args = args
7
+ end
8
+
9
+ def call
10
+ differed_files.split("\n")
11
+ end
12
+
13
+ private
14
+
15
+ def stringified_args
16
+ @args.join(' ')
17
+ end
18
+
19
+ def differed_files
20
+ `#{GIT_DIFF_COMMAND} #{stringified_args} #{GIT_DIFF_OPTIONS}`
21
+ end
22
+ end
@@ -0,0 +1,39 @@
1
+ class FindMatchingSpecs
2
+ attr_reader :directory, :files
3
+
4
+ RUBY_FILE_EXTENSION = '.rb'
5
+
6
+ def initialize(files, directory: nil)
7
+ @files = files
8
+ @directory = directory
9
+ end
10
+
11
+ def call
12
+ ruby_files = files.select { |filename| ruby_file?(filename) }
13
+ spec_files = ruby_files.map { |filename| specs_for(filename) }.flatten
14
+
15
+ spec_files.compact.uniq
16
+ end
17
+
18
+ private
19
+
20
+ def directory
21
+ @directory ||= Dir.pwd
22
+ end
23
+
24
+ def spec_file_listing
25
+ @spec_file_listing ||= Dir.glob("#{directory}/spec/**/*")
26
+ end
27
+
28
+ def ruby_file?(filename)
29
+ filename.end_with?(RUBY_FILE_EXTENSION)
30
+ end
31
+
32
+ def specs_for(filename)
33
+ file = filename.split(RUBY_FILE_EXTENSION).first
34
+
35
+ spec_file_listing.select do |spec_file|
36
+ spec_file.match(/#{file}/)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,11 @@
1
+ class SpecRunner
2
+ RSPEC_COMMAND = 'rspec'.freeze
3
+
4
+ def self.run(matching_specs)
5
+ if matching_specs.any?
6
+ exec "#{RSPEC_COMMAND} #{matching_specs.join(' ')}"
7
+ else
8
+ puts "No matching specs found"
9
+ end
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grspec
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jordane Lew
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-02-11 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: GRSpec is a tiny gem that can quickly and easily run specs for files
14
+ that git has detected changes for, allowing for quick and easy regression checking
15
+ without full-on test runs before committing and overloading build nodes.
16
+ email: jordane.lew@gmail.com
17
+ executables:
18
+ - grspec
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - bin/grspec
23
+ - lib/find_changed_files.rb
24
+ - lib/find_matching_specs.rb
25
+ - lib/spec_runner.rb
26
+ homepage: https://rubygems.org/gems/grspec
27
+ licenses:
28
+ - MIT
29
+ metadata: {}
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubyforge_project:
46
+ rubygems_version: 2.7.3
47
+ signing_key:
48
+ specification_version: 4
49
+ summary: A simple spec runner for differed files
50
+ test_files: []