Ever wanted to be able to debug an HTML page using the power of Firebug while running Cucumber/Capybara features/steps?
Follow these simple steps and you can get it to work:
1) Create a new “WebDriver” Firefox profile using the instructions found here
2) Fire up Firefox using the newly created profile and install/configure Firebug the way you want it. See instructions above.
3) Run your Cucumber/Capybara steps and pause the feature using a sleep() statement long enough for you to poke around in the page with Firebug.
**Note this has been proven to work on OS X, your mileage on other OS’s may be limited.
So I’ve been doing a bunch of BDD development these days using Cucumber as a starting point.
While working with client, the question came up about how they could share step definitions across multiple teams of developers.
I then remembered that the Aruba gem is just that, a collection of Cucumber step definitions.
So if you are looking for a way to start packaging up those step definitions that you have used on multiple projects and are tired of copying across projects, check out how the Aruba gem does it and go from there.
Thanks to the Cucumber and Aruba folks for sharing some very useful technology that allows us all to raise the bar when it comes to delivering quality software.
In an effort to continue my contributions to the open source Ruby/Rails ecosystem, I decided to help the factory_girl_rails team move the Rails3 generators from the rails3-generators project into the factory_girl_rails project.
Like all good Ruby/Rails developers, they asked to make sure that I had tests written around the generators. I thought for a bit on how I was going to do this and then I wandered across the Cucumber feature files in the rspec-rails repo and found my answer.
Rspec-rails (and RSpec2 as well) uses a gem called Aruba to easily write Cucumber features around things that happen from the command line.
If you’d like to check out the result of using Cucumber and Aruba to test Rails3 generators, head over to my fork of the factory_girl_rails gem and check out the features/generators.feature file.
Hopefully the changes will be merged into the official factory_girl_rails repo soon and the generators will live closer to home.
In continuing with my Cucumber themed posts, here is a great post about using Cucumber and Sunspot together…
The has_css? method call will wait until the element shows up and if it doesn’t show up before the Capybara timeout expires then it will return false.
For some reason the Universe keeps sending great Cucumber related stories to me via Twitter.
Here is another great one from the folks at Square on how to test Resque based functionality via Cucumber:
Try adding the following to your Gemfile:
gem 'thin', :group => :test
and see what happens.
Ask for Help
- Double-entry/ledger based accounting in Rails (i.e. Quickbooks in Rails for free)
Ideally would be tied in with user/role system where each accounting entry would be tied to a user, but also reconciled against a master account.
Recommendations? Latest and greatest?
One suggestion was to look at the code that Wesabe open sourced code when they closed their doors.
- Error message when opening Rubymine “Invalid Git Root”
This is likely because the project included a submodule that wasn’t configured correctly, fix this in under Rubymine’s version control preferences.
- Test 404 handling (e.g.
rescue_from ActiveRecord::RecordNotFound, :with => :render_record_not_found) with Cucumber by temporarily setting
ActionController::Base.allow_rescue = true. This is usually set to
JSON.pretty_generate hates Rails 3
This should work in most modern browsers. Follow the Mozilla docs, NOT the various blog posts about this.
Ask for Help
“Do you have to use to_param in functional tests?”
In the past you could simply provide an object in a param list in functional tests and the
to_param for the object would be called to get the proper value for the parameter. This is now broken, forcing you to use object.to_param every time.
Perhaps not helpful for existing projects but I recommend you use cucumber, webrat, or even selenium rather than Rails functional tests. Rails functional tests require that you specify parameters and specify them correctly. If you get them wrong your functional tests might continue to pass for the wrong reason. Here’s another “bad params in functional tests” post.