hydra 0.17.0 → 0.18.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/VERSION +1 -1
- data/hydra.gemspec +5 -2
- data/lib/hydra/js/lint.js +5150 -0
- data/lib/hydra/runner.rb +45 -2
- data/test/fixtures/js_file.js +4 -0
- data/test/fixtures/json_data.json +4 -0
- data/test/runner_test.rb +12 -0
- data/test/test_helper.rb +8 -0
- metadata +6 -3
data/lib/hydra/runner.rb
CHANGED
@@ -35,10 +35,12 @@ module Hydra #:nodoc:
|
|
35
35
|
trace "Running file: #{file}"
|
36
36
|
|
37
37
|
output = ""
|
38
|
-
if file =~ /_spec.rb$/
|
38
|
+
if file =~ /_spec.rb$/i
|
39
39
|
output = run_rspec_file(file)
|
40
|
-
elsif file =~ /.feature$/
|
40
|
+
elsif file =~ /.feature$/i
|
41
41
|
output = run_cucumber_file(file)
|
42
|
+
elsif file =~ /.js$/i or file =~ /.json$/i
|
43
|
+
output = run_javascript_file(file)
|
42
44
|
else
|
43
45
|
output = run_test_unit_file(file)
|
44
46
|
end
|
@@ -175,6 +177,47 @@ module Hydra #:nodoc:
|
|
175
177
|
return hydra_response.read
|
176
178
|
end
|
177
179
|
|
180
|
+
def run_javascript_file(file)
|
181
|
+
errors = []
|
182
|
+
require 'v8'
|
183
|
+
V8::Context.open do |context|
|
184
|
+
context.load(File.expand_path(File.join(File.dirname(__FILE__), 'js', 'lint.js')))
|
185
|
+
context['input'] = lambda{
|
186
|
+
File.read(file)
|
187
|
+
}
|
188
|
+
context['reportErrors'] = lambda{|js_errors|
|
189
|
+
js_errors.each do |e|
|
190
|
+
e = V8::To.ruby(e)
|
191
|
+
errors << "\n\e[1;31mJSLINT: #{file}\e[0m"
|
192
|
+
errors << " Error at line #{e['line'].to_i + 1} " +
|
193
|
+
"character #{e['character'].to_i + 1}: \e[1;33m#{e['reason']}\e[0m"
|
194
|
+
errors << "#{e['evidence']}"
|
195
|
+
end
|
196
|
+
}
|
197
|
+
context.eval %{
|
198
|
+
JSLINT(input(), {
|
199
|
+
sub: true,
|
200
|
+
onevar: true,
|
201
|
+
eqeqeq: true,
|
202
|
+
plusplus: true,
|
203
|
+
bitwise: true,
|
204
|
+
regexp: true,
|
205
|
+
newcap: true,
|
206
|
+
immed: true,
|
207
|
+
strict: true,
|
208
|
+
rhino: true
|
209
|
+
});
|
210
|
+
reportErrors(JSLINT.errors);
|
211
|
+
}
|
212
|
+
end
|
213
|
+
|
214
|
+
if errors.empty?
|
215
|
+
return '.'
|
216
|
+
else
|
217
|
+
return errors.join("\n")
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
178
221
|
# find all the test unit classes in a given file, so we can run their suites
|
179
222
|
def self.find_classes_in_file(f)
|
180
223
|
code = ""
|
data/test/runner_test.rb
CHANGED
@@ -37,6 +37,18 @@ class RunnerTest < Test::Unit::TestCase
|
|
37
37
|
Process.wait(child)
|
38
38
|
end
|
39
39
|
|
40
|
+
should "run a js lint file and find errors" do
|
41
|
+
runner = Hydra::Runner.new(:io => File.new('/dev/null', 'w'))
|
42
|
+
results = runner.run_file(javascript_file)
|
43
|
+
assert results =~ /Missing semicolon/
|
44
|
+
end
|
45
|
+
|
46
|
+
should "run a json data file and find errors" do
|
47
|
+
runner = Hydra::Runner.new(:io => File.new('/dev/null', 'w'))
|
48
|
+
results = runner.run_file(json_file)
|
49
|
+
assert results =~ /trailing comma/
|
50
|
+
end
|
51
|
+
|
40
52
|
should "run two rspec tests" do
|
41
53
|
runner = Hydra::Runner.new(:io => File.new('/dev/null', 'w'))
|
42
54
|
runner.run_file(rspec_file)
|
data/test/test_helper.rb
CHANGED
@@ -42,6 +42,14 @@ class Test::Unit::TestCase
|
|
42
42
|
def alternate_cucumber_feature_file
|
43
43
|
File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'features', 'write_alternate_file.feature'))
|
44
44
|
end
|
45
|
+
|
46
|
+
def javascript_file
|
47
|
+
File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'js_file.js'))
|
48
|
+
end
|
49
|
+
|
50
|
+
def json_file
|
51
|
+
File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'json_data.json'))
|
52
|
+
end
|
45
53
|
end
|
46
54
|
|
47
55
|
module Hydra #:nodoc:
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 18
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.18.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Nick Gauthier
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-28 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -84,6 +84,7 @@ files:
|
|
84
84
|
- lib/hydra.rb
|
85
85
|
- lib/hydra/cucumber/formatter.rb
|
86
86
|
- lib/hydra/hash.rb
|
87
|
+
- lib/hydra/js/lint.js
|
87
88
|
- lib/hydra/listener/abstract.rb
|
88
89
|
- lib/hydra/listener/minimal_output.rb
|
89
90
|
- lib/hydra/listener/notifier.rb
|
@@ -111,6 +112,8 @@ files:
|
|
111
112
|
- test/fixtures/features/write_alternate_file.feature
|
112
113
|
- test/fixtures/features/write_file.feature
|
113
114
|
- test/fixtures/hello_world.rb
|
115
|
+
- test/fixtures/js_file.js
|
116
|
+
- test/fixtures/json_data.json
|
114
117
|
- test/fixtures/slow.rb
|
115
118
|
- test/fixtures/sync_test.rb
|
116
119
|
- test/fixtures/write_file.rb
|