10
May
09

TextMate: lstat – No such file or directory

Sometimes in TextMate I get exceptions like this when trying to run unit tests:

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/pathname.rb:420:in `lstat': No such file or directory - /Users/evgeny/Projects/project/test/unit/test (Errno::ENOENT) from
<... stack trace skipped ...> 

The exception above is caused by the call to realpath() in path_to_url_chunk() in Bundles/Ruby.tmbundle/Support/RubyMate/run_script.rb.

def path_to_url_chunk(path)
  unless path == "untitled"
    file = Pathname.new(path).realpath.to_s
    "url=file://#{e_url(path)}&"
  else
    ''
  end
end

There are two problems here. First, the file variable is not used, so the hyperlink to the failed method in textmate output would be broken as a result. Second, realpath() raises an exception because for some reason (I didn’t dig deeper) the current directory is ‘/path/to/test/unit’ and path is ‘test/unit/my_test.rb’, so realpath() can’t find the test.

The modified version of the function works better:

def path_to_url_chunk(path)
unless path == "untitled"
Dir.chdir "../.."
file = Pathname.new(path).realpath.to_s
"url=file://#{e_url(file)}&"
else
''
end
end

It’s not a proper solution because the either the file path or the working directory should be corrected before this function is called. If you know a better solution to this problem, please leave a comment.


6 Responses to “TextMate: lstat – No such file or directory”


  1. 1 Tim Payton
    June 5, 2009 at 12:23 pm

    This worked for me… Thank you very much. Very nice to not have this popup form time to time and then be forced to work from the command line :)

  2. 2 Paul Ingles
    June 8, 2009 at 5:30 pm

    We’ve struggled with the same thing, although the fix above broke for some other spurious reason. Here’s the implementation we ended up with:

    def path_to_url_chunk(path)
    unless path == “untitled”
    prefix = ”
    2.times do
    begin
    file = Pathname.new(prefix + path).realpath.to_s
    “url=file://#{e_url(file)}&”
    rescue Errno::ENOENT
    # Hmm lets try to prefix with project directory
    prefix = “#{ENV['TM_PROJECT_DIRECTORY']}/”
    end
    end
    else

    end
    end

  3. 3 Stephen Best
    June 9, 2009 at 3:10 pm

    Thanks so much, been putting up with this when running failing tests for a while, finally today I felt like I had to do something about it.

    In case anyone is having trouble with the old

    `require’: no such file to load — test_helper (LoadError)

    when running tests on the command line should set this environment variable
    RUBYLIB=”.:test:$RUBYLIB”

  4. 5 Yi Lin
    August 17, 2009 at 4:55 pm

    I ran into the same problem. It occurred in my Rails unit test when I added an assert_raise clause. Turns out there’s already a patch for it in Ruby bundle for TextMate:

    http://www.nabble.com/Patch-for-RubyMate:-‘No-such-file-or-directory’-when-backtrace-contains-eval-td21506903.html

    So I installed the latest bundle off of trunk and problem solved. Did this work for you?


Leave a Reply




May 2009
M T W T F S S
    Jun »
 123
45678910
11121314151617
18192021222324
25262728293031