Skip to content

Commit

Permalink
Rescue invalid byte sequence exception
Browse files Browse the repository at this point in the history
  • Loading branch information
Dalibor Nasevic and Sachin Ranchod authored and dalibor committed Sep 4, 2012
1 parent 2bd9adf commit cb1f18a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/should_clean/replacer.rb
Expand Up @@ -13,6 +13,8 @@ def initialize(file_path)
end

def run
return unless content.valid_encoding?

tmp_file = Tempfile.new('tmp.txt')

content.each_line.each do |line|
Expand Down
2 changes: 2 additions & 0 deletions lib/should_clean/simulator.rb
Expand Up @@ -13,6 +13,8 @@ def initialize(file_path, buffer = $stdout)
end

def run
return unless content.valid_encoding?

content.each_line.each do |line|
if line.strip.match(MATCHER)
cleaned = Cleaner.clean(line)
Expand Down
12 changes: 12 additions & 0 deletions spec/fixtures/broken_spec.txt
@@ -0,0 +1,12 @@
require File.dirname(__FILE__) + '/../../../spec_helper'

describe Notification do

it "should instantiate a notification for a given transaction ����" do
notification = BankStatement::Notification.for(:transaction => @transaction)
notification.is_a?(BankStatement::Notification).should be_true
notification.transaction.should == @transaction
end
end

hפ���g�<� ��x?name(__FILE__) + '/../../../spec_helper'
6 changes: 6 additions & 0 deletions spec/should_clean/replacer_spec.rb
Expand Up @@ -22,4 +22,10 @@
replacer.run
FileUtils.compare_file(spec_file, correct_spec_file).should be_true
end

it "does not raise exception when file has invalid encoding" do
spec_file = File.join(File.dirname(__FILE__), '..', 'fixtures', 'broken_spec.txt')
replacer = ShouldClean::Replacer.new(spec_file)
lambda { replacer.run }.should_not raise_exception(ArgumentError)
end
end
7 changes: 7 additions & 0 deletions spec/should_clean/simulator_spec.rb
Expand Up @@ -17,4 +17,11 @@
+ it %{does something} do
eos
end

it "does not raise exception when file has invalid encoding" do
spec_file = File.join(File.dirname(__FILE__), '..', 'fixtures', 'broken_spec.txt')
buffer = StringIO.new
simulator = ShouldClean::Simulator.new(spec_file, buffer)
lambda { simulator.run }.should_not raise_exception(ArgumentError)
end
end

0 comments on commit cb1f18a

Please sign in to comment.