guard-jruby-minitest 0.0.1 → 0.1.0

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: 5e4d62eb23a8e2272ecb8695cfe652894a67e542
4
- data.tar.gz: c40df619c00bb170bdb008f355feaa72918219ed
3
+ metadata.gz: 4cc9d48d0d1386bd4ca79fb4f9e1ca82b8a551ae
4
+ data.tar.gz: 00b4602d66109f96118c237bfab966c177d3c7db
5
5
  SHA512:
6
- metadata.gz: 055e04529697f8339f7f25a2a4f918da856b0d29397ec4368dff821c9ad95869fab78ff7f8c5ef088bdf00baa63e10b5c1769d3471c82c7c54a5e15317b92658
7
- data.tar.gz: 920ce80fc8fbab97f380489529694052dac2a99c77abc0b2bc543bf8f8c6af3827b01d10d58a24b765b30ac8a9c380cff3c5d9cc848475c019641a60d73d26c7
6
+ metadata.gz: 2aaa340feb51fe6aef6c0a610e0f9ed539b4730398ca673290502301af9534110d24ddf278c280324fecd85fce63b1b5ddba5896f7dc21d2c760da70b6512b75
7
+ data.tar.gz: cb6588dcd37f5c058b218acb972a52159f9491accac00a67bb8b884017c32e944ae738f1021d59ab606f0a83b2c08443c750308e53c540b9ebea6abb8af46f75
data/README.md CHANGED
@@ -1,6 +1,25 @@
1
- # Guard::Jruby::Minitest
1
+ # guard-jruby-minitest
2
2
 
3
- TODO: Write a gem description
3
+ Guard has been a great productivity booster when used in a TDD environment. However, JRuby makes TDD harder, if not impossible. It is due to the fact that, by default, every `run_on_modification` or `run_on_change` starts a new process, which incurs [the long JVM start time]. Some approaches have been attempted, such as [Drip] or [Nailgun].
4
+
5
+ This guard extension allows you to run all of your tests on JRuby without the initial start up cost every time. It loads all of your application files in advance, and reloads any that change. That way, when you run test, the JVM is already running, and your files have already been required.
6
+
7
+ Most of the configuration options available to `guard-minitest` work with this extension too.
8
+
9
+ This gem should work with Rails as well as Rack applications.
10
+
11
+ ## Reloaders
12
+
13
+ Currently, `guard` runs the following reloaders when part of application is changed:
14
+
15
+ * `AppPathsReloader`: Reloads the application (non-test) code.
16
+ * `FactoryGirlReloader`: Reloads the `factory_girl` factories.
17
+ * `RailsReloader`: Reloads the entire application if the application is a Rails app.
18
+ * `TestPathsReloader`: Reloads the tests. This is the most tricky part because of the way `minitest` run tests.
19
+
20
+ ## Caveats
21
+
22
+ Reloading is not always clean and sometimes could lead to unpredictable results. In that case, it is best to exit and rerun `guard`.
4
23
 
5
24
  ## Installation
6
25
 
@@ -18,12 +37,29 @@ Or install it yourself as:
18
37
 
19
38
  ## Usage
20
39
 
21
- TODO: Write usage instructions here
40
+ Create or add to the `Guardfile` by running the following command in your application directory:
41
+
42
+ $ bundle exec guard init jruby-minitest
43
+
44
+ Then run `guard` like this:
45
+
46
+ $ bundle exec guard
47
+
48
+ The first time the test runs in Guard, it will take some time. However, after that, it should be quite fast.
49
+
50
+ ## Thank You
51
+
52
+ Many thanks to [guard-jruby-rspec] for the inspiration.
22
53
 
23
54
  ## Contributing
24
55
 
