guard-jruby-rspec 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  This guard extention allows you to run all of your specs on JRuby without the initial start up cost. *It does not run a subset of your specs like guard-rspec* and it does not trigger a run when a file changes.
4
4
 
5
- Instead, this extension loads all of your application files in advance, and reloads any that change. That way, when you run RSpec, the JVM is already running, and your file have already been required.
5
+ Instead, this extension loads all of your application files in advance, and reloads any that change. That way, when you run RSpec, the JVM is already running, and your files have already been required.
6
6
 
7
7
  ## How to Use
8
8
 
@@ -1,61 +1,83 @@
1
1
  require 'guard'
2
2
  require 'guard/guard'
3
- # require 'guard/jruby-rspec/runner'
3
+ require 'guard/rspec'
4
4
 
5
5
  module Guard
6
- class JRubyRSpec < Guard
7
- autoload :Runner, 'guard/jruby-rspec/runner'
6
+ class JRubyRSpec < ::Guard::RSpec
7
+ autoload :Runner, 'guard/jruby-rspec/runner'
8
+ autoload :Inspector, 'guard/jruby-rspec/inspector'
8
9
 
9
10
  def initialize(watchers = [], options = {})
10
- @monitor = options[:monitor_file]
11
- @monitor ||= ".guard-jruby-rspec"
12
-
13
- @spec_paths = options[:spec_dir]
14
- @spec_paths ||= ["spec"]
15
-
16
- all_watchers = watchers + [
17
- Watcher.new(@monitor),
18
- Watcher.new(%r{^(.+)\.rb$}),
19
- Watcher.new(%r{^(.+)\.(erb|haml)$})
20
- ]
21
-
11
+ @options = {
12
+ :all_after_pass => true,
13
+ :all_on_start => true,
14
+ :keep_failed => true,
15
+ :spec_paths => ["spec"],
16
+ :run_all => {},
17
+ :monitor_file => ".guard-jruby-rspec"
18
+ }.merge(options)
19
+ @last_failed = false
20
+ @failed_paths = []
21
+
22
+ default_watchers = [Watcher.new(@monitor)]
23
+ if @custom_watchers.nil? or @custom_watchers.empty?
24
+ default_watchers <<
25
+ Watcher.new(%r{^(.+)\.rb$}) <<
26
+ Watcher.new(%r{^(.+)\.(erb|haml)$})
27
+ else
28
+ watchers.each do |w|
29
+ default_watchers << Watcher.new(w.pattern)
30
+ end
31
+ end
32
+
33
+ @custom_watchers = watchers
34
+
22
35
  # touch the monitor file (lets the gjrspec know we're here)
23
36
  #File.open(@monitor, "w") {}
24
37
 
25
- super(all_watchers, options)
38
+ # ideally we would bypass the Guard::RSpec initializer
39
+ super(default_watchers, @options)
26
40
 
27
- @runner = Runner.new(options)
41
+ @inspector = Inspector.new(@options)
42
+ @runner = Runner.new(@options)
28
43
 
29
44
  end
30
45
 
31
46
  # Call once when guard starts
32
47
  def start
33
48
  UI.info "Guard::JRuby::RSpec is running, with RSpec!"
34
- run_all #if @options[:all_on_start]
49
+ run_all if @options[:all_on_start]
35
50
  end
36
51
 
37
- def run_all
38
- @runner.run(@spec_paths) # options should be configurable
39
- end
52
+ def run_on_change(raw_paths)
53
+ reload_paths(raw_paths)
40
54
 
41
- def reload
42
- #UI.info "reload!"
55
+ unless @custom_watchers.nil? or @custom_watchers.empty?
56
+ paths = []
57
+
58
+ raw_paths.each do |p|
59
+ @custom_watchers.each do |w|
60
+ paths << w.call_action(w.match(p))
61
+ end
62
+ end
63
+ super(paths)
64
+ end
43
65
  end
44
66
 
45
- def run_on_change(paths)
67
+ def reload_paths(paths)
46
68
  paths.each do |p|
