diff --git a/lib/jasmine/headless/spec_file_analyzer.rb b/lib/jasmine/headless/spec_file_analyzer.rb index 0ac0899..f32308d 100644 --- a/lib/jasmine/headless/spec_file_analyzer.rb +++ b/lib/jasmine/headless/spec_file_analyzer.rb @@ -14,7 +14,7 @@ module Jasmine::Headless data = File.read(file) if data.respond_to?(:encode) - data.encode!('US-ASCII', 'UTF-8', :invalid => :replace) + data.encode!('US-ASCII', 'UTF-8', :invalid => :replace, :undef => :replace) else require 'iconv' ic = Iconv.new('UTF-8//IGNORE', 'US-ASCII') diff --git a/spec/files/UTF-8-test.txt b/spec/files/UTF-8-test.txt new file mode 100644 index 0000000..abd16f7 Binary files /dev/null and b/spec/files/UTF-8-test.txt differ diff --git a/spec/lib/jasmine/headless/spec_file_analyzer_spec.rb b/spec/lib/jasmine/headless/spec_file_analyzer_spec.rb index fbde25c..5a5dd72 100644 --- a/spec/lib/jasmine/headless/spec_file_analyzer_spec.rb +++ b/spec/lib/jasmine/headless/spec_file_analyzer_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' describe Jasmine::Headless::SpecFileAnalyzer do - include FakeFS::SpecHelpers let(:file) { 'file' } let(:analyzer) { described_class.new(file) } @@ -11,45 +10,57 @@ describe Jasmine::Headless::SpecFileAnalyzer do analyzer.action end - before do - File.open(file, 'wb') { |fh| fh.print file_data } - end + context 'fake files' do + include FakeFS::SpecHelpers - context 'coffeescript' do - let(:file_data) do - <<-SPEC -describe 'test', -> - context 'yes', -> - it 'should do something', -> - "yes" - "PR.registerLangHandler(PR.createSimpleLexer([[\"com\",/^#[^\\n\\r]*/,null,\"#\"],[\"pln\",/^[\\t\\n\\r \\xa0]+/,null,\"\\t\\n\\r \xC2\\xa0\"],[\"str\",/^\"(?:[^\"\\\\]|\\\\[\\S\\s])*(?:\"|$)/,null,'\"']],[[\"kwd\",/^(?:ADS|AD|AUG|BZF|BZMF|CAE|CAF|CA|CCS|COM|CS|DAS|DCA|DCOM|DCS|DDOUBL|DIM|DOUBLE|DTCB|DTCF|DV|DXCH|EDRUPT|EXTEND|INCR|INDEX|NDX|INHINT|LXCH|MASK|MSK|MP|MSU|NOOP|OVSK|QXCH|RAND|READ|RELINT|RESUME|RETURN|ROR|RXOR|SQUARE|SU|TCR|TCAA|OVSK|TCF|TC|TS|WAND|WOR|WRITE|XCH|XLQ|XXALQ|ZL|ZQ|ADD|ADZ|SUB|SUZ|MPY|MPR|MPZ|DVP|COM|ABS|CLA|CLZ|LDQ|STO|STQ|ALS|LLS|LRS|TRA|TSQ|TMI|TOV|AXT|TIX|DLY|INP|OUT)\\s/,\n" -SPEC + before do + File.open(file, 'wb') { |fh| fh.print file_data } 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 ] + context 'coffeescript' do + let(:file_data) do + <<-SPEC + describe 'test', -> + context 'yes', -> + it 'should do something', -> + "yes" + SPEC + 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 ] + end end - end - context 'javascript' do - let(:file_data) do - <<-SPEC -describe('test', function() { - context('yes', function() { - it('should do something', function() { + context 'javascript' do + let(:file_data) do + <<-SPEC + describe('test', function() { + context('yes', function() { + it('should do something', function() { + }); }); }); -}); -SPEC - end + SPEC + 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 ] + it 'should get the line numbers' do + line_numbers['test'].should == [ 1 ] + line_numbers['yes'].should == [ 2 ] + line_numbers['should do something'].should == [ 3 ] + end + end + end + + context 'utf 8' do + let(:analyzer) { described_class.new('spec/files/UTF-8-test.txt') } + let(:file_data) { '' } + + it 'should not explode' do + line_numbers end end end