... in order to have a different logfile for each unicorn worker, setting the log level in your environment file will not take affect.

any_instance doesn't work with should_not_receive

It always passes.

The rspec folks haven't decided what it should do. "Official" suggestion is to only use any_instance with stubbing instead of with expectations.

Capistrano doesn't clean up that well

When you use the deploy:cleanup task it only looks at the FIRST server declared in deploy.rb to determine which releases to rm. You'd think that it would look at the primary server. But then you'd think that the task would be included by default, too. Which it doesn't.

Enumerators, ActiveRecord Connections, and JRuby

We ran into what we thought was a quirk of Enumerators where inside the enumerator you are in a different thread from outside. This affects ActiveRecord because your connection is determined by Thread.current.object_id. So you'd end up with a new connection inside the Enumerator.

This turned out to only be true in JRuby. Under MRI, you have the same Thread object, however, you have a new Thread locals context. This makes it particularly hard to find someplace cross Ruby for Rails to store its connection id.

… in order to have a different logfile for each unicorn worker, setting the log level in your environment file will not take affect.

any_instance doesn’t work with should_not_receive

It always passes.

The rspec folks haven’t decided what it should do. “Official” suggestion is to only use any_instance with stubbing instead of with expectations.

Capistrano doesn’t clean up that well

When you use the deploy:cleanup task it only looks at the FIRST server declared in deploy.rb to determine which releases to rm. You’d think that it would look at the primary server. But then you’d think that the task would be included by default, too. Which it doesn’t.

Enumerators, ActiveRecord Connections, and JRuby

We ran into what we thought was a quirk of Enumerators where inside the enumerator you are in a different thread from outside. This affects ActiveRecord because your connection is determined by Thread.current.object_id. So you’d end up with a new connection inside the Enumerator.

This turned out to only be true in JRuby. Under MRI, you have the same Thread object, however, you have a new Thread locals context. This makes it particularly hard to find someplace cross Ruby for Rails to store its connection id.

Sometimes your controllers get so full of before_filters, after_filters, and around_filters that it's hard to figure out what order these callbacks are actually executing in. A couple of times recently, I've run into some tricky bugs that ended up being related to callbacks running too soon or too late.

Due to some fancy-pants metaprogramming in AbstractController::Callbacks, it's hard to see what's going on.

In Rails 3, send this to Rails.logger.debug or puts from inside your controller to see the ordered filter callback chain:

]]>Sometimes your controllers get so full of before_filters, after_filters, and around_filters that it’s hard to figure out what order these callbacks are actually executing in. A couple of times recently, I’ve run into some tricky bugs that ended up being related to callbacks running too soon or too late.

Due to some fancy-pants metaprogramming in AbstractController::Callbacks, it’s hard to see what’s going on.

In Rails 3, send this to Rails.logger.debug or puts from inside your controller to see the ordered filter callback chain:

Interesting Things

silly Ruby trick of the day -- does anyone know what this does?

while gets
print if /foo/
end

This is an example from the Ruby "Pickaxe" book. No respected Rubyist actually writes such difficult-to-understand and obfuscated code. Though, it was mentioned, that terse syntax like this is useful for command-line hacking.

unstub! is a useful Rspec method that removes a stub from a previously stubbed object. This can be useful if you have stubbed, then mocked the same method, and you want to remove the stub.

The unofficial community-developed iPhone app for Pivotal Tracker, is changing its name from iPivotal to PTCruiser. See the author's Twitter for more.

This is an example from the Ruby “Pickaxe” book. No respected Rubyist actually writes such difficult-to-understand and obfuscated code. Though, it was mentioned, that terse syntax like this is useful for command-line hacking.

unstub! is a useful Rspec method that removes a stub from a previously stubbed object. This can be useful if you have stubbed, then mocked the same method, and you want to remove the stub.

The unofficial community-developed iPhone app for Pivotal Tracker, is changing its name from iPivotal to PTCruiser. See the author’s Twitter for more.

