guard-minitest_cr 0.1.0

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: a0c7b8029e6e13df4af3720697f56c2ceeecac725a0c5f8c97951232b051fb73
4
+ data.tar.gz: ab8859e9d537b8012ac8e5ec27bebd8701c335c5dff7d4f5c16627b604cc0377
5
+ SHA512:
6
+ metadata.gz: 69532eb63bdf3e6860df158e0f5ae29930b1321c14f6b2938d739d0bfaef1d2b1cfcd254e1c3dfc3a1c34ef2e82c2c2cc9cc06dd62fea788da7eebc344beee02
7
+ data.tar.gz: fa5d1acaaf9b9619c8719879466ca3ea220be3001ad6575e910f444b1bc788c311372c8cf6b54cf49969d7869af96ae2b2e20298d3e1f251a800cf58fca194ec
data/CHANGELOG.md ADDED
@@ -0,0 +1 @@
1
+ # Moved to [GitHub releases](https://github.com/felixbuenemann/guard-minitest_cr/releases) page.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Yann Lugrin, Rémy Coutable
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ 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, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,122 @@
1
+ # Guard::MinitestCr
2
+ [![Gem Version](https://badge.fury.io/rb/guard-minitest_cr.svg)](http://badge.fury.io/rb/guard-minitest_cr) [![Build Status](https://travis-ci.org/felixbuenemann/guard-minitest_cr.svg?branch=master)](https://travis-ci.org/felixbuenemann/guard-minitest_cr)
3
+
4
+ Guard::MinitestCr allows to automatically & intelligently launch tests with the Crystal
5
+ [minitest.cr framework](https://github.com/ysbaddaden/minitest.cr) when files are modified.
6
+
7
+ ## Install
8
+
9
+ Please be sure to have [Guard](http://github.com/guard/guard) installed before you continue.
10
+
11
+ The simplest way to install Guard::MinitestCr is to use [Bundler](http://gembundler.com/).
12
+
13
+ Add Guard::MinitestCr to your `Gemfile`:
14
+
15
+ ```ruby
16
+ group :development do
17
+ gem 'guard-minitest_cr'
18
+ end
19
+ ```
20
+
21
+ and install it by running Bundler:
22
+
23
+ ```bash
24
+ $ bundle
25
+ ```
26
+
27
+ Add guard definition to your Guardfile by running the following command:
28
+
29
+ ```bash
30
+ guard init minitest_cr
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ Please read [Guard usage doc](http://github.com/guard/guard#readme)
36
+
37
+ ## Guardfile
38
+
39
+ Guard::MinitestCr can be adapated to all kind of projects.
40
+ Please read [guard doc](http://github.com/guard/guard#readme) for more info about the Guardfile DSL.
41
+
42
+ ### Standard Guardfile when using Minitest::Test
43
+
44
+ ```ruby
45
+ guard :minitest_cr do
46
+ watch(%r{^test/(.+)_test\.cr$})
47
+ watch(%r{^src/(.+)\.cr$}) { |m| "test/#{m[1]}_test.cr" }
48
+ watch(%r{^test/test_helper\.cr$}) { Dir.glob("test/**/*_test.cr") }
49
+ end
50
+ ```
51
+
52
+ ### Standard Guardfile when using Minitest::Spec
53
+
54
+ ```ruby
55
+ guard :minitest_cr do
56
+ watch(%r{^spec/(.+)_spec\.cr$})
57
+ watch(%r{^src/(.+)\.cr$}) { |m| "spec/#{m[1]}_spec.cr" }
58
+ watch(%r{^spec/spec_helper\.cr$}) { Dir.glob("spec/**/*_spec.cr") }
59
+ end
60
+ ```
61
+
62
+ ## Options
63
+
64
+ ### List of available options
65
+
66
+ ```ruby
67
+ all_on_start: false # run all tests in group on startup, default: true
68
+ all_after_pass: true # run all tests in group after changed specs pass, default: false
69
+ cli: '--verbose' # pass arbitrary Minitest CLI arguments, default: ''
70
+ test_folders: ['tests'] # specify an array of paths that contain test files, default: %w[test spec]
71
+ test_file_patterns: %w[test_*.cr] # specify an array of patterns that test files must match in order to be run, default: %w[*_test.cr test_*.cr *_spec.cr]
72
+ test_helpers: ['test_helper.cr'] # specify an array of test helpers that should be excluded from test files, default: %w[test_helper.cr spec_helper.cr]
73
+ env: {} # specify some environment variables to be set when the test command is invoked, default: {}
74
+ all_env: {} # specify additional environment variables to be set when all tests are being run, default: false
75
+ ```
76
+
77
+ ### Options usage examples
78
+
79
+ #### `:test_folders` and `:test_file_patterns`
80
+
81
+ You can change the default location of test files using the `:test_folders` option and change the pattern of test files using the `:test_file_patterns` option:
82
+
83
+ ```ruby
84
+ guard :minitest_cr, test_folders: 'test/unit', test_file_patterns: '*_test.rb' do
85
+ # ...
86
+ end
87
+ ```
88
+
89
+ #### `:cli`
90
+
91
+ You can pass any of the standard MiniTest CLI options using the `:cli` option:
92
+
93
+ ```ruby
94
+ guard :minitest_cr, cli: '--seed 123456 --verbose' do
95
+ # ...
96
+ end
97
+ ```
98
+
99
+ ## Development
100
+
101
+ * Documentation hosted at [RubyDoc](http://rubydoc.info/github/felixbuenemann/guard-minitest_cr/master/frames).
102
+ * Source hosted at [GitHub](https://github.com/felixbuenemann/guard-minitest_cr).
103
+
104
+ Pull requests are very welcome! Please try to follow these simple rules if applicable:
105
+
106
+ * Please create a topic branch for every separate change you make.
107
+ * Make sure your patches are well tested. All specs run by Travis CI must pass.
108
+ * Update the [README](https://github.com/felixbuenemann/guard-minitest_cr/blob/master/README.md).
109
+ * Please **do not change** the version number.
110
+
111
+ For questions please join us in our [Google group](http://groups.google.com/group/guard-dev) or on
112
+ `#guard` (irc.freenode.net).
113
+
114
+ ## Author
115
+
116
+ [Felix Bünemann](https://github.com/felixbuenemann)
117
+
118
+ This is a fork of the [guard-minitest](https://github.com/guard/guard-minitest) gem that was adapted to work with the minitest.cr Crystal Shard.
119
+
120
+ ## Contributors
121
+
122
+ [https://github.com/felixbuenemann/guard-minitest\_cr/graphs/contributors](https://github.com/felixbuenemann/guard-minitest_cr/graphs/contributors)
@@ -0,0 +1,53 @@
1
+ require 'guard/compat/plugin'
2
+
3
+ module Guard
4
+ class MinitestCr < Plugin
5
+ require 'guard/minitest_cr/runner'
6
+ require 'guard/minitest_cr/version'
7
+
8
+ attr_accessor :runner
9
+
10
+ def initialize(options = {})
11
+ super
12
+ @options = {
13
+ all_on_start: true
14
+ }.merge(options)
15
+ @runner = Runner.new(@options)
16
+ end
17
+
18
+ def start
19
+ Compat::UI.info "Guard::MinitestCr #{MinitestCrVersion::VERSION} is running!"
20
+ run_all if @options[:all_on_start]
21
+ end
22
+
23
+ def stop
24
+ true
25
+ end
26
+
27
+ def reload
28
+ true
29
+ end
30
+
31
+ def run_all
32
+ throw_on_failed_tests { runner.run_all }
33
+ end
34
+
35
+ def run_on_modifications(paths = [])
36
+ throw_on_failed_tests { runner.run_on_modifications(paths) }
37
+ end
38
+
39
+ def run_on_additions(paths)
40
+ runner.run_on_additions(paths)
41
+ end
42
+
43
+ def run_on_removals(paths)
44
+ runner.run_on_removals(paths)
45
+ end
46
+
47
+ private
48
+
49
+ def throw_on_failed_tests
50
+ throw :task_has_failed unless yield
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,57 @@
1
+ require 'guard/minitest_cr'
2
+
3
+ module Guard
4
+ class MinitestCr < Plugin
5
+ class Inspector
6
+ attr_reader :test_folders, :test_file_patterns, :test_helpers
7
+
8
+ def initialize(test_folders, test_file_patterns, test_helpers)
9
+ @test_folders = test_folders.uniq.compact
10
+ @test_file_patterns = test_file_patterns.uniq.compact
11
+ @test_helpers = test_helpers.uniq.compact
12
+ end
13
+
14
+ def clean_all
15
+ clean(test_folders)
16
+ end
17
+
18
+ def clean(paths)
19
+ paths.reduce([]) do |memo, path|
20
+ if File.directory?(path)
21
+ memo += _test_files_for_paths(path)
22
+ else
23
+ memo << path if _test_file?(path)
24
+ end
25
+ memo
26
+ end.uniq
27
+ end
28
+
29
+ def clear_memoized_test_files
30
+ @all_test_files = nil
31
+ end
32
+
33
+ def all_test_files
34
+ @all_test_files ||= _test_files_for_paths
35
+ end
36
+
37
+ private
38
+
39
+ def _test_files_for_paths(paths = test_folders)
40
+ paths = _join_for_glob(Array(paths))
41
+ files = _join_for_glob(test_file_patterns)
42
+ helpers = _join_for_glob(test_helpers)
43
+
44
+ Dir["#{paths}/**/#{files}"] - Dir["#{paths}/**/#{helpers}"]
45
+ end
46
+
47
+ def _test_file?(path)
48
+ _test_files_for_paths.map {|path| File.expand_path(path) }
49
+ .include?(File.expand_path(path))
50
+ end
51
+
52
+ def _join_for_glob(fragments)
53
+ "{#{fragments.join(',')}}"
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,135 @@
1
+ require 'guard/minitest_cr/inspector'
2
+ require 'English'
3
+
4
+ module Guard
5
+ class MinitestCr < Plugin
6
+ class Runner
7
+ attr_accessor :inspector
8
+
9
+ def initialize(options = {})
10
+ @options = {
11
+ all_after_pass: false,
12
+ all_env: {},
13
+ env: {},
14
+ test_folders: %w(test spec),
15
+ test_file_patterns: %w(*_test.cr test_*.cr *_spec.cr),
16
+ test_helpers: %w(test_helper.cr spec_helper.cr),
17
+ cli: nil
18
+ }.merge(options)
19
+
20
+ [:test_folders, :test_file_patterns, :test_helpers].each do |k|
21
+ @options[k] = Array(@options[k]).uniq.compact
22
+ end
23
+
24
+ @inspector = Inspector.new(test_folders, test_file_patterns, test_helpers)
25
+ end
26
+
27
+ def run(paths, options = {})
28
+ return unless options[:all] || !paths.empty?
29
+
30
+ message = "Running: #{options[:all] ? 'all tests' : paths.join(' ')}"
31
+ Compat::UI.info message, reset: true
32
+
33
+ begin
34
+ status = _run(*minitest_command(paths, options[:all]))
35
+ rescue Errno::ENOENT => e
36
+ Compat::UI.error e.message
37
+ throw :task_has_failed
38
+ end
39
+
40
+ success = status.zero?
41
+
42
+ Compat::UI.notify(message, title: 'Minitest results', image: success ? :success : :failed)
43
+
44
+ run_all_coz_ok = @options[:all_after_pass] && success && !options[:all]
45
+ run_all_coz_ok ? run_all : success
46
+ end
47
+
48
+ def run_all
49
+ paths = inspector.clean_all
50
+ run(paths, all: true)
51
+ end
52
+
53
+ def run_on_modifications(paths = [])
54
+ paths = inspector.clean(paths)
55
+ run(paths, all: all_paths?(paths))
56
+ end
57
+
58
+ def run_on_additions(_paths)
59
+ inspector.clear_memoized_test_files
60
+ true
61
+ end
62
+
63
+ def run_on_removals(_paths)
64
+ inspector.clear_memoized_test_files
65
+ end
66
+
67
+ private
68
+
69
+ def cli_options
70
+ @cli_options ||= Array(@options[:cli])
71
+ end
72
+
73
+ def all_after_pass?
74
+ @options[:all_after_pass]
75
+ end
76
+
77
+ def test_folders
78
+ @options[:test_folders]
79
+ end
80
+
81
+ def test_file_patterns
82
+ @options[:test_file_patterns]
83
+ end
84
+
85
+ def test_helpers
86
+ @options[:test_helpers]
87
+ end
88
+
89
+ def _run(*args)
90
+ Compat::UI.debug "Running: #{args.join(' ')}"
91
+ return $CHILD_STATUS.exitstatus unless Kernel.system(*args).nil?
92
+
93
+ fail Errno::ENOENT, args.join(' ')
94
+ end
95
+
96
+ def minitest_command(paths, all)
97
+ cmd_parts = []
98
+
99
+ cmd_parts << crystal_command(paths)
100
+
101
+ [cmd_parts.compact.join(' ')].tap do |args|
102
+ env = generate_env(all)
103
+ args.unshift(env) if env.length > 0
104
+ end
105
+ end
106
+
107
+ def crystal_command(paths)
108
+ cmd_parts = ['crystal', 'run']
109
+ cmd_parts.concat(paths)
110
+
111
+ cmd_parts << '--'
112
+ cmd_parts += cli_options
113
+ cmd_parts
114
+ end
115
+
116
+ def generate_env(all = false)
117
+ base_env.merge(all ? all_env : {})
118
+ end
119
+
120
+ def base_env
121
+ Hash[(@options[:env] || {}).map { |key, value| [key.to_s, value.to_s] }]
122
+ end
123
+
124
+ def all_env
125
+ return { @options[:all_env].to_s => 'true' } unless @options[:all_env].is_a? Hash
126
+ Hash[@options[:all_env].map { |key, value| [key.to_s, value.to_s] }]
127
+ end
128
+
129
+ def all_paths?(paths)
130
+ paths == inspector.all_test_files
131
+ end
132
+
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,16 @@
1
+ guard :minitest_cr do
2
+ # with Minitest::Test ("_test" suffix)
3
+ watch(%r{^test/(.+)_test\.cr$})
4
+ watch(%r{^src/(.+)\.cr$}) { |m| "test/#{m[1]}_test.cr" }
5
+ watch(%r{^test/test_helper\.cr$}) { Dir.glob("test/**/*_test.cr") }
6
+
7
+ # with Minitest::Test ("test_" prefix)
8
+ # watch(%r{^test/(.*)\/?test_(.*)\.cr$})
9
+ # watch(%r{^src/(.*/)?([^/]+)\.cr$}) { |m| "test/#{m[1]}test_#{m[2]}.cr" }
10
+ # watch(%r{^test/test_helper\.cr$}) { Dir.glob("test/**/test_*.cr") }
11
+
12
+ # with Minitest::Spec ("_spec" suffix)
13
+ # watch(%r{^spec/(.+)_spec\.cr$})
14
+ # watch(%r{^src/(.+)\.cr$}) { |m| "spec/#{m[1]}_spec.cr" }
15
+ # watch(%r{^spec/spec_helper\.cr$}) { Dir.glob("spec/**/*_spec.cr") }
16
+ end
@@ -0,0 +1,5 @@
1
+ module Guard
2
+ class MinitestCrVersion
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard-minitest_cr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Felix Bünemann
8
+ - Yann Lugrin
9
+ - Rémy Coutable
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2018-07-01 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: guard
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: 2.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: 2.0.0
29
+ - !ruby/object:Gem::Dependency
30
+ name: guard-compat
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '1.2'
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '1.2'
43
+ - !ruby/object:Gem::Dependency
44
+ name: bundler
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ description: Guard::Minitest automatically run your tests with Minitest.cr framework
58
+ (much like autotest)
59
+ email:
60
+ - felix.buenemann@gmail.com
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - CHANGELOG.md
66
+ - LICENSE
67
+ - README.md
68
+ - lib/guard/minitest_cr.rb
69
+ - lib/guard/minitest_cr/inspector.rb
70
+ - lib/guard/minitest_cr/runner.rb
71
+ - lib/guard/minitest_cr/templates/Guardfile
72
+ - lib/guard/minitest_cr/version.rb
73
+ homepage: https://github.com/felixbuenemann/guard-minitest-cr
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 1.9.2
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.7.7
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Guard plugin for the Crystal Minitest.cr framework
97
+ test_files: []