-
Notifications
You must be signed in to change notification settings - Fork 34
/
feature_execution_test.exs
192 lines (156 loc) · 6.18 KB
/
feature_execution_test.exs
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
Code.require_file("test_helper.exs", __DIR__)
defmodule Cabbage.FeatureExecutionTest do
use ExUnit.Case
describe "Tests execution" do
test "ignores steps that doesn't comply to pattern {:ok, map}" do
defmodule FeatureExecutionTest do
use Cabbage.Feature, file: "simple.feature"
setup do
{:ok, %{state: [:initial]}}
end
defgiven ~r/^I provide Given$/, _vars, %{state: state} do
[:given | state]
end
defgiven ~r/^I provide And$/, _vars, %{state: state} do
assert [:initial] == state
nil
end
defwhen ~r/^I provide When$/, _vars, %{state: state} do
assert [:initial] == state
:ok
end
defthen ~r/^I provide Then$/, _vars, %{state: state} do
assert state == [:initial]
end
end
{result, _output} = CabbageTestHelper.run()
assert result == %{failures: 0, skipped: 0, total: 1, excluded: 0}
end
test "error on returning {:ok, not a map}" do
defmodule FeatureExecutionTest2 do
use Cabbage.Feature, file: "simplest.feature"
defthen ~r/^I provide Then$/, _vars, _state do
{:ok, [some: :some]}
end
end
{result, output} = CabbageTestHelper.run()
assert result == %{failures: 1, skipped: 0, total: 1, excluded: 0}
assert output =~ "** (BadMapError) expected a map, got: [some: :some]"
end
test "accepts state steps that does comply to pattern {:ok, map}" do
defmodule FeatureExecutionTest3 do
use Cabbage.Feature, file: "simple.feature"
setup do
{:ok, %{state: [:initial]}}
end
defgiven ~r/^I provide Given$/, _vars, %{state: state} do
assert [:initial] == state
{:ok, %{state: [:given | state]}}
end
defgiven ~r/^I provide And$/, _vars, %{state: state} do
assert [:given, :initial] == state
{:ok, %{state: [:given | state]}}
end
defwhen ~r/^I provide When$/, _vars, %{state: state} do
assert [:given, :given, :initial] == state
{:ok, %{state: [:when | state]}}
end
defthen ~r/^I provide Then$/, _vars, %{state: state} do
assert state == [:when, :given, :given, :initial]
end
end
{result, _output} = CabbageTestHelper.run()
assert result == %{failures: 0, skipped: 0, total: 1, excluded: 0}
end
end
describe "Tests contains dynamic and outlined data" do
test "dynamic patternmatched data are passed to steps" do
defmodule FeatureExecutionTest4 do
use Cabbage.Feature, file: "dynamic.feature"
defgiven ~r/^I provide Given with \'(?<string_1>[^\']+)\' part$/, %{string_1: string_1}, _state do
assert string_1 == "given dynamic"
end
defwhen ~r/^I provide When with \"(?<string_1>[^\"]+)\" part and with one more \"(?<string_2>[^\"]+)\" part$/,
%{string_1: string_1, string_2: string_2},
_state do
assert string_1 == "when dynamic"
assert string_2 == "another when dynamic"
end
defthen ~r/^I provide Then with number (?<number_1>\d+) part and with docs part$/,
%{number_1: number_1, doc_string: doc_string},
_state do
complex_string = """
Here is provided some complex part that is way to complex
"""
# TODO: Shouldn't it be casted to a integer?
assert number_1 == "6"
assert doc_string == complex_string
end
defthen ~r/^I provide And with \"(?<string_1>[^\"]+)\" part and with one more \"(?<string_2>[^\"]+)\" part and with table part$/,
%{string_1: string_1, string_2: string_2, table: table},
_state do
assert string_1 == "and dynamic"
assert string_2 == "another and dynamic"
assert table == [%{Age: "30", Name: "John"}, %{Age: "29", Name: "Ann"}]
end
end
{result, _output} = CabbageTestHelper.run()
assert result == %{failures: 0, skipped: 0, total: 1, excluded: 0}
end
test "outlined data are passed to steps" do
defmodule FeatureExecutionTest5 do
use Cabbage.Feature, file: "outline.feature"
setup do
datatable = %{
"a" => "b",
"c" => "d",
"e" => "f",
2 => 3,
3 => 5,
5 => 8
}
{:ok, %{datatable: datatable}}
end
defgiven ~r/^there is given (?<string_1>[^\" ]+) value$/, %{string_1: string_1}, %{datatable: datatable} do
assert string_1 in Map.keys(datatable)
{:ok, %{given_value: string_1}}
end
defgiven ~r/^there is given numeric (?<number_1>\d+) value$/, %{number_1: number_1}, %{datatable: datatable} do
number_1 = String.to_integer(number_1)
assert number_1 in Map.keys(datatable)
{:ok, %{given_value: number_1}}
end
defwhen ~r/^there is when (?<string_1>[^\" ]+) value$/, %{string_1: string_1}, %{
datatable: datatable,
given_value: given
} do
assert string_1 == Map.get(datatable, given)
{:ok, %{when_value: string_1}}
end
defwhen ~r/^there is when numeric (?<number_1>\d+) value$/, %{number_1: number_1}, %{
datatable: datatable,
given_value: given
} do
number_1 = String.to_integer(number_1)
assert number_1 == Map.get(datatable, given)
{:ok, %{when_value: number_1}}
end
defthen ~r/^there is then (?<string_1>[^\" ]+) value$/, %{string_1: string_1}, %{
given_value: given_value,
when_value: when_value
} do
assert string_1 == given_value <> when_value
end
defthen ~r/^there is then numeric (?<number_1>\d+) value$/, %{number_1: number_1}, %{
given_value: given_value,
when_value: when_value
} do
number_1 = String.to_integer(number_1)
assert number_1 == given_value + when_value
end
end
{result, _output} = CabbageTestHelper.run()
assert result == %{failures: 0, skipped: 0, total: 6, excluded: 0}
end
end
end