Interesting Things

One team had trouble deploying via capistrano to Engineyard's Solo environment because SSH keys weren't being sent correctly. Setting ssh_options[:forward_agent] = false in their Capistrano config fixed the problem.

After upgrading to Rails 2.3, Rails started sending two content-types down with each page's headers, text/html, application/json. This was causing Selenium tests to choke.

If you scp a file to /etc/cron.d, cron will not notice the new file until you touch it.

One team had trouble deploying via capistrano to Engineyard’s Solo environment because SSH keys weren’t being sent correctly. Setting ssh_options[:forward_agent] = false in their Capistrano config fixed the problem.

After upgrading to Rails 2.3, Rails started sending two content-types down with each page’s headers, text/html, application/json. This was causing Selenium tests to choke.

If you scp a file to /etc/cron.d, cron will not notice the new file until you touch it.

Ask For Help

"Anybody use an off-the-shelf State Machine plugin for Rails? Which one?"

Our team recommends using the rubyist-aasm gem from Github. It works well for our current applications, and it appears to be the most actively developed and frequently updated. This gem is the successor to the acts_as_state_machine plugin.

Interesting Things

Don't use comments in ERB. Writing comments (or any '#' character, for that matter) inside an ERB evaluation block was never right, but some versions of Ruby 1.8.6 allowed it anyway. This is trouble if you upgrade to Ruby 1.8.7 (for example, when upgrading to Snow Leopard) which does not allow comments within ERB.

This is wrong:

<%= link_to "/", home_path #link to the homepage %>

If you really need comments in ERB, do it this way:

<%# link to the homepage %>
<%= link_to "/", home_path %>

test-unit 2.0.3 breaks RSpec. If you upgrade to test-unit 2.0.3, you may notice that your RSpec specs no longer run. Roll back to test-unit < 2.0 (or remove the test-unit gem completely) and you should be back in business.

RubyMine 1.5 early release is available for trying out. Preliminary reports from one Pivot are positive. If you are using Snow Leopard, which ships with Java 1.6, you'll need to do this hack to get it to run

“Anybody use an off-the-shelf State Machine plugin for Rails? Which one?”

Our team recommends using the rubyist-aasm gem from Github. It works well for our current applications, and it appears to be the most actively developed and frequently updated. This gem is the successor to the acts_as_state_machine plugin.

Interesting Things

