Skip to content

Commit

Permalink
Proc.to_s return ASCII string, let's change pwd string to be ascii too.
Browse files Browse the repository at this point in the history
Fixes #150.
  • Loading branch information
os97673 committed Mar 8, 2013
1 parent 83b0680 commit e95a595
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
7 changes: 7 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [Git master](https://github.com/cucumber/cucumber/compare/v1.2.3...master)

### New Features

### Bugfixes
* Fix problem with non-ascii characters in file path ([#150](https://github.com/cucumber/cucumber/issues/150) Oleg Sukhodolsky)

## [1.2.3](https://github.com/cucumber/cucumber/compare/v1.2.2...v1.2.3)

### Bugfixes
Expand Down
2 changes: 2 additions & 0 deletions lib/cucumber/core_ext/proc.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Proc extension to get more location info out of a proc
require 'cucumber/platform'
class Proc #:nodoc:
PROC_PATTERN = /[\d\w]+@(.+):(\d+).*>/
PWD = Dir.pwd
Expand All @@ -16,6 +17,7 @@ def file_colon_line
path, line = *to_s.match(PROC_PATTERN)[1..2]
path = File.expand_path(path)
pwd = File.expand_path(PWD)
pwd.force_encoding(path.encoding) unless Cucumber::RUBY_1_8_7
if path.index(pwd)
path = path[pwd.length+1..-1]
elsif path =~ /.*\/gems\/(.*\.rb)$/
Expand Down
14 changes: 13 additions & 1 deletion spec/cucumber/core_ext/proc_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
# encoding: utf-8
require 'spec_helper'
require 'cucumber/core_ext/proc'

describe Proc do
it "should remove extraneous path info for file" do
proc = lambda {|a,b|}
proc.file_colon_line.should =~ /^spec\/cucumber\/core_ext\/proc_spec\.rb:6/
proc.file_colon_line.should =~ /^spec\/cucumber\/core_ext\/proc_spec\.rb:7/
end

unless Cucumber::RUBY_1_8_7
it "should work with non-English path" do
proc = lambda {|a,b|}
def proc.to_s
"#<Proc:0x00000003c04740@#{Dir.pwd}/å/spec/cucumber/core_ext/proc_spec.rb:12 (lambda)>".force_encoding('ASCII-8BIT')
end

proc.file_colon_line.force_encoding('UTF-8').should =~ /^å\/spec\/cucumber\/core_ext\/proc_spec\.rb:12/
end
end

it "should raise ArityMismatchError for too many args (expecting 0)" do
Expand Down

0 comments on commit e95a595

Please sign in to comment.