Archive for April 2009

Rack::Bug debugging toolbar in four minutes

Here’s a quick screencast demonstrating Rack::Bug, a new Rack middleware for inspecting requests to any Rack-compatible web application.

Download the screencast (12 MB, 4:00)

The source is on GitHub. It ships with nine panels:

  • Rails Info
  • Resource Usage
  • Rack Env
  • SQL
  • AR Objects
  • Memcached
  • Templates
  • Log
  • Memory Usage
./script/plugin install git://github.com/brynary/rack-bug.git
1
2
3
4
5
6
7
# config/initializers/middleware.rb
require "rack/bug"

ActionController::Dispatcher.middleware.use Rack::Bug,
  :ip_masks   => [IPAddr.new("127.0.0.1")],
  :secret_key => "epT5uCIchlsHCeR9dloOeAPG66PtHd9K8l0q9avitiaA/KUrY7DE52hD4yWY+8z1",
  :password   => "rack-bug-secret"

Webrat slides from GoGaRuCo

I finally got an internet connection (on the plane wifi) to upload my slide from GoGaRuCo 2009 about Webrat. Couldn’t get them up to SlideShare yet, so I’ll add that tomorrow. (Update: Slides are now up on SlideShare and embedded below.)

Thanks again to Josh and Leah for organizing GoGaRuCo. I had a great time in SF meeting a lot of cool people and learning about all sorts of new technologies I want to try out soon.

Download the slides as a PDF (1.9 MB)

Note: The talks were recorded, so a full video of my presentation should be online soon.

Switching Webrat to Selenium mode

Ryan Bates did a great job covering Webrat in Railscast #156, and I’d recommend anyone who hasn’t used Webrat check it out. It’s a clear demonstration of how you can start using Webrat in a few minutes today with Rails built-in integration testing framework. Webrat works with RSpec, Cucumber, Shoulda, etc. too, but they aren’t required.

Unfortunately, during the screencast some Webrat bugs prevented running the tests in Selenium mode. Webrat has worked with Selenium for some time, but there have been some lingering rough edges around getting it up and running that I’ve been meaning to resolve. Today I’m happy to report those issues are now fixed, and getting started using Selenium with Webrat should now be drop-dead simple.

Give it a try by checking out the full Episode #156 source code, then make the following changes:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# config/environments/test.rb
config.gem "webrat", :version => ">=0.4.4" # was 0.4.3

# test/test_helper.rb
class ActiveSupport::TestCase
  # ...
  self.use_transactional_fixtures = false # was true

  # ...

  # Add these lines:
  setup do |session|
    session.host! "localhost:3001"
  end
end
  
Webrat.configure do |config|
  config.mode = :selenium # was :rails
end

Running the test again should pop open a Firefox window for the running tests and print output like this:

$ rake test:integration
(in /Users/bhelmkamp/p/railscasts-episodes/episode-156/authenticator)
Loaded suite /Library/Ruby/Gems/1.8/gems/rake-0.8.4/lib/rake/rake_test_loader
Started
==> Waiting for Selenium RC server on port 4444... Ready!
==> Waiting for rails application server on port 3001... Ready!
..
Finished in 11.679288 seconds.

2 tests, 2 assertions, 0 failures, 0 errors

Success!

Note: I just pushed Webrat 0.4.4, so it might not be available on all the gem sever mirrors yet. If not, you can install it with the following commands:

git clone git://github.com/brynary/webrat.git
cd webrat
rake install_gem