开发者

How can I test a view of product detail information in Cucumber?

I have an a开发者_如何学Cpplication 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