views:

23

answers:

1

I have an application with a product detail page. On that page the user can see prices, descriptions, specifications, all pretty standard stuff. But I want to test this view in Cucumber.

Right now I use factories to generate product identifiers and leave everything else blank. If I add defaults to the factories, then check for those same defaults in the features, then I've tightly coupled those two components (bad).

Is the only real way to do this to supply all of the values I'm testing for in the feature file itself?

A: 

Cucumber tables are a good way to handle this, and it's simple to tie them into your factories. I'm assuming that you're using FactoryGirl, but it matters little.

Scenario: I want to see some product details
    Given the following product data
          | name | price | description   | 
          | Foo  | 1.99  | Yay, it's foo |
          | Bar  | 4.99  | Yay, it's bar |

Then somewhere in your step definitions you'll want to tie this into your factory.

Given /^the following product data$/ do |table|
  table.hashes.each do |hash|
    Factory.create(:product, hash)
  end
end

Note that the 'magic' here comes from naming the table columns in the feature the same as your db columns, which become the keys in hash.

jdl
Feel free to ask more about this if I didn't answer you completely enough. It wasn't clear from your question just how much of Cucumber you were already familiar with.
jdl