47
- if File.exists?(p)
48
- if p == @monitor
49
- begin
50
- pidfile = open(@monitor, "r+")
51
- pid = pidfile.read
52
-
53
- run_all
54
-
55
- system("kill #{pid}") if (pid and !pid.empty?)
56
- ensure
57
- @runner.cleanup
58
- end
69
+ if File.exists?(p)
70
+ if p == @options[:monitor_file]
71
+ # begin
72
+ # pidfile = open(@options[:monitor_file], "r+")
73
+ # pid = pidfile.read
74
+
75
+ # run_all
76
+
77
+ # system("kill #{pid}") if (pid and !pid.empty?)
78
+ # ensure
79
+ # @runner.cleanup
80
+ # end
59
81
  else
60
82
  # reload the file
61
83
  load p
@@ -0,0 +1,13 @@
1
+ require "guard/rspec/formatter"
2
+ require "rspec/core/formatters/base_formatter"
3
+
4
+ class Guard::JRubyRSpec::Formatter::NotificationRSpec < RSpec::Core::Formatters::BaseFormatter
5
+ include Guard::RSpec::Formatter
6
+
7
+ def dump_summary(duration, total, failures, pending)
8
+ message = guard_message(total, failures, pending, duration)
9
+ image = guard_image(failures, pending)
10
+ notify(message, image)
11
+ end
12
+
13
+ end
@@ -0,0 +1,9 @@
1
+ require 'guard/rspec/inspector'
2
+
3
+ module Guard
4
+ class JRubyRSpec
5
+ class Inspector < ::Guard::RSpec::Inspector
6
+
7
+ end
8
+ end
9
+ end
@@ -1,10 +1,17 @@
1
1
  require 'rspec'
2
+ require 'guard/jruby-rspec/formatters/notification_rspec'
3
+ #require 'guard/rspec/runner'
2
4
 
3
5
  module Guard
4
6
  class JRubyRSpec
5
- class Runner
7
+ class Runner #< ::Guard::RSpec::Runner
6
8
 
7
9
  def initialize(options = {})
10
+ @options = {
11
+ :cli => nil,
12
+ :notification => true
13
+ }.merge(options)
14
+
8
15
  @pipefile = options[:pipefile]
9
16
  @pipefile ||= ".guard-jruby-rspec-pipe"
10
17
  cleanup
@@ -15,26 +22,62 @@ module Guard
15
22
  end
16
23
 
17
24
  def run(paths, options = {})
25
+ return false if paths.empty?
26
+
27
+ message = options[:message] || "Running: #{paths.join(' ')}"
28
+ UI.info(message, :reset => true)
29
+
18
30
  # it might be a problem to run Rspec within this runtime. Might have to create an
19
- # auxillary java process and run it over there. That would just make this one a
20
- # controller for the other one.
31
+ # embedded jruby.
21
32
  if File.exists?(@pipefile)
22
-
33
+ raise "not supported yet"
23
34
  # instead of writing to the pipefile, we should probably use a
24
35
  # formatter and write to /dev/null
25
- orig_stdout = $stdout.clone
26
- orig_stderr = $stderr.clone
27
- begin
28
- $stdout.reopen(@pipefile, "w")
29
- $stderr.reopen(@pipefile, "w")
30
- RSpec::Core::Runner.run(paths)
31
- ensure
32
- $stdout.reopen(orig_stdout)
33
- $stderr.reopen(orig_stderr)
34
- end
36
+ # orig_stdout = $stdout.clone
37
+ # orig_stderr = $stderr.clone
38
+ # begin
39
+ # $stdout.reopen(@pipefile, "w")
40
+ # $stderr.reopen(@pipefile, "w")
41
+ # ::RSpec::Core::Runner.run(paths)
42
+ # ensure
43
+ # $stdout.reopen(orig_stdout)
44
+ # $stderr.reopen(orig_stderr)
45
+ # end
35
46
  else
