forked from karatelabs/karate
/
copy-caller.feature
33 lines (29 loc) · 1.43 KB
/
copy-caller.feature
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
Feature: the difference with variable scoping in 'isolated' and 'shared' mode
since call is 'pass by reference' you need to clone using 'copy' if needed
Scenario: isolated scope: called feature does not over-write variables
* def someString = 'before'
* def someJson = { value: 'before' }
* def result = call read('copy-called-overwrite.feature')
* match someString == 'before'
* match someJson == { value: 'before' }
* assert typeof fromCalled == 'undefined'
Scenario: shared scope: called feature will over-write (and contribute) variables
* def someString = 'before'
* def someJson = { value: 'before' }
* call read('copy-called-overwrite.feature')
* match someString == 'after'
* match someJson == { value: 'after' }
* match fromCalled == { hello: 'world' }
Scenario: called feature updates a nested element of 'foo' using the 'set' keyword
* def foo = { key: 'value' }
# by default, complex data (JSON, XML, MAP, LIST) are passed by reference
* def result = call read('copy-called.feature')
# so callers can mutate this context !
* match foo == { key: 'changed' }
Scenario: you can manually 'clone' a payload if needed
* def original = { key: 'value' }
# since the called feature mutates 'foo' we ensure it is a clone
* copy foo = original
* def result = call read('copy-called.feature')
# and original remains unchanged
* match original == { key: 'value' }