Why isn't autotest working?
I'm trying to use autotest for Rails development. It's supposed to run my tests automatically.
Here's my setup:
$ which ruby
/usr/bin/ruby
$ ruby -v
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
$ rails -v
Rails 2.3.9
autotest-rails (4.1.0)
ZenTest (4.4.0)
$ echo $PATH
/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/Current/bin:/usr/local/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/mysql/bin:/Users/ethan/bin:/opt/local/bin:/usr/local/pgsql/bin:/usr/local/git/bin:/usr/local/oracle/instantclient_10_2
Here's the gem environment:
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.7
- RUBY VERSION: 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
- INSTALLATION DIRECTORY: /Library/Ruby/Gems/1.8
- RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
- EXECUTABLE DIRECTORY: /usr/bin
- RUBYGEMS PLATFORMS:
- ruby
- universal-darwin-10
- GEM PATHS:
- /Library/Ruby/Gems/1.8
- /Users/ethan/.gem/ruby/1.8
- /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- :sources => ["http://gemcutter.org"]
- REMOTE SOURCES:
- http://gemcutter.org
Here's the error. It looks like autotest is trying to use some other version of Ruby.
$ autotest
loading autotest/rails
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -I.:lib:test -rubygems -e "%w[test/unit test/functional/procurements_controller_test.rb].each { |f| require f }" | unit_diff -u
sh: /usr/local/bin/unit_diff: /usr/local/bin/ruby: bad interpreter: No such file or directory
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/ui/console/testrunner.rb:108:in `flush': Broken pipe (Errno::EPIPE)
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/ui/console/testrunner.rb:108:in `output'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/ui/console/testrunner.rb:51:in `setup_mediator'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/ui/console/testrunner.rb:39:in `start'
from /System/Library/Frameworks/Ruby.framework/Versions/1开发者_JAVA技巧.8/usr/lib/ruby/1.8/test/unit/ui/testrunnerutilities.rb:29:in `run'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/autorunner.rb:216:in `run'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit/autorunner.rb:12:in `run'
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/test/unit.rb:278
from -e:1
I see two things:
Your which ruby
says the default is /usr/bin/ruby
, but your Autotest is calling /usr/local/bin/ruby
.
sh: /usr/local/bin/unit_diff: /usr/local/bin/ruby: bad interpreter: No such file or directory
Also, your path is not organized well because you have duplicated entries. I split it on ':' then sorted it to look for duplicates:
/bin
/Library/Frameworks/Python.framework/Versions/Current/bin
/opt/local/bin # <--
/opt/local/bin # <--
/opt/local/sbin
/sbin
/Users/ethan/bin
/usr/bin
/usr/local/bin # <--
/usr/local/bin # <--
/usr/local/git/bin
/usr/local/mysql/bin
/usr/local/oracle/instantclient_10_2
/usr/local/pgsql/bin
/usr/sbin
Notice that you have duplicated /opt/local/bin
and /usr/local/bin
directories. Those should appear ahead of the default /usr/bin
directory in order for your "personally" installed apps to be located first, so you should do some housekeeping. Once you have done that close your terminal session(s). Open a new session and try rerunning your test and see if anything has changed/improved.
The path organization is part of the problem and explains why which ruby
points to the system Ruby. I suspect another part of this puzzle is that you are using #!/usr/local/bin/ruby
as the "bang slash" in your scripts, or explicitly pointing to that Ruby when you call things on the command-line. That will confuse tests no end. In my scripts I use this to invoke Ruby:
#!/usr/bin/env ruby
which works nicely because it uses whatever Ruby is defined first in my path, and with this next part...
I'm a big proponent for using RVM to manage Ruby installations on Mac OS and Linux. It makes it so you don't have to install anything in your default /usr/bin
ruby or even bother with adding one in /usr/local/bin
. RVM puts everything in ~/.rvm
and makes it really easy to install/manage/remove Ruby versions along with their associated gems, or even blow it all away by deleting that directory. Installing RVM and Gemsets are good starting places if you want to give it a try.
Rails support seems out of the ZenTest core. Install autotest-rails
or downgrade to ZenTest 4.0.0 to have it working again.
I had to do the following to get my autotest working after getting the following error with ruby ree-1.8.7 + rbenv: "rbenv: autotest: command not found" even though gem said autotest was installed. The binary in /usr/local/rbenv/versions/ree-1.8.7-2012.02/bin/autotest was missing however, even after repeated reinstalls of autotest.
#> gem uninstall ZenTest #all versions
#> gem uninstall autotest autotest-fsevent autotest-growl autotest-rails
#> bundle install
My Gemfile:
group :test,:development do
gem 'factory_girl_rails', '1.0'
gem 'mocha','~> 0.12.1', :require => false #for mocking data
gem 'ZenTest', '4.8.2' #DON'T USE 4.8.3 with Rails 3.2!
gem 'autotest', '~> 4.4.6'
gem 'autotest-fsevent','~> 0.2.8'
gem 'autotest-rails', '~> 4.1.2'
gem 'autotest-growl', '~> 0.2.16'
end
精彩评论