Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal Idea: Provide a convenient way to call step with table argument within another step #183

Open
hanachin opened this issue Sep 15, 2016 · 6 comments

Comments

@hanachin
Copy link
Contributor

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
@gongo
Copy link
Collaborator

gongo commented Sep 15, 2016

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?

@hanachin
Copy link
Contributor Author

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?

@gongo
Copy link
Collaborator

gongo commented Sep 15, 2016

Can Turnip's table method receive the table string like 1st example?

Pending 🙏

@hanachin
Copy link
Contributor Author

hanachin commented Sep 15, 2016

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

@ghost
Copy link

ghost commented May 31, 2018

お久しぶりです。

この話題は、去年開催されたRuby会議3日目の帰りの電車での話題だと思います。
現在、私はturnipを使っていないのでペンディング状態のままIssueが残るのが嫌でしたらクローズして頂いて結構です。

@gongo
Copy link
Collaborator

gongo commented May 31, 2018

No problem!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants