Rails, rcovが落ちるのを修正

色々とおかしな状況だったので整理。

Ruby 1.8.7
Rails 2.2.2
rspec 1.1.11
rspec-rails 1.1.11
rcov 0.8.1.2.0

とりあえず、rake specが2回実行されたので、vendor/plugins以下のrspecとrspec-railsを消します。
それから、rake spec:rcovを実行。

% rake spec:rcov

(中略)

/opt/local/lib/ruby/1.8/rexml/formatters/pretty.rb:131:in `[]': no implicit conversion from nil to integer (TypeError)
        from /opt/local/lib/ruby/1.8/rexml/formatters/pretty.rb:131:in `wrap'
        from /opt/local/lib/ruby/1.8/rexml/formatters/pretty.rb:131:in `wrap'
        from /opt/local/lib/ruby/1.8/rexml/formatters/pretty.rb:90:in `write_text'
        from /opt/local/lib/ruby/1.8/rexml/formatters/default.rb:50:in `write'
        from /opt/local/lib/ruby/1.8/rexml/formatters/pretty.rb:75:in `write_element'
        from /opt/local/lib/ruby/1.8/rexml/formatters/pretty.rb:73:in `each'
        from /opt/local/lib/ruby/1.8/rexml/formatters/pretty.rb:73:in `write_element'
        from /opt/local/lib/ruby/1.8/rexml/formatters/default.rb:31:in `write'
        from /opt/local/lib/ruby/1.8/rexml/formatters/pretty.rb:75:in `write_element'
        from /opt/local/lib/ruby/1.8/rexml/formatters/pretty.rb:73:in `each'
        from /opt/local/lib/ruby/1.8/rexml/formatters/pretty.rb:73:in `write_element'
        from /opt/local/lib/ruby/1.8/rexml/formatters/default.rb:31:in `write'
        from /opt/local/lib/ruby/1.8/rexml/formatters/pretty.rb:117:in `write_document'
        from /opt/local/lib/ruby/1.8/rexml/formatters/pretty.rb:111:in `each'
        from /opt/local/lib/ruby/1.8/rexml/formatters/pretty.rb:111:in `write_document'
        from /opt/local/lib/ruby/1.8/rexml/formatters/default.rb:28:in `write'
        from /opt/local/lib/ruby/1.8/rexml/document.rb:195:in `write'
        from (eval):93:in `pretty'
        from /opt/local/lib/ruby/gems/1.8/gems/rcov-0.8.1.2.0/lib/rcov/report.rb:1003:in `create_file'
        from /opt/local/lib/ruby/gems/1.8/gems/rcov-0.8.1.2.0/lib/rcov/report.rb:708:in `execute'
        from /opt/local/lib/ruby/gems/1.8/gems/rcov-0.8.1.2.0/lib/rcov/report.rb:125:in `each'
        from /opt/local/lib/ruby/gems/1.8/gems/rcov-0.8.1.2.0/lib/rcov/report.rb:125:in `each_file_pair_sorted'
        from /opt/local/lib/ruby/gems/1.8/gems/rcov-0.8.1.2.0/lib/rcov/report.rb:707:in `execute'
        from /opt/local/lib/ruby/gems/1.8/gems/rcov-0.8.1.2.0/lib/rcov.rb:640:in `dump_coverage_info'
        from /opt/local/lib/ruby/gems/1.8/gems/rcov-0.8.1.2.0/lib/rcov.rb:640:in `each'
        from /opt/local/lib/ruby/gems/1.8/gems/rcov-0.8.1.2.0/lib/rcov.rb:640:in `dump_coverage_info'
        from /opt/local/lib/ruby/gems/1.8/gems/rcov-0.8.1.2.0/bin/rcov:421
rake aborted!

rexmlがなんかおかしいっぽい。
なので直修正。

vi /opt/local/lib/ruby/1.8/rexml/formatters/pretty.rb:130
+ place = string.rindex(' ', width) || width

めでたくrake spec:rcovが実行されました。

Rails, GraphvizとRailRoadで設計確認

いつも最初にきちんと設計するんですが、あれこれと仕様変更でどんどんコードが変わっていく・・

しかもRspecでテスト書いているので仕様変更にも柔軟に対応できてしまう。

そうなると、後でこれってどうなってたっけ?みたいなことになる。

そんなときに簡単に設計をチェックできる、いわゆるリバースエンジニアリングに近いことができます。

http://www.graphviz.org/

http://railroad.rubyforge.org/

# sudo port install graphviz
# sudo gem install railroad

RAILS_ROOTに移動して、コマンド実行。

# railroad -C -o doc/controllers.dot
# railroad -M -o doc/models.dot
# neato -Tpng doc/controllers.dot > doc/controllers.png
# neato -Tpng doc/models.dot

簡単なクラス図を生成してくれます。

いちいちコマンドが面倒なのでrakeタスクにしちゃいます。

namespace :doc do
  namespace :railroad do
    task :models do
      sh "railroad -i -l -a -m -M -o doc/models.dot"
      sh "neato -Tpng doc/models.dot > doc/models.png"
    end

    task :controllers do
      sh "railroad -i -l -C -o doc/controllers.dot"
      sh "neato -Tpng doc/controllers.dot > doc/controllers.png"
    end
  end
  task :railroad => %w(railroad:models railroad:controllers)
end

私はコントローラーのアクションとか確認するのによく使います。

リモートリポジトリのsync

svnadmin create /var/svn/testrails
cat <<‘EOF’ > /var/svn/testrails/hooks/pre-revprop-change
#!/bin/sh
exit 0
EOF

chmod +x /var/svn/testrails/hooks/pre-revprop-change
svnsync init file:///var/svn/testrails svn+ssh://admin@code.twintail.tv/home/svn/testrails
svnsync sync file:///var/svn/testrails

sshを使っているので毎回パスワード聞かれる。鍵を作ってしまうか、httpで公開REPOにするかの判断。

retorspectivaにsvnsyncさせるには鍵認証にしてsyncコマンド送らせるか、設定のオプションにパスワード直書きするか。

迷う。

retrospectiva / subversionメモ

ruby-enterpriseで使えるように。

./configure RUBY=/usr/local/bin/ruby –enable-experimental-libtool –enable-shared –disable-static –with-apr=/usr/bin/apr-1-config –with-apr-util=/usr/bin/apu-1-config –with-apxs=/usr/sbin/apxs –with-openssl –enable-ssl –with-ssl
make
make install
make swig-rb
make install-swig-rb

一発Rails開発環境

RM-Install

朝から下痢で体調が悪いけど、こんなのみつけた。

MAMPとかXAMPPみたいなもの。

インストーラーで以下がパッケージされている。

Ruby 1.8.6
Rails 1.2.3
MySQL 5.0
SQLite 3.3
Subversion 1.4
Apache HTTP Server 2.2 (Production mode)
OpenSSL
ImageMagick 6.3
Mongrel/Mongrel Cluster
Capistrano
Gruff
Rake
RMagick

productionとdevelopmentを選べるようで、productionを選ぶとApache+Mongrel Clusterな環境になるようで。
結構めんどくさいImageMagickとかもはいってる。

でも漢なら全部ソースからインストールでしょ。押忍。

どうもおかしいと思ってたら、mongrel_clusterが止まってるよ・・

ついでにPoundの設定も見直しつつ、様子見かなぁ。

つーか、Pound+mongrel_cluster+Apache2の組み合わせは流行らないのか。

Railsのプラグインを検索

raptってコマンドで検索できる。

$ gem install rapt

$ cd RAILS_ROOT

$ rapt search authenticated
Authenticated Cookie
Info: http://agilewebdevelopment.com/plugins/show/309
Install:
Acts as Authenticated
Info: http://agilewebdevelopment.com/plugins/show/1
Install: http://svn.techno-weenie.net/projects/plugins/acts_as_authenticated
Restful Authentication
Info: http://agilewebdevelopment.com/plugins/show/350
Install: http://svn.techno-weenie.net/projects/plugins/restful_authentication/
ActiveTest Authentication
Info: http://agilewebdevelopment.com/plugins/show/456
Install: http://mabs29.googlecode.com/svn/trunk/plugins/active_test_authentication
Simple Access Control
Info: http://agilewebdevelopment.com/plugins/show/308
Install: http://mabs29.googlecode.com/svn/trunk/plugins/simple_access_control
Authenticate As Remote User
Info: http://agilewebdevelopment.com/plugins/show/662
Install: http://craz8.com/svn/trunk/plugins/authenticate_as_remote_user/
Super Simple Authentication
Info: http://agilewebdevelopment.com/plugins/show/849
Install: http://svn.ariejan.net/plugins/super_simple_authentication

ちょっと便利。

iBookにRuby on Rails

なんだか調子の悪いiBookを初期化しました。
で、Rails開発ができるように再構築です。リンク先は記述してないけど、探せばあるから。

OSXインストール直後から。

必要なアプリケーションをダウンロードしてインストール。

Quicksilver
Frefox
Opera
Adium
Skype
AppDelete
Cyberduck
iBackup
iTerm
The Unarchiver
VLC

シェアウェア
TextMate
Transmit

Internet Plug-ins
PDF Browser Plugin
Word Browser Plugin

必要ないものもあるけど気にしない。

事前にiBackupでバックアップしていたものをリストア。
appleのサイトからXcodeをダウンロード。1Gくらいある。

XcodeとX11SDKをインストール。

MacPortsをダウンロードしてインストール。

MacPortsで下記をインストール。

sudo port install wget
sudo port install nmap
sudo port install subversion
sudo port install mysql5-devel +server
sudo port install ruby +mactk
sudo port install rb-rubygems
sudo port install imagemagick +wmf +jpeg2

一緒に必要なモノもインストールしてくれるから全部ね。

待っている間、山手線3週くらいできる。

RubyGemsのインストール。

sudo gem install mysql
sudo gem install rails
sudo gem install mongrel
sudo gem install net-sftp
sudo gem install net-ssh
sudo gem install gettext
sudo gem install rmagick
sudo gem install capistrano
sudo gem install acts_as_searchable

待っている間、ご飯を3回食べられる。

Railsアプリケーションを作成してテスト。

以上で終了。長かった。。。

mongrel::clusterの設定とか

user@myserv% sudo mongrel_rails cluster::configure ?
-e production -p 8100 -a 127.0.0.1 -l /var/log/mongrel.log ?
-P /var/run/mongrel/mongrel.pid -c /var/www/rails.example.jp ?
-r /var/www/rails.example.jp -N 3 –user www-data –password www-data

cd RAILS_ROOT
mongrel_rails cluster::config -e production -p 8000 -N 3
mongrel_rails cluster::start
mongrel_rails cluster::stop