Sha256: 4259930c590884e8804dbf46ed4e7264288e7859612b554e02ffdf967523f3fa

Contents?: true

Size: 861 Bytes

Versions: 14

Compression:

Stored size: 861 Bytes

Contents

[<< back](README.md)

# Macros

Macros is a technique to make it easier to write and reuse code.

**Example**

* We start from a set of repeated targets.

```ruby
target "Exist user fran"
run "id fran"
expect_one "root"

target "Exist user root"
run "id root"
expect_one "root"

target "Exist user david"
run "id david"
expect_one "david"
```

* Define a macro with the repeated block:

```ruby
define_macro "user_exists", :name do
  target "Exist user #{get(:name)}"
  run "id #{get(:name)}"
  expect_one get(:name)
end
```

* Replace the previous targets with macro calls. There are 3 ways to invoke the macro:

```ruby
user_exists(name: "fran")
user_exists(name: "root")
user_exists(name: "david")
```

**Notice**: There are 3 ways to invoke the macro:

```ruby
user_exists(name: "fran")
macro "user_exists", name: "fran"
macro_user_exists(name: "fran")
```

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
teuton-2.9.2 docs/learn/20-macros.md
teuton-2.9.1 docs/learn/20-macros.md
teuton-2.9.0 docs/learn/20-macros.md
teuton-2.8.0 docs/learn/20-macros.md
teuton-2.7.3 docs/learn/20-macros.md
teuton-2.7.2 docs/learn/20-macros.md
teuton-2.7.1 docs/learn/20-macros.md
teuton-2.7.0 docs/learn/20-macros.md
teuton-2.6.0 docs/learn/20-macros.md
teuton-2.5.0 docs/learn/20-macros.md
teuton-2.4.5 docs/learn/20-macros.md
teuton-2.4.4 docs/learn/20-macros.md
teuton-2.4.3 docs/learn/20-macros.md
teuton-2.4.2 docs/learn/20-macros.md