やりたいこと
Turnip の Step 内から他の Table Step を呼び出したい
Turnip の Step 内では send や step というメソッドで他の Step を呼び出すことが出来る
しかし、Table Step を呼び出したいときは、
Table 部分の引数をどのようにすれば与えれば良いのか困ったのでメモ
Table Step
Table Step とは以下のように引数を Table 形式で受け取る Step
Given there are the following monsters:
| Name | Hitpoints |
| Blaaarg | 23 |
| Moorg | 12 |
- Table Steps: https://github.com/jnicklas/turnip#table-steps
Step 内で他 Step の呼び出し
step "the value is :num" do |num|
@value = num
end
step "the value is twice as much as :num" do |num|
send "the value is :num", num * 2
end
step "the value is the magic number" do
step "the value is 3"
end
- Calling steps from other steps:https://github.com/jnicklas/turnip#calling-steps-from-other-steps
結論
Turnip::Table.new で Step の引数に与えるパラメータを生成する
例
step "there are the following monsters:" do |monsters|
# Table 形式のパラメータ monsters に対する処理
end
step "call another table step" do
# Table 形式のパラメータ生成
monsters = Turnip::Table.new([
["Name", "Hitpoints"],
["Blaaarg", "23"],
["Moorg", "12"],
])
# 上記の Table Step を呼び出す
step "there are the following monsters:", monsters
end