Yaml files fixture is a specialization of FileFixture which allows YAML files to be read.
It supports YAML specification version 1.1.
Reading
In this sample we first create a .yml file, using FileFixture, and then read it.script | file fixture | ||||
set directory | http://files/test | ||||
$yaml<-[sample.yml] | create | sample.yml | containing | wine: good | |
append | #comment: ignored | to | $yaml->[sample.yml] | on new line | |
append | beer: "bad" | to | $yaml->[sample.yml] | on new line | |
show | content of | $yaml->[sample.yml] | wine: good #comment: ignored beer: "bad" |
script | yaml file fixture | |||||||
load values from | $yaml->[sample.yml] | |||||||
show | values |
| ||||||
check | value | wine | good | |||||
check | value | beer | bad | |||||
check | number of values | 2 | ||||||
We can use standard file fixture methods | ||||||||
delete | $yaml->[sample.yml] |
Writing
We can also write in an easier way:script | yaml file fixture | |||
set directory | http://files/test | |||
set value | bad | for | wine | |
set value | good | for | beer | |
set value | better | for | cola | |
$sample2<-[sample2.yml] | create | sample2.yml | containing values | |
show | content of | $sample2->[sample2.yml] | wine: bad beer: good cola: better |
script | yaml file fixture | |||||||||
load values from | $sample2->[sample2.yml] | |||||||||
show | values |
| ||||||||
check | value | wine | bad | |||||||
check | value | beer | good | |||||||
check | value | cola | better | |||||||
check | number of values | 3 | ||||||||
delete | $sample2->[sample2.yml] |
Reading array
The top level of a YAML file can be an array instead of a set of properties. In that case the fixture will create a 'root value' called elements.script | file fixture | ||||
set directory | http://files/test | ||||
$sample3<-[sample3.yml] | create | sample3.yml | containing | - wine | |
append | - beer | to | $sample3->[sample3.yml] | on new line | |
show | content of | $sample3->[sample3.yml] | - wine - beer |
script | yaml file fixture | |||||
load values from | $sample3->[sample3.yml] | |||||
show | values |
| ||||
check | value | elements[0] | wine | |||
check | value | elements[1] | beer | |||
check | number of values | 1 | ||||
delete | $sample3->[sample3.yml] |
Writing nested value
script | yaml file fixture | ||||
set directory | http://files/test | ||||
set value | white | for | wine[0] | ||
set value | red | for | wine[1] | ||
set value | rose | for | wine[2] | ||
$sample4<-[sample4.yml] | create | sample4.yml | containing value | wine | |
show | content of | $sample4->[sample4.yml] | - white - red - rose |
script | yaml file fixture | |||||
load values from | $sample4->[sample4.yml] | |||||
show | values |
| ||||
check | value | elements[0] | white | |||
check | value | elements[1] | red | |||
check | value | elements[2] | rose | |||
delete | $sample4->[sample4.yml] |
Reading binary content
script | file fixture | |||
set directory | http://files/test | |||
$bin<-[sample-bin.yml] | create | sample-bin.yml | containing | canonical: !!binary "\ R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5\ OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/+\ +f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLC\ AgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs=" description: The binary value above is a tiny arrow encoded as a gif image. |
script | yaml file fixture | ||||||||
load values from | $bin->[sample-bin.yml] | ||||||||
show | values |
| |||||||
check | value | description | The binary value above is a tiny arrow encoded as a gif image. | ||||||
$img1<-[arrow1.gif] | create | arrow1.gif | containing base64 value | canonical | |||||
$img2<-[arrow2.gif] | create | arrow2.gif | containing value | canonical | |||||
delete | $bin->[sample-bin.yml] |
Writing binary content
script | yaml file fixture | |||
set content of | $img2->[arrow2.gif] | as value for | gif | |
set base64 encoded content of | $img2->[arrow2.gif] | as value for | encoded-gif | |
set value | A small arrow image | for | description | |
$sample5<-[sample5.yml] | create | sample5.yml | containing values | |
show | content of | $sample5->[sample5.yml] | gif: !!binary |- R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/++f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLCAgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs= encoded-gif: R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/++f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLCAgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs= description: A small arrow image | |
delete | $sample5->[sample5.yml] |