36
- RSpec::Core::Runner.run(paths)
47
+ ::RSpec::Core::Runner.run(rspec_arguments(paths, @options))
48
+ end
49
+ end
50
+
51
+ def parsed_or_default_formatter
52
+ @parsed_or_default_formatter ||= begin
53
+ file_name = "#{Dir.pwd}/.rspec"
54
+ parsed_formatter = if File.exist?(file_name)
55
+ formatters = File.read(file_name).scan(formatter_regex).flatten
56
+ formatters.map { |formatter| "-f #{formatter}" }.join(' ')
57
+ end
58
+
59
+ parsed_formatter.nil? || parsed_formatter.empty? ? '-fprogress' : parsed_formatter
60
+ end
61
+ end
62
+
63
+ private
64
+
65
+ def rspec_arguments(paths, options)
66
+ arg_parts = []
67
+ # arg_parts << options[:cli]
68
+ if @options[:notification]
69
+ arg_parts << parsed_or_default_formatter unless options[:cli] =~ formatter_regex
70
+ # arg_parts << "-r #{File.dirname(__FILE__)}/formatters/notification_rspec.rb"
71
+ arg_parts << "-fGuard::JRubyRSpec::Formatter::NotificationRSpec"
72
+ arg_parts << "-o/dev/null"
73
+ arg_parts << "-c"
37
74
  end
75
+ #arg_parts << "--failure-exit-code #{FAILURE_EXIT_CODE}" if failure_exit_code_supported?
76
+ arg_parts.concat(paths)
77
+ end
78
+
79
+ def formatter_regex
80
+ @formatter_regex ||= /(?:^|\s)(?:-f\s*|--format(?:=|\s+))([\w:]+)/
38
81
  end
39
82
 
40
83
  end
@@ -1,2 +1,20 @@
1
- guard 'jruby-rspec', :spec_paths => ["spec"]
1
+ guard 'jruby-rspec', :spec_paths => ["spec"] do
2
+ # You can leave this empty and jruby-rspec will not autorun,
3
+ # but it will run all specs in :spec_paths on demand
4
+
5
+ # or you can configure it just like guard-rspec
6
+ watch(%r{^spec/.+_spec\.rb$})
7
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
8
+ watch('spec/spec_helper.rb') { "spec" }
9
+
10
+ # Rails example
11
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
12
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
13
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
14
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
15
+ watch('config/routes.rb') { "spec/routing" }
16
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
17
+ # Capybara request specs
18
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
19
+ end
2
20
 
@@ -1,5 +1,5 @@
1
1
  module Guard
2
2
  module JRubyRSpecVersion
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: guard-jruby-rspec
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.1.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Joe Kutner
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-05-29 00:00:00 Z
13
+ date: 2012-05-30 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: guard
@@ -24,16 +24,27 @@ dependencies:
24
24
  type: :runtime
25
25
  version_requirements: *id001
26
26
  - !ruby/object:Gem::Dependency
27
- name: rspec
27
+ name: guard-rspec
28
28
  prerelease: false
29
29
  requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 0.7.3
35
+ type: :runtime
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: rspec
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
30
41
  none: false
31
42
  requirements:
32
43
  - - ~>
33
44
  - !ruby/object:Gem::Version
34
45
  version: "2.7"
35
46
  type: :development
36
- version_requirements: *id002
47
+ version_requirements: *id003
37
48
  description: Guard::JRuby::RSpec keeps a warmed up JVM ready to run your specs.
38
49
  email:
39
50
  - jpkutner@gmail.com
@@ -46,8 +57,10 @@ extra_rdoc_files: []
46
57
  files:
47
58
  - lib/guard-jruby-rspec.rb
48
59
  - lib/guard/jruby-rspec.rb
60
+ - lib/guard/jruby-rspec/inspector.rb
49
61
  - lib/guard/jruby-rspec/runner.rb
50
62
  - lib/guard/jruby-rspec/version.rb
63
+ - lib/guard/jruby-rspec/formatters/notification_rspec.rb
51
64
  - lib/guard/jruby-rspec/templates/Guardfile
52
65
  - LICENSE
53
66
  - README.md