25
- 1. Fork it ( https://github.com/[my-github-username]/guard-jruby-minitest/fork )
56
+ 1. Fork it ( https://github.com/jackxxu/guard-jruby-minitest/fork )
26
57
  2. Create your feature branch (`git checkout -b my-new-feature`)
27
58
  3. Commit your changes (`git commit -am 'Add some feature'`)
28
59
  4. Push to the branch (`git push origin my-new-feature`)
29
60
  5. Create a new Pull Request
61
+
62
+ [the long JVM start time]: https://github.com/jruby/jruby/wiki/Improving-startup-time
63
+ [Drip]: https://github.com/ninjudd/drip/wiki/JRuby
64
+ [Nailgun]: https://github.com/jruby/jruby/wiki/JRubyWithNailgun
65
+ [guard-jruby-rspec]: https://github.com/jkutner/guard-jruby-rspec
@@ -1,11 +1,11 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'guard/jruby/minitest/version'
4
+ require 'guard/jruby-minitest/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "guard-jruby-minitest"
8
- spec.version = Guard::Jruby::Minitest::VERSION
8
+ spec.version = Guard::JRubyMinitestVersion::VERSION
9
9
  spec.authors = ["Jack Xu"]
10
10
  spec.email = ["jackxxu@gmail.com"]
11
11
  spec.summary = %q{Guard gem for JRuby Minitest}
@@ -19,7 +19,9 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency 'guard', '>= 0.10.0'
22
- spec.add_dependency 'guard-minitest', '>= 0.7.3'
22
+ spec.add_dependency 'guard-minitest', '>= 2.3.0'
23
+ spec.add_dependency 'ruby_parser', '>= 3.0'
24
+ spec.add_dependency 'pry', '~> 0.9.12'
23
25
 
24
26
  spec.add_development_dependency "bundler", "~> 1.6"
25
27
  spec.add_development_dependency "rake"
@@ -0,0 +1 @@
1
+ require_relative 'guard/jruby-minitest'
@@ -0,0 +1,68 @@
1
+ require 'guard/guard'
2
+ require 'guard/minitest'
3
+ require_relative 'jruby-minitest/version'
4
+
5
+ module Guard
6
+ class JRubyMinitest < ::Guard::Minitest
7
+ require_relative 'jruby-minitest/containment'
8
+ require_relative 'jruby-minitest/runner'
9
+ require_relative 'jruby-minitest/reloaders/test_paths'
10
+ require_relative 'jruby-minitest/reloaders/rails_reloader'
11
+ require_relative 'jruby-minitest/reloaders/factory_girl_reloader'
12
+ require_relative 'jruby-minitest/reloaders/app_paths_reloader'
13
+ require_relative 'jruby-minitest/reloaders/test_paths_reloader'
14
+
15
+ unless Utils.minitest_version_gte_5?
16
+ require_relative 'jruby-minitest/runners/old_runner'
17
+ end
18
+
19
+ def initialize(options = {})
20
+ @custom_watchers = options[:watchers]
21
+ general_watchers = [Watcher.new(%r{^(.+)\.rb$}), Watcher.new(%r{^(.+)\.(erb|haml)$})]
22
+ super(options.merge(watchers: general_watchers))
23
+ TestPaths.test_folders = options[:test_folders]
24
+ super
25
+ end
26
+
27
+ def run_all
28
+ unload_previous_tests
29
+ super
30
+ end
31
+
32
+ %w(run_on_modifications run_on_additions run_on_removals).each do |method_name|
33
+ define_method method_name do |raw_paths = []|
34
+ unload_previous_tests
35
+ reload_application(raw_paths)
36
+ super matched_paths(raw_paths)
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ def matched_paths(raw_paths)
43
+ [].tap do |paths|
44
+ raw_paths.each do |p|
45
+ @custom_watchers.each do |w|
46
+ if (m = w.match(p))
47
+ paths << (w.action.nil? ? p : w.call_action(m))
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ def reload_application(paths)
55
+ [RailsReloader, AppPathsReloader, FactoryGirlReloader].each do |reloader|
56
+ reloader.run(paths)
57
+ end
58
+ end
59
+
60
+ def unload_previous_tests
61
+ if Utils.minitest_version_gte_5?
62
+ ::Minitest::Test.reset
63
+ else
64
+ ::MiniTest::Unit::TestCase.reset
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,26 @@
1
+ module Guard
2
+ class JRubyMinitest
3
+ class Containment
4
+
5
+ def initialize(options = {})
6
+ @error_handler = options.fetch(:error_handler, method(:output_as_guard_error))
7
+ end
8
+
9
+ def protect
10
+ yield
11
+ rescue Exception => e
12
+ error_handler.call e
13
+ throw :task_has_failed
14
+ end
15
+
16
+ private
17
+
18
+ attr_reader :error_handler
19
+
20
+ def output_as_guard_error(exception)
21
+ UI.error $!.message
22
+ UI.error $!.backtrace.join "\n"
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,16 @@
1
+ module Guard
2
+ class JRubyMinitest
3
+ class AppPathsReloader
4
+ extend TestPaths
5
+
6
+ def self.run(paths)
7
+
8
+ paths.select{|p| !in_test_folders?(p)}.each do |p|
9
+ if File.exists?(p)
10
+ Containment.new.protect { load p }
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ module Guard
2
+ class JRubyMinitest
3
+ class FactoryGirlReloader
4
+ def self.run(*)
5
+ if defined? ::FactoryGirl
6
+ Containment.new.protect { FactoryGirl.reload }
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ module Guard
2
+ class JRubyMinitest
3
+ class RailsReloader
4
+ def self.run(*)
5
+ if defined? ::ActionDispatch::Reloader
6
+ Containment.new.protect do
7
+ ActionDispatch::Reloader.cleanup!
8
+ ActionDispatch::Reloader.prepare!
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+ module Guard
2
+ class JRubyMinitest
3
+ module TestPaths
4
+ extend self
5
+
6
+ attr_writer :test_folders
7
+
8
+ def test_folders
9
+ @test_folders ||= ['test', 'spec']
10
+ end
11
+
12
+ def in_test_folders?(path)
13
+ test_folders.any? {|folder| path.start_with?("#{folder}/")}
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,27 @@
1
+ require 'ruby_parser'
2
+
3
+ module Guard
4
+ class JRubyMinitest
5
+ class TestPathsReloader
6
+ extend TestPaths
7
+
8
+ def self.run(paths)
9
+ paths.select{|p| in_test_folders?(p)}.each do |p|
10
+ if File.exists?(p)
11
+ Containment.new.protect { unload p; load p }
12
+ end
13
+ end
14
+ end
15
+
16
+ def self.unload(path)
17
+ code = RubyParser.new.parse(IO.read(path))
18
+ test_classes = []
19
+ test_classes << code[1] if code[0] == :class
20
+ code.each_of_type(:class) {|c| test_classes << c[1] if c[1].is_a?(Symbol) }
21
+ test_classes.each do |c|
22
+ Object.send(:remove_const, c) if Object.const_defined?(c)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,36 @@
1
+ require 'minitest/unit'
2
+
3
+ module Guard
4
+ class Minitest
5
+ class Runner
6
+
7
+ def _run_command(paths, all)
8
+ $LOAD_PATH << 'test' unless $LOAD_PATH.include?('test')
9
+ paths.each {|path| reload path, all}
10
+
11
+ # if ::MiniTest.respond_to?(:run) # minitest 5
12
+ if Utils.minitest_version_gte_5?
13
+ ::MiniTest.run(ARGV)
14
+ ::MiniTest.class_variable_get(:@@after_run).reverse_each(&:call)
15
+ else
16
+ ::Minitest::Unit.runner = nil # resets the runner for minitest
17
+ ::MiniTest::Unit.new.run(ARGV)
18
+ ::MiniTest::Unit.class_variable_get(:@@after_tests).reverse_each(&:call)
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def reload(path, all)
25
+ if all
26
+ load path
27
+ else
28
+ ::Guard::JRubyMinitest::TestPathsReloader.run([path])
29
+ end
30
+ end
31
+
32
+ end
33
+ end
34
+ end
35
+
36
+
@@ -0,0 +1,16 @@
1
+ require 'minitest/unit'
2
+ require 'guard/minitest/notifier'
3
+
4
+ module MiniTest
5
+ class MiniTest::Unit
6
+ begin
7
+ alias_method :_run_anything_without_guard, :_run_anything
8
+ def _run_anything(type)
9
+ start = Time.now
10
+ _run_anything_without_guard(type)
11
+ duration = Time.now - start
12
+ ::Guard::Minitest::Notifier.notify(test_count, assertion_count, failures, errors, skips, duration)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,9 @@
1
+ # This eliminates the stty warning.
2
+ interactor :simple
3
+ guard 'jruby-minitest', :spec_paths => ["test"] do
4
+ # with Minitest::Unit
5
+ watch(%r{^test/(.*)\/?test_(.*)\.rb$})
6
+ watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
7
+ watch(%r{^test/test_helper\.rb$}) { 'test' }
8
+ end
9
+
@@ -0,0 +1,5 @@
1
+ module Guard
2
+ module JRubyMinitestVersion
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guard-jruby-minitest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jack Xu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-08 00:00:00.000000000 Z
11
+ date: 2014-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: guard
@@ -30,12 +30,40 @@ dependencies:
30
30
  requirements:
31
31
  - - '>='
32
32
  - !ruby/object:Gem::Version
33
- version: 0.7.3
33
+ version: 2.3.0
34
34
  requirement: !ruby/object:Gem::Requirement
35
35
  requirements:
36
36
  - - '>='
37
37
  - !ruby/object:Gem::Version
38
- version: 0.7.3
38
+ version: 2.3.0
39
+ prerelease: false
40
+ type: :runtime
41
+ - !ruby/object:Gem::Dependency
42
+ name: ruby_parser
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '3.0'
53
+ prerelease: false
54
+ type: :runtime
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.12
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ~>
65
+ - !ruby/object:Gem::Version
66
+ version: 0.9.12
39
67
  prerelease: false
40
68
  type: :runtime
41
69
  - !ruby/object:Gem::Dependency
@@ -81,8 +109,18 @@ files:
81
109
  - README.md
82
110
  - Rakefile
83
111
  - guard-jruby-minitest.gemspec
84
- - lib/guard/jruby/minitest.rb
85
- - lib/guard/jruby/minitest/version.rb
112
+ - lib/guard-jruby-minitest.rb
113
+ - lib/guard/jruby-minitest.rb
114
+ - lib/guard/jruby-minitest/containment.rb
115
+ - lib/guard/jruby-minitest/reloaders/app_paths_reloader.rb
116
+ - lib/guard/jruby-minitest/reloaders/factory_girl_reloader.rb
117
+ - lib/guard/jruby-minitest/reloaders/rails_reloader.rb
118
+ - lib/guard/jruby-minitest/reloaders/test_paths.rb
119
+ - lib/guard/jruby-minitest/reloaders/test_paths_reloader.rb
120
+ - lib/guard/jruby-minitest/runner.rb
121
+ - lib/guard/jruby-minitest/runners/old_runner.rb
122
+ - lib/guard/jruby-minitest/templates/Guardfile
123
+ - lib/guard/jruby-minitest/version.rb
86
124
  - test/test_helper.rb
87
125
  homepage: https://github.com/jackxxu/guard-jruby-minitest
88
126
  licenses:
@@ -1,12 +0,0 @@
1
- require 'guard/guard'
2
- require 'guard/minitest'
3
- require "guard/jruby/minitest/version"
4
-
5
- module Guard
6
- module Jruby
7
- class Minitest < ::Guard::Minitest
8
-
9
-
10
- end
11
- end
12
- end
@@ -1,7 +0,0 @@
1
- module Guard
2
- module Jruby
3
- module Minitest
4
- VERSION = "0.0.1"
5
- end
6
- end
7
- end