10
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

TurnipのStep内から他のTable Stepを呼び出す

Last updated at Posted at 2014-05-27

やりたいこと

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        |

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

結論

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
10
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?