开发者

How can I test with Cucumber when I require the data in question?

开发者 https://www.devze.com 2023-03-12 14:47 出处:网络
I have an application that has users.When users are created, a related account model is also created that creates the basis of a lot of the paths in the application.

I have an application that has users. When users are created, a related account model is also created that creates the basis of a lot of the paths in the application.

For instance: /accounts/:account_id/funds

We a开发者_运维问答re using the accounts uuid as the :account_id in the path (via to_param)

In my cucumber tests I want to hit the above URL, but need to know the account uuid for the user in question.

Therefore, how can I build a path that will work against the data I currently have in my database?


So the best way to do this is to create all the needed data at the beginning of the test. In my own project I avoid seeding the database external to my scenarios.

You can do this easily with the "Given" construct. By way of example:

Given the following URLs:
  | url            | name  | etc...
  | www.foo.com    | Foo   | ...

You will get the contents of those pipe delimited rows as a list of hashes with the heading as the key in each row to the related value. In the step you'll have to write, you can zoom through the hashes and build up your required data as described.

Given /^the following URLs?:$/ do |urls|
  urls.hashes.each do | url_hash |
    url= URL.new
    url.url = url_hash[:url]
    url.title = url_hash[:name]
    ...
    url.save!
  end
end

In my tests I have a series of objects that all need to be set up correctly in relation to each other. So I have a series of related "Given" steps that help me build up the data.

I hope this answers your question

0

精彩评论

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

关注公众号