Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running test from TextMate in a Rails 3 project #13

Open
galaxycats opened this issue Feb 11, 2010 · 1 comment
Open

Running test from TextMate in a Rails 3 project #13

galaxycats opened this issue Feb 11, 2010 · 1 comment
Labels

Comments

@galaxycats
Copy link

Hi folks,

there is an issue running test cases with Command-R in a Rails 3 project. I got the following error doing it:

Errno::ENOENT: No such file or directory - /Users/dbreuer/path/to/rails3app/test/functional/config/database.yml

I digged into it and localized the "source" of the problem is concerned with the way Rails 3 sets it root path. In the file railties-3.0.0.beta/lib/rails/engine.rb the root path localization method is as follows:

15       def inherited(base)
16         unless abstract_railtie?(base)
17           base.called_from = begin
18             call_stack = caller.map { |p| p.split(':').first }
19             File.dirname(call_stack.detect { |p| p !~ %r[railties/lib/rails|rack/lib/rack] })
20           end
21         end
22 
23         super
24       end
25 
26       def find_root_with_flag(flag, default=nil)
27         root_path = self.called_from
28         
29         while root_path && File.directory?(root_path) && !File.exist?("#{root_path}/#{flag}")
30           parent = File.dirname(root_path)
31           root_path = parent != root_path && parent
32         end
33 
34         root = File.exist?("#{root_path}/#{flag}") ? root_path : default
35         raise "Could not find root path for #{self}" unless root
36         
37         RUBY_PLATFORM =~ /(:?mswin|mingw)/ ?
38           Pathname.new(root).expand_path : Pathname.new(root).realpath
39       end

The variable called_from in line 27 points in my case always to the gem directory (which seems to be quite obvious to me). But then it will take always the default parameter as the root directory, which is Dir.pwd as specified in railties-3.0.0.beta/lib/rails/application/configurable.rb:

@config ||= Application::Configuration.new(self.class.find_root_with_flag("config.ru", Dir.pwd))

You could assign the default parameter as the root_path which will result in the correct resolution for the root variable and so in a successful execution of my test execution out of TextMate. But obviously that isn't the best thing to do. You could try first the called_from value and after that the default value to find the root directory but that isn't much better in my opinion. What I ask myself, there must be reason why it is as it is, and you should probably find a way to handle this in the TextMate Rails bundle. But I have no idea how to accomplish this.

@elitau
Copy link

elitau commented Feb 28, 2010

Hay railsbros,

i have the same problem with TextMate and Rails 3 Tests.
For me this seems to be a problem of Rails. As you pointed out, it is only possible to run tests from the root of your project which is kind of inappropriate to me - but i am not deep enough in the rails 3.0 code to judge this.

My solution for this problem is to change the working directory before running the script in the run command of the Ruby bundle in TextMate like this:

#!/bin/sh

export RUBYLIB="$TM_BUNDLE_SUPPORT/RubyMate${RUBYLIB:+:$RUBYLIB}"
export TM_RUBY=$(type -p "${TM_RUBY:-ruby}")

cd "${TM_PROJECT_DIRECTORY:-$TM_DIRECTORY}"

"${TM_RUBY}" -- "$TM_BUNDLE_SUPPORT/RubyMate/run_script.rb"

The environment variable is taken from the TextMate Help:
TM_PROJECT_DIRECTORY — the top-level folder in the project drawer (may not be set).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant