MacksMind

Technical Wizardry, Rants, and just a Whiff of Insanity

Verifying select field value with Cucumber and Webrat

I’ve been using Cucumber and Webrat for only a couple months now. Today I needed something new and it wasn’t obvious how to make it work.

Here’s an example of a test in Cucumber:

Given I am Sam
When I follow "Foo"
Then the "Bar" field should contain "Baz"

Which relies on Webrat:


Then /^the "([^"]*)" field should contain "([^"]*)"$/ do |field, value|
  field_labeled(field).value.should =~ /#{value}/
end

But what if it’s not a text field? What if it’s a select? Then we need to check which value is selected.

Given Sam I am
When I follow "Foo"
Then "Baz" should be selected for "Bar"

Here’s my solution:


Then /^"([^"]*)" should be selected for "([^"]*)"$/ do |value, field|
  field_labeled(field).element.search(".//option[@selected = 'selected']").inner_html.should =~ /#{value}/
end

Hope this helps!

Installing mod_rails on Ubuntu Hardy

First, install these packages using apt-get or aptitude:

  • ruby
  • rubygems
  • ruby1.8-dev
  • build-essential
  • apache2-mpm-prefork
  • apache2-prefork-dev

[Read the rest of this entry...]

Moments of Clarity

How do you use your Windshield Time? You know, the time you spend alone in your car. Many use it to listen to music or talk radio. Others may catch up on phone calls or, faith defend us, email and text messages! If you tell me you don’t use it, you’re wrong. Even using it to contemplate is using the time, and you have consciously or unconsciously chosen to use it in that particular way. But maybe that’s not the real question. Meander with me for a bit…

[Read the rest of this entry...]

The Longoria Identity

Playing the Hot Corner

If you’re confused about Eva Longoria of Desperate Housewives vs. Evan Longoria of the Tampa Bay Rays, I say it doesn’t matter. They’re both winners… they just play for different teams. ;-)

Using belongs_to in Rails model validations when the parent is unsaved

Can’t get there from here

In one of my Ruby on Rails projects, I have a model validation which is dependent on attributes from a belongs_to parent. Normally, you can refer to a parent model as child.parent and access the parent’s attributes as child.parent.attr. The difficulty arises when the parent object is unsaved. Let’s look at the code:

[Read the rest of this entry...]

Integrating your WordPress Blog with Google Analytics

If you’re like me, you’d like to know whether anyone is paying attention to what you have to say online. There are plugins for WordPress that will make this information available through the wp-admin pages. There are also tools such as AWStats that your hosting provider can likely provide. If you’ve outgrown those options, you may get what you need from Google Analytics. Whether you need it or just want it because you can, here are the basic steps:

[Read the rest of this entry...]

Moving to WordPress

Well, here it is my blog is only a week old and I’m already switching to a different engine on the back end. As I find my way around WordPress I’ll get the old content moved over.

My primary reason for moving is the apparent lack of full support for trackback in Typo.

Speeding School Bus

So I was rolling through a 25MPH School Zone yesterday at 35MPH. I know, I’m bad, I should be punished. ;-) Then why the hell was the Washington Township school bus passing me!

Economic Misfortune

Apparently, Madonna, Justin Timberlake, and Timbaland originally had 5 minutes to save the world. Until, that is, Warner Bros insisted on a 20% across the board cost reduction.

Twitter is the new CNN

I noted with some interest Douglass Karr’s post on Twitter as a search engine last month. I don’t have enough contacts to receive the benefits he describes, but I found another raison d’etre for Twitter this morning. While drinking coffee and contemplating the best use of the hour before my kids awake, Something gently picked up my apartment and shook it. There was a rattle of dishes, and I could see my refrigerator wobbling to and fro. My 8 year old was roused from her bed by the shaking and of course wanted an explanation.

[Read the rest of this entry...]