How Stop Autotest From Running After Each Failed Test Was Fixed

Autotest until recently only had one flaw: it could not be used for large test suites, since after each red-green cycle I had to wait x minutes for all tests to pass, which made autotest really frustrating.

So grep autotest (the ‘without ZenTest version’) from github and enjoy “autotest -c” (also works with auospec).

And remember kids: always run autospec with script/spec_server and its twice the fun πŸ˜‰

Passenger for Local Development of Multiple Applications on Ubuntu

Starting with the Railscasts episode on passenger I tried to get passenger working for development, since it removes the burden of always starting an extra console for the server and reveals errors that happen in passenger and not in mongel alone.

Apache should use the same group/user you use, otherwise you may get an 302 not allowed error, this can be changed in /etc/apach2/apache2.conf (User / Group).

httpd.conf

#/ets/apacha2/httpd.conf
# /apps is the folder where your projects lie
# I name them all *.lc so i can easily distinguish them from a live application
# if you use subdomains add the *. before the servername (example 1)
<Directory "/apps">
  Order allow,deny
  Allow from all
</Directory>

<Directory "/apps">
  Options FollowSymLinks
  AllowOverride None
</Directory>

<VirtualHost *:80>
  ServerAlias *.dw.lc
  PassengerPoolIdleTime 1800
  RailsEnv development
  DocumentRoot /apps/someproject/public
</VirtualHost>

<VirtualHost *:80>
  ServerAlias rs.lc
  PassengerPoolIdleTime 1800
  RailsEnv development
  DocumentRoot /apps/anotherproject/public
</VirtualHost>

hosts file

#/ets/hosts
127.0.0.1       de.dw.lc en.dw.lc fr.dw.lc
127.0.0.1       rs.lc
127.0.0.1       localhost
...

restart apache

sudo /etc/init.d/apache2 restart

Hope it works for you πŸ˜‰

Cucumber vs ActiveRecord 2.3 — Attempt to call private method (NoMethodError)

All of the sudden some columns began to misbehave in cucumber tests, claiming that “Attempt to call private method (NoMethodError)” on normal column attributes!

A simple fix for this, essentially saying that a method is not private when its a column:

#features/support/ar_private_fix.rb required from env.rb
unless ActiveRecord::Base.methods.include?('private_method_defined_with_fix?')
  class ActiveRecord::Base
    class << self
      def private_method_defined_with_fix?(method)
        return false if columns_hash.keys.include?(method.to_s)
        private_method_defined_without_fix?(method)
      end
      alias_method_chain :private_method_defined?, :fix
    end
  end
end

Lessons learned from upgrading Rails 2.1 to 2.3

Just my collection, so you do not need to find it out on your own πŸ˜‰

  • :expire now is called :expires_in, update your cache calls or timed expiring will fail
  • get rspec edge/ rspec-rails edge
    detailed instruction
    also possible and easy: sudo gem install dchelimsky-rspec dchelimsky-rspec-railsyou may need to add this when you are on 1.1.99.9 and get
    no such file to load — spec/rails/example/routing_example_group
    from github
  • get webrat 0.4.2 (atm only by installing from github clone + rake gem + sudo gem install)
  • truncate(‘xxx’,3) ==> truncate(‘xxx’,:length=>3)
  • Model.find_by_xxx will now call Model.find with :conditions=>{:xxx=>something}, this broke some of my stubs/mocks, e.g. User.stubs(:find) worked before but now came in conflict with user login that used find_by_id
  • render :inline seems not to be testable, all my request.body from render :inline are blank now (rspec 1.1.12)
  • stub_model install rspec-rails-mocha — ./script/plugin install git://github.com/mislav/rspec-rails-mocha.git
  • count returns OrderedHash, so tests now look like xxx.to_a.should == [[‘name’,2]]
  • String.chars does not have the [] method anymore, so e.g. only “xxx”.mb_chars[1..4] will work
  • @template will no longer work in vie tests, use response instead
  • have_tag returns
    undefined method `id2name’ for {:instance_writer=>false}:Hash
    , upgrade the money gem!
  • controller tests are no longer able to call actions that are not defined (e.g. no action was defined because it only renders a view and does nothing or because the action was included from a module)
  • HopToad will silently fail, use this branch instead: http://github.com/pzingg/hoptoad_notifier (as long as thoughbot does not update their own of course)
  • work systematically e.g. rake spec:models, then rake spec:controllers … or you may get mad πŸ˜‰