Tonight, I got a chance to give a presentation to the Columbus Ruby Brigade on MetricFu. If you’re interested in seeing it, here is the PDF.
MetricFu at CRB
June 15th, 2009 — Uncategorized
Adding to webrat_steps with cukesteps
June 2nd, 2009 — Uncategorized
As a recent convert to Ruby on Rails, I’ve fallen in love with the combination of Cucumber and its associated ecosystem (RSpec, webrat, etc.). When you first start a Cuke project, it provides an initial set of helpful steps in a file called webrat_steps.rb in your features/step_definitions file. While these are helpful, I found myself creating several other steps that seemed to be more generally useful than just my project. I’ve packaged these steps up into a gem called cukesteps that you can get at:
Github
These steps fall into three basic categories:
- Object creation step(s)
- Debugging steps
- Semantic markup checking steps
Object creation steps
In our project, we have fairly complex sets of ActiveRecord models and associations. Trying to do acceptance testing proved challenging because several tests require non-trivial amounts of setup to work. Consider for an example an application that helps you find restaurants with foods that enable you to lose weight. In this kind of application, you might have models for Food, Restaurant, Brand, and Location. And you need to tie these together in your features as in this example:
Given the following foods exist
| food | calories | fat_calories |
| eggs | 200 | 180 |
| burger | 350 | 200 |
| salad | 100 | 80 |
And the following restaurants exist
| brand | location | foods |
| mcdonalds | chicago il | eggs, burger |
| panera | chicago il | eggs, salad |
| mcdonalds | dallas tx | burger, salad |
When I fill in "city" with "chicago"
And I select "under 100" from "calories"
And I press "search"
Then I should see "panera"
Creation of restaurants in this example is fairly complicated (and maybe over-complicated):
- the base Restaurant object is probably created with FixtureReplacement, FactoryGirl, Object Daddy, Fixjour, or something similar, but:
- the associated brand might have to be grabbed using Brand.find_by_name to make use of a db:seed kind of table
- the associated location could be created with whatever Factory mechanism you’re using with only a single string param being enough to make it interesting
- the associated foods come from objects created in the prior step
Getting these steps with the cukesteps gem installed is a matter of doing the following in your features/support/env.rb file for cuke:
require 'cukesteps'
include CukeAssociationHelpers
cuke_association_attributes(:brand => :name,
:location => :address)
The use of cuke_association_attributes causes the brand and location columns in the second step to be treated special. Instead of being treated as simple attributes, they instead are found or built. If a result of find_by_attribute_name (e.g. find_by_name for brand or find_by_address for location) returns non-nil, then that object is used as the associated object. Otherwise, the object is created using a create_model-style factory method. The foods column is also special in that it refers back to the Food objects created in the prior step.
Debugging Steps
The cukesteps gem provides four basic debugging steps:
- Then I debug
- Then save_and_open_page
- Then n foos should exist
- Then dump all foos to standard output
These steps are not ones you’d leave in your feature file for any length of time, but they can come in handy for chasing down problems you encounter along the way.
Semantic markup checking steps
These steps help encourage use of semantic IDs and Class Names in your markup. The use of the articles “a” and “the” represent a class and ID respectively. For example, “I should see a photo in the search-results” ensures that the the page contains an element of class photo inside an element of ID search-results. The steps available here are:
- Then I should see the foo (e.g. Then I should see the search-results)
- Then I should see a|an foo (e.g. Then I should see a listing)
- Then I should see a foo in the bar (e.g. Then I should see a listing in the search-results)
- Then I should see the foo in the bar (e.g. Then I should see the map in the search-results)
- Then I should see n foos in the bar (e.g. Then I should see 4 listings in the search-results)
- Then I should see n to m foos in the bar (e.g. Then I should see 3 to 5 listings in the search-results)
- Then the baz in the bar should contain a foo (e.g. Then the map in the search-results should contain a resizer)
The negation of each of the above is also available (e.g. Then I should not see a listing in the search-results)
Installation
To use this gem, just do the following:
gem sources github.com gem install mdoel-cukesteps
Feel free to fork away and send me feedback.
Stealing Second Base
December 29th, 2008 — Uncategorized
Progress always involves risk; you can’t steal second base and keep your foot on first.
Fred Wilcox
For Christmas this year, my wife got me a copy of The Winners Manual by Jim Tressel – head coach of the Ohio State football team. It’s a fantastic book, written in a style that is well suited to digesting it in small bits of 5-7 pages at a time. Given the author, you might be surprised to find that there’s really very little football in the book. Instead, it’s a book that helps you to realize the big picture parts of your life – your life’s purpose and the goals you set for yourself. Reading a chunk is now a part of my morning ritual for getting the day started.
The quote at the start of this post comes from the beginning of chapter 3 – “Attitude”. I found it particularly relevant to my current situation. It was a year ago that I left AOL and the comforts of a steady paycheck. The past year has been eventful (more on that in a future post), but the professional part of it has largely been a search for the right entrepreneurial business opportunity with some consulting work done along the way.
Well, we finally feel like we have the right business model to pursue and have started working on that over the last couple of weeks. The thing is, pursuing this opportunity means more time with, uh, shall we say a non-ideal income model (on the positive side – income taxes are low). And in the last couple of days, I’ve had someone approach me about an opportunity that is very tempting. It would be a 40 hour per week position that brought in a nice income stream. And in case you haven’t been paying attention to the news lately, this could come in handy. But it would almost certainly put a serious crimp in our ability to execute on the new business.
Which brings me back to The Winners Manual and that quote. I guess every entrepreneur eventually reaches a gut-check moment where you move from chicken to pig. Well, oink oink – this pig is off first and running hard for second.
Andrew Doel
November 20th, 2008 — Uncategorized
I just got back from three days in Denver, attending the Advanced Rails Studio (which was fantastic). Going to Denver gave me a chance to get to see my brother, Andrew. Although we talk fairly regularly on the phone, it had been a few years since I actually had seen him in person. I hope it won’t be that long between visits this time. Click the smaller picture for a bigger one.
At the Obama Rally
November 2nd, 2008 — Uncategorized
Today, two days before the 2008 election, Barack Obama held a rally at the Ohio statehouse. News reports estimate that sixty thousand people attended. Four of them were our family. We arrived on the scene about four hours before the start and found ourselves in a line that was already about a quarter mile long. Fortunately however, we got reasonably close and the kids got a chance to experience the political process in action (and got to meet John Glenn in the process).
You can see our pictures of the event here.
Fall Colors
November 1st, 2008 — potd
A couple of days ago, I read a pretty compelling post entitled Photograph Those You Love by Zack Arias. It made me realize that it had been awhile since I put more than “quick snapshot” effort into taking pictures of the kids. Today, we had beautiful weather and still had some nice fall colors here in central Ohio, so the timing could not have been better. So, despite some grumbling, I drug the kids out and got some nice shots made.
For those interested in the technical elements, here you go. The lighting basically amounted to a three-light setup. The first was a flash, gelled with a 1/4 CTO to help warm it up, mounted on a light stand with a shoot through umbrella. The second was the sun coming from back camera left, serving as a separation light. And finally, I used a large reflector front camera right to kick some of that sunlight back up to fill in the shadows on their faces. This is the kind of lighting setup that I would never have thought to try until making my way through David Hobby’s Strobist blog, but it’s amazing how easy and effective this kind of thing is. This kind of extra effort helps turn simple snapshots into portraits worth framing.
Happy Halloween 2008
October 31st, 2008 — potd
A Tale of Two Cities
October 29th, 2008 — potd
One of the things I’d been telling myself I had to get out and do was to go out and shoot some light trails pictures. So, tonight, while the kids were off at choir practice, I set out. The pictures below are from Westerville, Ohio (home, sweet, home) and of downtown Columbus. The Columbus shot includes the statehouse and the iconic Columbus Dispatch sign. The Westerville shot is of the building that houses the newish Old Bag of Nails pub (home of the best fish and chips in the city).
Adding color to enhance the effect
October 26th, 2008 — Uncategorized
As an addition to the technique I talked about in my last post, consider also adding color gels (basically colored pieces of plastic) over the flash head to create a different mood. This self-portrait uses a red gel and makes me look like I belong in a David Lynch movie.
Maybe I’ll tell our son that this is what I’ll look like the next time he thinks it’s okay to check and see if the hand vac can sweep water up from out of the toilet. For the curious among you out there, the answer is “yes”, though later analysis reveals that this particular application falls outside of the design specs spelled out by the manufacturer.
Next up – back to more light hearted fare.
How to make a spooky Halloween picture
October 25th, 2008 — potd
In the process of learning to be a good photographer, there are several conceptual hurdles you have to pass. The first one is how to properly control the three key elements of exposure (ISO, shutter speed, aperture) and make trade-offs between image quality, motion control, and depth of field. Another, more difficult, hurdle is learning how to control light.
The strobist blog is a great resource for learning this stuff, and I was going back and reviewing one of the posts in David’s Lighting 102 series on the importance of position and distance. A formal education in photography involves learning things like the Inverse Square Law, but the general idea is this. The closer your light source is to your subject and the farther away the background, the less background you get in the picture. And furthermore, this effect isn’t linear (this is where the “square” part comes in). The effect gets more and more pronounced as you move the light source in.
Your initial thought at seeing the picture of the skeleton might be that it was taken in a dark room. In fact, it was taken in our well-lit living room in the middle of the day as you can see here.
As you can see, the light source is very close (a couple of feet) away from the subject. To avoid blasting the subject and to emit as little light as possible, I have the flash dialed down to 1/16th power. That’s more then enough light to illuminate the skeleton, but it won’t do much beyond that. Also note that the flash is direct (i.e. not diffused with something like a shoot-through umbrella or a stofen cap). The goal here is to make this thing look scary, and harsh light is good at that. Finally, the flash is off-camera and triggered with a Pocket Wizard (a little radio transmitter).
Once the flash is set, the next set of decisions are around the exposure controls. The thing to know here though is that you’ll need to shoot in Manual exposure mode. The effect being done requires virtually no light to be collected at the sensor except that which comes from the flash. If you used one of the auto-exposure modes, it would try to go for a balanced exposure that captured the background. But, we don’t want the background – so we need to take control and ignore the camera as it yells at us and tells us we’re grossly under-exposing the image. For those who care, I ended up shooting at my camera’s maximum sync speed (shutter speed of 1/250th of a second) at ISO 100 and an aperture of f/20. Without the flash, that combination of exposure controls would have resulted in a near-black picture. But the flash lights the subject and we’re good to go.
The final step was to make a slight adjustment in the image on the computer. As shot, the background isn’t completely black – but it’s pretty darn close. So, the adjustment I made on the computer was to use the Levels control (almost any photo editing program has one of these) and force anything that was close to black down to black.











