better finding of spec lines
This commit is contained in:
parent
3c4e557517
commit
e72eaef7a1
@ -16,6 +16,11 @@ guard 'rspec', :version => 2, :all_on_start => false do
|
||||
watch('spec/spec_helper.rb') { "spec" }
|
||||
end
|
||||
|
||||
guard 'jasmine-headless-webkit', :all_on_start => false do
|
||||
watch(%r{^spec/javascripts/.+_spec\.coffee})
|
||||
watch(%r{^jasmine/(.+)\.coffee$}) { |m| "spec/javascripts/#{m[1]}_spec.coffee" }
|
||||
end
|
||||
|
||||
def compile
|
||||
system %{cd ext/jasmine-webkit-specrunner && ruby extconf.rb}
|
||||
end
|
||||
|
@ -1,7 +1,7 @@
|
||||
if !jasmine?
|
||||
throw new Error("jasmine not laoded!")
|
||||
|
||||
class HeadlessReporterResult
|
||||
class window.HeadlessReporterResult
|
||||
constructor: (@name, @splitName) ->
|
||||
@results = []
|
||||
addResult: (message) ->
|
||||
@ -18,11 +18,21 @@ class HeadlessReporterResult
|
||||
_findSpecLine: ->
|
||||
bestChoice = { accuracy: 0, file: null, lineNumber: null }
|
||||
|
||||
for file, lines of SPEC_LINE_NUMBERS
|
||||
for file, lines of HeadlessReporterResult.specLineNumbers
|
||||
index = 0
|
||||
while newLineNumber = lines[@splitName[index]]
|
||||
lineNumber = 0
|
||||
while newLineNumberInfo = lines[@splitName[index]]
|
||||
if newLineNumberInfo.length == 0
|
||||
lineNumber = newLineNumberInfo[0]
|
||||
else
|
||||
lastLine = null
|
||||
for line in newLineNumberInfo
|
||||
lastLine = line
|
||||
break if line > lineNumber
|
||||
|
||||
lineNumber = lastLine
|
||||
|
||||
index++
|
||||
lineNumber = newLineNumber
|
||||
|
||||
if index > bestChoice.accuracy
|
||||
bestChoice = { accuracy: index, file: file, lineNumber: lineNumber }
|
||||
|
@ -1,10 +1,9 @@
|
||||
(function() {
|
||||
var HeadlessReporterResult;
|
||||
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
||||
if (!(typeof jasmine !== "undefined" && jasmine !== null)) {
|
||||
throw new Error("jasmine not laoded!");
|
||||
}
|
||||
HeadlessReporterResult = (function() {
|
||||
window.HeadlessReporterResult = (function() {
|
||||
function HeadlessReporterResult(name, splitName) {
|
||||
this.name = name;
|
||||
this.splitName = splitName;
|
||||
@ -32,18 +31,32 @@
|
||||
return _results;
|
||||
};
|
||||
HeadlessReporterResult.prototype._findSpecLine = function() {
|
||||
var bestChoice, file, index, lineNumber, lines, newLineNumber;
|
||||
var bestChoice, file, index, lastLine, line, lineNumber, lines, newLineNumberInfo, _i, _len, _ref;
|
||||
bestChoice = {
|
||||
accuracy: 0,
|
||||
file: null,
|
||||
lineNumber: null
|
||||
};
|
||||
for (file in SPEC_LINE_NUMBERS) {
|
||||
lines = SPEC_LINE_NUMBERS[file];
|
||||
_ref = HeadlessReporterResult.specLineNumbers;
|
||||
for (file in _ref) {
|
||||
lines = _ref[file];
|
||||
index = 0;
|
||||
while (newLineNumber = lines[this.splitName[index]]) {
|
||||
lineNumber = 0;
|
||||
while (newLineNumberInfo = lines[this.splitName[index]]) {
|
||||
if (newLineNumberInfo.length === 0) {
|
||||
lineNumber = newLineNumberInfo[0];
|
||||
} else {
|
||||
lastLine = null;
|
||||
for (_i = 0, _len = newLineNumberInfo.length; _i < _len; _i++) {
|
||||
line = newLineNumberInfo[_i];
|
||||
lastLine = line;
|
||||
if (line > lineNumber) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
lineNumber = lastLine;
|
||||
}
|
||||
index++;
|
||||
lineNumber = newLineNumber;
|
||||
}
|
||||
if (index > bestChoice.accuracy) {
|
||||
bestChoice = {
|
||||
|
@ -21,11 +21,15 @@ module Jasmine
|
||||
|
||||
class << self
|
||||
def get_spec_line_numbers(file)
|
||||
Hash[file.lines.each_with_index.collect { |line, index|
|
||||
line_numbers = {}
|
||||
|
||||
file.lines.each_with_index.each { |line, index|
|
||||
if description = line[%r{(describe|context|it)[( ]*(["'])(.*)\2}, 3]
|
||||
[ description, index + 1 ]
|
||||
(line_numbers[description] ||= []) << (index + 1)
|
||||
end
|
||||
}.compact]
|
||||
}
|
||||
|
||||
line_numbers
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -34,7 +34,7 @@ module Jasmine
|
||||
</script>
|
||||
#{files.join("\n")}
|
||||
<script type="text/javascript">
|
||||
SPEC_LINE_NUMBERS = #{MultiJson.encode(spec_lines)};
|
||||
HeadlessReporterResult.specLineNumbers = #{MultiJson.encode(spec_lines)};
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
16
spec/javascripts/jasmine.headless-reporter_spec.coffee
Normal file
16
spec/javascripts/jasmine.headless-reporter_spec.coffee
Normal file
@ -0,0 +1,16 @@
|
||||
describe 'HeadlessReporterResult', ->
|
||||
beforeEach ->
|
||||
HeadlessReporterResult.specLineNumbers = {
|
||||
'one': {
|
||||
'name': [ 1 ],
|
||||
'of': [ 2, 9 ],
|
||||
'test': [ 3, 10 ],
|
||||
'other': [ 7 ]
|
||||
}
|
||||
}
|
||||
it 'should find the best spec lines', ->
|
||||
result = new HeadlessReporterResult('test', [ 'name', 'of', 'test' ])
|
||||
expect(result._findSpecLine().lineNumber).toEqual(3)
|
||||
|
||||
result = new HeadlessReporterResult('test', [ 'other', 'of', 'test' ])
|
||||
expect(result._findSpecLine().lineNumber).toEqual(10)
|
5
spec/javascripts/support/jasmine.yml
Normal file
5
spec/javascripts/support/jasmine.yml
Normal file
@ -0,0 +1,5 @@
|
||||
src_files: [ 'jasmine/*.coffee' ]
|
||||
spec_files: [ 'spec/javascripts/*_spec.coffee' ]
|
||||
src_dir: .
|
||||
spec_dir: .
|
||||
|
@ -223,9 +223,9 @@ describe 'test', ->
|
||||
end
|
||||
|
||||
it 'should get the line numbers' do
|
||||
line_numbers['test'].should == 1
|
||||
line_numbers['yes'].should == 2
|
||||
line_numbers['should do something'].should == 3
|
||||
line_numbers['test'].should == [ 1 ]
|
||||
line_numbers['yes'].should == [ 2 ]
|
||||
line_numbers['should do something'].should == [ 3 ]
|
||||
end
|
||||
end
|
||||
|
||||
@ -243,9 +243,9 @@ describe('test', function() {
|
||||
end
|
||||
|
||||
it 'should get the line numbers' do
|
||||
line_numbers['test'].should == 1
|
||||
line_numbers['yes'].should == 2
|
||||
line_numbers['should do something'].should == 3
|
||||
line_numbers['test'].should == [ 1 ]
|
||||
line_numbers['yes'].should == [ 2 ]
|
||||
line_numbers['should do something'].should == [ 3 ]
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -259,13 +259,13 @@ describe('test', function() {
|
||||
'test2.coffee'
|
||||
])
|
||||
|
||||
File.open('test.coffee', 'w') { |fh| fh.print "describe('cat')" }
|
||||
File.open('test.coffee', 'w') { |fh| fh.print "describe('cat')\ndescribe('cat')" }
|
||||
File.open('test2.coffee', 'w') { |fh| fh.print "no matches" }
|
||||
end
|
||||
|
||||
it 'should generate filenames and line number info' do
|
||||
files_list.spec_file_line_numbers.should == {
|
||||
'test.coffee' => { 'cat' => 1 }
|
||||
'test.coffee' => { 'cat' => [ 1, 2 ] }
|
||||
}
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user