Don’t use comments in ERB. Writing comments (or any ‘#’ character, for that matter) inside an ERB evaluation block was never right, but some versions of Ruby 1.8.6 allowed it anyway. This is trouble if you upgrade to Ruby 1.8.7 (for example, when upgrading to Snow Leopard) which does not allow comments within ERB.

This is wrong:

<%= link_to "/", home_path #link to the homepage %>

If you really need comments in ERB, do it this way:

<%# link to the homepage %>
<%= link_to "/", home_path %>

test-unit 2.0.3 breaks RSpec. If you upgrade to test-unit 2.0.3, you may notice that your RSpec specs no longer run. Roll back to test-unit < 2.0 (or remove the test-unit gem completely) and you should be back in business.

RubyMine 1.5 early release is available for trying out. Preliminary reports from one Pivot are positive. If you are using Snow Leopard, which ships with Java 1.6, you’ll need to do this hack to get it to run

Interesting Things

libxml-ruby doesn't work on Windows (surprise, surprise!). One of our teams discovered that the version of Ruby on Windows has a XML::Parser class, but it is NOT libxml-ruby even if you try to install the gem. A workaround is to rename or delete the libxml.so file, and then you can use the real XML::Parser.

A few Pivots just whipped up a pivotal-apdex gem that allows you to calculate your application's Apdex performance index via a simple command line tool by parsing Nginx or Apache server logs. Apdex is an emerging standard in measuring application performance. We were inspired by Lew Cirne, CEO of New Relic, who gave a talk about Apdex a few weeks ago at Pivotal's office.

libxml-ruby doesn’t work on Windows (surprise, surprise!). One of our teams discovered that the version of Ruby on Windows has a XML::Parser class, but it is NOT libxml-ruby even if you try to install the gem. A workaround is to rename or delete the libxml.so file, and then you can use the real XML::Parser.

A few Pivots just whipped up a pivotal-apdex gem that allows you to calculate your application’s Apdex performance index via a simple command line tool by parsing Nginx or Apache server logs. Apdex is an emerging standard in measuring application performance. We were inspired by Lew Cirne, CEO of New Relic, who gave a talk about Apdex a few weeks ago at Pivotal’s office.

Interesting Things

memcache-client is broken in the sense that if it fails to connect to your memcached server, it will automatically try a new server. It does this 20 times. Not what one would expect. You can turn off this weird behavior by setting :failover => false

Ask For Help

When writing view specs, is there a better way to include your helpers if all helpers are not automatically included in ApplicationController? Some suggestions from the crowd: mock the helpers (test helpers separately), or reopen the template and define helpers there directly.

memcache-client is broken in the sense that if it fails to connect to your memcached server, it will automatically try a new server. It does this 20 times. Not what one would expect. You can turn off this weird behavior by setting :failover => false

Ask For Help

When writing view specs, is there a better way to include your helpers if all helpers are not automatically included in ApplicationController? Some suggestions from the crowd: mock the helpers (test helpers separately), or reopen the template and define helpers there directly.

Interesting Things

Rubymine, just released a new beta revision 856. So far it "seems to work".

When using Object-Mother patterns for creating objects in tests (i.e. Fixjour, FactoryGirl) one gotcha that caused one of our teams some pain was when inadvertently setting an object and object_id for the same association. For example, setting person = @nate and person_id = @david.id in the same object creation will cause really weird problems. Our team debugged and solved this by validating object creation ... essentially writing tests for your test objects.

Rubymine, just released a new beta revision 856. So far it “seems to work”.

When using Object-Mother patterns for creating objects in tests (i.e. Fixjour, FactoryGirl) one gotcha that caused one of our teams some pain was when inadvertently setting an object and object_id for the same association. For example, setting person = @nate and person_id = @david.id in the same object creation will cause really weird problems. Our team debugged and solved this by validating object creation … essentially writing tests for your test objects.

Interesting Things

Webrat, the acceptance testing framework that is all the rage right now, has a neat lesser-known save_and_open_page command that is helpful for debugging when your tests go wrong. Essentially, this command dumps the current HTML to the browser and lets you inspect the state of the page visually at any point within your test.

Rubymine, Pivotal's favorite Ruby IDE, doesn't really support UTF8. You can type UTF8 characters seemingly fine ... but somewhere along the way it doesn't save properly. Apparently this has been an issue with Rubymine for quite some time. Frustrating.

Ask for Help

Anyone know a reliable way of CSS regression testing? When we are refactoring CSS or markup, it would be great if there was an automated way to detect visual breakages. Some ideas floating around involve taking screenshots through Webkit's API and comparing them pixel by pixel. This kind of thing has been attempted twice by Pivots without much success. Anybody have a good solution?

Webrat, the acceptance testing framework that is all the rage right now, has a neat lesser-known save_and_open_page command that is helpful for debugging when your tests go wrong. Essentially, this command dumps the current HTML to the browser and lets you inspect the state of the page visually at any point within your test.

Rubymine, Pivotal’s favorite Ruby IDE, doesn’t really support UTF8. You can type UTF8 characters seemingly fine … but somewhere along the way it doesn’t save properly. Apparently this has been an issue with Rubymine for quite some time. Frustrating.

Ask for Help

Anyone know a reliable way of CSS regression testing? When we are refactoring CSS or markup, it would be great if there was an automated way to detect visual breakages. Some ideas floating around involve taking screenshots through Webkit’s API and comparing them pixel by pixel. This kind of thing has been attempted twice by Pivots without much success. Anybody have a good solution?