Proposal Idea: Provide a convenient way to call step with table argument within another step
hanachin opened this issue · 6 comments
I use Turnip::Table.new
to call step that takes table argument, like following:
step "There are admin user :user of :company_name" do |user, company_name|
table = Turnip::Table.new([['name', 'admin'], [user, 'true']])
step "There are employees of #{company_name} :", table
end
step "There are employees of :company_name :" do |company_name, table|
company = Company.find_by!(name: company_name)
table.hashes.each do |row|
user = company.users.create!(row.slice('name'))
if row['admin']
user.admin!
end
end
end
But Turnip::Table.new
example is not in README. Is it a private API?
I want convert the array to Turnip::Table
implicitly when passing the array to another step like following:
step "There are admin user :user of :company_name" do |user, company_name|
# Passing as Array
step "There are employees of #{company_name} :", [['name', 'admin'], [user, 'true']]
end
step "There are employees of :company_name :" do |company_name, table|
company = Company.find_by!(name: company_name)
# table is a `Turnip::Table` instance from the array
table.hashes.each do |row|
user = company.users.create!(row.slice('name'))
if row['admin']
user.admin!
end
end
end
Hi @hanachin . Thanks for proposal.
But Turnip::Table.new example is not in README. Is it a private API?
Yes (for now).
I want convert the array to Turnip::Table implicitly when passing the array to another step like following:
I understand 🙆♀️ .
By the way, Cucumber realized like the following code:
Given /A simple expense report/ do
step "an expense report for Jan 2009 with the following posts:", table(%{
| account | description | amount |
| INT-100 | Taxi | 114 |
| CUC-101 | Peeler | 22 |
})
end
## or
Given /A simple expense report/ do
step "an expense report for Jan 2009 with the following posts:", table([
%w{ account description amount },
%w{ INT-100 Taxi 114 },
%w{ CUC-101 Peeler 22 }
])
end
refs: Calling Steps from Step Definitions · cucumber/cucumber Wiki
Cucumber provides table()
alias for pass Cucumber::Ast::Table
Turnip also might provide as similar avoid code (dont use Turnip::Table.new
).
What do you think?
I didn't know that the cucumber has API to explicitly convert string or array to the table, thanks for quick reply😄
I'm ok to call new DSL table
explicitly 👍
Cucumber provides table() alias for pass Cucumber::Ast::Table
Turnip also might provide as similar avoid code (dont use Turnip::Table.new).
Can Turnip's table
method receive the table string like 1st example?
Can Turnip's table method receive the table string like 1st example?
Pending 🙏
Pending 🙏
I got it! If turnip provide the table()
that works like 2nd example, it is good enough in my use case!
But IMHO the 1st example is more readable than 2nd one :P
お久しぶりです。
この話題は、去年開催されたRuby会議3日目の帰りの電車での話題だと思います。
現在、私はturnipを使っていないのでペンディング状態のままIssueが残るのが嫌でしたらクローズして頂いて結構です。
No problem!