From 363ee91b6b3edbab7d751ecaceda09b816e85bfb Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 6 Sep 2011 16:48:19 -0400 Subject: [PATCH] better support for when we don't know spec line location --- jasmine/jasmine.headless-reporter.coffee | 5 ++++- jasmine/jasmine.headless-reporter.js | 6 +++++- lib/jasmine/headless/report.rb | 5 +++-- lib/jasmine/headless/report_message/spec.rb | 6 +++++- .../jasmine.headless-reporter_spec.coffee | 7 +++++++ .../headless/report_message/spec_spec.rb | 17 +++++++++++++---- spec/lib/jasmine/headless/report_spec.rb | 13 +++++++++++++ 7 files changed, 50 insertions(+), 9 deletions(-) diff --git a/jasmine/jasmine.headless-reporter.coffee b/jasmine/jasmine.headless-reporter.coffee index 59c56f0..a98bdbc 100644 --- a/jasmine/jasmine.headless-reporter.coffee +++ b/jasmine/jasmine.headless-reporter.coffee @@ -18,7 +18,10 @@ jasmine.Spec.prototype.getSplitName = getSplitName jasmine.Spec.prototype.getJHWSpecInformation = -> parts = this.getSpecSplitName() specLineInfo = HeadlessReporterResult.findSpecLine(parts) - parts.push("#{specLineInfo.file}:#{specLineInfo.lineNumber}") + if specLineInfo.file + parts.push("#{specLineInfo.file}:#{specLineInfo.lineNumber}") + else + parts.push('') parts.join("||") if !jasmine.WaitsBlock.prototype._execute diff --git a/jasmine/jasmine.headless-reporter.js b/jasmine/jasmine.headless-reporter.js index 17e018c..04268e6 100644 --- a/jasmine/jasmine.headless-reporter.js +++ b/jasmine/jasmine.headless-reporter.js @@ -19,7 +19,11 @@ var parts, specLineInfo; parts = this.getSpecSplitName(); specLineInfo = HeadlessReporterResult.findSpecLine(parts); - parts.push("" + specLineInfo.file + ":" + specLineInfo.lineNumber); + if (specLineInfo.file) { + parts.push("" + specLineInfo.file + ":" + specLineInfo.lineNumber); + } else { + parts.push(''); + } return parts.join("||"); }; if (!jasmine.WaitsBlock.prototype._execute) { diff --git a/lib/jasmine/headless/report.rb b/lib/jasmine/headless/report.rb index 4e2b5ae..ab05c35 100644 --- a/lib/jasmine/headless/report.rb +++ b/lib/jasmine/headless/report.rb @@ -21,7 +21,8 @@ module Jasmine::Headless def process @report = File.readlines(file).collect do |line| - type, *parts = line.split('||') + type, *parts = line.split('||', -1) + parts.last.strip! Jasmine::Headless::ReportMessage.const_get( Jasmine::Headless::ReportMessage.constants.find { |k| k.to_s.downcase == type.downcase } @@ -49,7 +50,7 @@ module Jasmine::Headless def failed_files @report.find_all { |entry| entry.kind_of?(Jasmine::Headless::ReportMessage::Fail) - }.collect(&:filename).uniq + }.collect(&:filename).uniq.compact end private diff --git a/lib/jasmine/headless/report_message/spec.rb b/lib/jasmine/headless/report_message/spec.rb index 099f444..63c5b54 100644 --- a/lib/jasmine/headless/report_message/spec.rb +++ b/lib/jasmine/headless/report_message/spec.rb @@ -19,7 +19,11 @@ module Jasmine::Headless::ReportMessage end def filename - file_info.split(":").first + if name = file_info.split(":").first + name + else + nil + end end end end diff --git a/spec/javascripts/jasmine.headless-reporter_spec.coffee b/spec/javascripts/jasmine.headless-reporter_spec.coffee index bd70b45..64e291b 100644 --- a/spec/javascripts/jasmine.headless-reporter_spec.coffee +++ b/spec/javascripts/jasmine.headless-reporter_spec.coffee @@ -61,6 +61,13 @@ describe 'jasmine.Spec.prototype.getSuiteSplitName', -> spec.description = 1 expect(spec.getSpecSplitName()).toEqual([ "1" ]) +describe 'jasmine.Spec.prototype.getJHWSpecInformation', -> + it 'should append null when there is no file information', -> + spec = new jasmine.Spec({}, {}) + spyOn(spec, 'getSpecSplitName').andReturn(["one"]) + spyOn(HeadlessReporterResult, 'findSpecLine').andReturn({}) + expect(spec.getJHWSpecInformation()).toEqual("one||") + describe 'jasmine.WaitsBlock and jasmine.WaitsForBlock', -> beforeEach -> it 'should notify JHW of waiting', -> diff --git a/spec/lib/jasmine/headless/report_message/spec_spec.rb b/spec/lib/jasmine/headless/report_message/spec_spec.rb index 8642f2e..dfdef29 100644 --- a/spec/lib/jasmine/headless/report_message/spec_spec.rb +++ b/spec/lib/jasmine/headless/report_message/spec_spec.rb @@ -1,11 +1,20 @@ require 'spec_helper' describe Jasmine::Headless::ReportMessage::Spec do - let(:filename) { 'file.js' } - let(:spec) { described_class.new("Test", "#{filename}:23") } - subject { spec } - its(:filename) { should == filename } + context 'with filename' do + let(:filename) { 'file.js' } + let(:spec) { described_class.new("Test", "#{filename}:23") } + + its(:filename) { should == filename } + end + + context 'without filename' do + let(:filename) { 'file.js' } + let(:spec) { described_class.new("Test", "") } + + its(:filename) { should be_nil } + end end diff --git a/spec/lib/jasmine/headless/report_spec.rb b/spec/lib/jasmine/headless/report_spec.rb index 2f4d9c4..c97d8ae 100644 --- a/spec/lib/jasmine/headless/report_spec.rb +++ b/spec/lib/jasmine/headless/report_spec.rb @@ -47,6 +47,19 @@ REPORT report.failed_files.should == [ 'file2.js' ] end end + + context 'nil filed file' do + before do + File.open(file, 'wb') { |fh| fh.puts <<-REPORT } +FAIL||Statement||Two|| +TOTAL||1||2||3||T +REPORT + end + + it 'should read the report file' do + report.failed_files.should == [] + end + end end end