guard-jruby-rspec 0.1.8 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/guard/jruby-rspec.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'guard'
|
2
2
|
require 'guard/guard'
|
3
3
|
require 'guard/rspec'
|
4
|
+
require 'guard/jruby-rspec/reloaders'
|
4
5
|
|
5
6
|
module Guard
|
6
7
|
class JRubyRSpec < ::Guard::RSpec
|
@@ -15,7 +16,8 @@ module Guard
|
|
15
16
|
:spec_paths => ["spec"],
|
16
17
|
:spec_file_suffix => "_spec.rb",
|
17
18
|
:run_all => {},
|
18
|
-
:monitor_file => ".guard-jruby-rspec"
|
19
|
+
:monitor_file => ".guard-jruby-rspec",
|
20
|
+
:custom_reloaders => []
|
19
21
|
}.merge(options)
|
20
22
|
@last_failed = false
|
21
23
|
@failed_paths = []
|
@@ -41,7 +43,7 @@ module Guard
|
|
41
43
|
|
42
44
|
@inspector = Inspector.new(@options)
|
43
45
|
@runner = Runner.new(@options)
|
44
|
-
|
46
|
+
@reloaders = set_up_reloaders(@options)
|
45
47
|
end
|
46
48
|
|
47
49
|
# Call once when guard starts
|
@@ -50,8 +52,14 @@ module Guard
|
|
50
52
|
run_all if @options[:all_on_start]
|
51
53
|
end
|
52
54
|
|
55
|
+
def run_all
|
56
|
+
unload_previous_examples
|
57
|
+
super
|
58
|
+
end
|
59
|
+
|
53
60
|
def run_on_changes(raw_paths)
|
54
|
-
|
61
|
+
unload_previous_examples
|
62
|
+
@reloaders.reload(raw_paths)
|
55
63
|
|
56
64
|
unless @custom_watchers.nil? or @custom_watchers.empty?
|
57
65
|
paths = []
|
@@ -69,6 +77,13 @@ module Guard
|
|
69
77
|
# Guard 1.1 renamed run_on_change to run_on_changes
|
70
78
|
alias_method :run_on_change, :run_on_changes
|
71
79
|
|
80
|
+
def reload_rails(*)
|
81
|
+
if defined? ::ActionDispatch::Reloader
|
82
|
+
ActionDispatch::Reloader.cleanup!
|
83
|
+
ActionDispatch::Reloader.prepare!
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
72
87
|
def reload_paths(paths)
|
73
88
|
paths.reject {|p| p.end_with?(@options[:spec_file_suffix])}.each do |p|
|
74
89
|
if File.exists?(p)
|
@@ -85,18 +100,30 @@ module Guard
|
|
85
100
|
# end
|
86
101
|
else
|
87
102
|
# reload the file
|
88
|
-
|
103
|
+
Containment.new.protect do
|
89
104
|
load p
|
90
|
-
rescue
|
91
|
-
UI.error $!.message
|
92
|
-
UI.error $!.backtrace.join "\n"
|
93
|
-
throw :task_has_failed
|
94
105
|
end
|
95
106
|
end
|
96
107
|
end
|
97
108
|
end
|
98
109
|
end
|
99
110
|
|
111
|
+
private
|
112
|
+
|
113
|
+
def set_up_reloaders(options)
|
114
|
+
reloaders = Reloaders.new
|
115
|
+
reloader_methods = [:reload_rails, :reload_paths]
|
116
|
+
reloader_procs = reloader_methods.map { |name| method(name) }
|
117
|
+
reloader_procs += options[:custom_reloaders]
|
118
|
+
reloader_procs.each { |reloader| reloaders.register &reloader }
|
119
|
+
|
120
|
+
reloaders
|
121
|
+
end
|
122
|
+
|
123
|
+
def unload_previous_examples
|
124
|
+
::RSpec.configuration.reset
|
125
|
+
::RSpec.world.reset
|
126
|
+
end
|
100
127
|
end
|
101
128
|
end
|
102
129
|
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Guard
|
2
|
+
class JRubyRSpec
|
3
|
+
class Containment
|
4
|
+
def initialize(options = {})
|
5
|
+
@error_handler = options.fetch(:error_handler, method(:output_as_guard_error))
|
6
|
+
end
|
7
|
+
|
8
|
+
def protect
|
9
|
+
yield
|
10
|
+
rescue Exception => e
|
11
|
+
error_handler.call e
|
12
|
+
throw :task_has_failed
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
attr_reader :error_handler
|
18
|
+
|
19
|
+
def output_as_guard_error(exception)
|
20
|
+
UI.error $!.message
|
21
|
+
UI.error $!.backtrace.join "\n"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class Reloaders
|
2
|
+
def initialize
|
3
|
+
@reloaders = []
|
4
|
+
end
|
5
|
+
|
6
|
+
# Add a reloader to be called on reload
|
7
|
+
def register(options = {}, &block)
|
8
|
+
if options[:prepend]
|
9
|
+
@reloaders.unshift block
|
10
|
+
else
|
11
|
+
@reloaders << block
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def reload(paths = [])
|
16
|
+
@reloaders.each do |reloader|
|
17
|
+
reloader.call(paths)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'rspec'
|
2
|
+
require 'guard/jruby-rspec/containment'
|
2
3
|
require 'guard/jruby-rspec/formatters/notification_rspec'
|
3
4
|
|
4
5
|
module Guard
|
@@ -44,13 +45,10 @@ module Guard
|
|
44
45
|
# end
|
45
46
|
else
|
46
47
|
orig_configuration = ::RSpec.configuration
|
47
|
-
|
48
|
+
Containment.new.protect do
|
48
49
|
::RSpec::Core::Runner.run(rspec_arguments(paths, @options))
|
49
|
-
rescue SyntaxError => e
|
50
|
-
UI.error e.message
|
51
|
-
ensure
|
52
|
-
::RSpec.instance_variable_set(:@configuration, orig_configuration)
|
53
50
|
end
|
51
|
+
::RSpec.instance_variable_set(:@configuration, orig_configuration)
|
54
52
|
end
|
55
53
|
end
|
56
54
|
|
@@ -83,7 +81,6 @@ module Guard
|
|
83
81
|
def formatter_regex
|
84
82
|
@formatter_regex ||= /(?:^|\s)(?:-f\s*|--format(?:=|\s+))([\w:]+)/
|
85
83
|
end
|
86
|
-
|
87
84
|
end
|
88
85
|
end
|
89
86
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guard-jruby-rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: guard
|
@@ -68,7 +68,9 @@ extra_rdoc_files: []
|
|
68
68
|
files:
|
69
69
|
- lib/guard-jruby-rspec.rb
|
70
70
|
- lib/guard/jruby-rspec.rb
|
71
|
+
- lib/guard/jruby-rspec/containment.rb
|
71
72
|
- lib/guard/jruby-rspec/inspector.rb
|
73
|
+
- lib/guard/jruby-rspec/reloaders.rb
|
72
74
|
- lib/guard/jruby-rspec/runner.rb
|
73
75
|
- lib/guard/jruby-rspec/version.rb
|
74
76
|
- lib/guard/jruby-rspec/formatters/notification_rspec.rb
|