cql 0.3.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -32,7 +32,7 @@ shared_examples_for 'a name filterable target set' do |target_type, test_data|
32
32
  with name matched_name
33
33
  end
34
34
 
35
- expect(result).to eq(expected)
35
+ expect(result).to match_array(expected)
36
36
  end
37
37
  end
38
38
 
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'CQL::Repository' do
4
+
5
+ clazz = CQL::Repository
6
+
7
+ it 'can be made from a file path' do
8
+ expect { clazz.new(@feature_fixtures_directory) }.to_not raise_error
9
+ end
10
+
11
+ it 'can be made from a model' do
12
+ some_model = CukeModeler::Scenario.new
13
+
14
+ expect { clazz.new(some_model) }.to_not raise_error
15
+ end
16
+
17
+ end
@@ -11,34 +11,34 @@ describe "select" do
11
11
  from features
12
12
  end
13
13
 
14
- expect(result).to eq([{"name" => "Simple"}, {"name" => "Test Feature"},
15
- {"name" => "Test2 Feature"}, {"name" => "Test3 Feature"}])
14
+ expect(result).to match_array([{"name" => "Simple"}, {"name" => "Test Feature"},
15
+ {"name" => "Test2 Feature"}, {"name" => "Test3 Feature"}])
16
16
  end
17
17
 
18
18
  it 'should return descriptions from features' do
19
19
  gs = CQL::Repository.new("#{@feature_fixtures_directory}/scenario/simple2")
20
20
 
21
21
  result = gs.query do
22
- select description
22
+ select description_text
23
23
  from features
24
24
  end
25
25
 
26
- expect(result).to eq([{"description" => "The cat in the hat"}])
26
+ expect(result).to eq([{"description_text" => "The cat in the hat"}])
27
27
  end
28
28
 
29
- it 'should return uris from features' do
29
+ it 'should return paths from from feature files' do
30
30
  repo_path = "#{@feature_fixtures_directory}/scenario/simple"
31
31
  gs = CQL::Repository.new(repo_path)
32
32
 
33
33
  result = gs.query do
34
- select uri
35
- from features
34
+ select path
35
+ from feature_files
36
36
  end
37
37
 
38
- expect(result[0]['uri']).to eq("#{repo_path}/simple.feature")
39
- expect(result[1]['uri']).to eq("#{repo_path}/test.feature")
40
- expect(result[2]['uri']).to eq("#{repo_path}/test2.feature")
41
- expect(result[3]['uri']).to eq("#{repo_path}/test_full.feature")
38
+ expect(result).to match_array([{'path' => "#{repo_path}/simple.feature"},
39
+ {'path' => "#{repo_path}/test.feature"},
40
+ {'path' => "#{repo_path}/test2.feature"},
41
+ {'path' => "#{repo_path}/test_full.feature"}])
42
42
  end
43
43
 
44
44
  it 'should return tags from features' do
@@ -49,10 +49,10 @@ describe "select" do
49
49
  from features
50
50
  end
51
51
 
52
- expect(result).to eq([{"tags" => nil},
53
- {"tags" => [{"name" => "@one", "line" => 1}]},
54
- {"tags" => [{"name" => "@two", "line" => 1}]},
55
- {"tags" => [{"name" => "@one", "line" => 1}, {"name" => "@two", "line" => 1}]}])
52
+ expect(result).to match_array([{"tags" => []},
53
+ {"tags" => ["@one"]},
54
+ {"tags" => ["@two"]},
55
+ {"tags" => ["@one", "@two"]}])
56
56
  end
57
57
 
58
58
 
@@ -64,10 +64,10 @@ describe "select" do
64
64
  from features
65
65
  end
66
66
 
67
- expect(result).to eq([{"name" => "Simple", "tags" => nil},
68
- {"name" => "Test Feature", "tags" => [{"name" => "@one", "line" => 1}]},
69
- {"name" => "Test2 Feature", "tags" => [{"name" => "@two", "line" => 1}]},
70
- {"name" => "Test3 Feature", "tags" => [{"name" => "@one", "line" => 1}, {"name" => "@two", "line" => 1}]}])
67
+ expect(result).to match_array([{"name" => "Simple", "tags" => []},
68
+ {"name" => "Test Feature", "tags" => ["@one"]},
69
+ {"name" => "Test2 Feature", "tags" => ["@two"]},
70
+ {"name" => "Test3 Feature", "tags" => ["@one", "@two"]}])
71
71
  end
72
72
 
73
73
  it 'should return things from multiple feature files' do
@@ -78,9 +78,9 @@ describe "select" do
78
78
  from features
79
79
  end
80
80
 
81
- expect(result).to eq([{"name" => "f1_1_tag"},
82
- {"name" => "f2_2_tags"},
83
- {"name" => "f3_3_tags"}])
81
+ expect(result).to match_array([{"name" => "f1_1_tag"},
82
+ {"name" => "f2_2_tags"},
83
+ {"name" => "f3_3_tags"}])
84
84
  end
85
85
 
86
86
  it 'should return multiple features as a list of maps' do
@@ -91,101 +91,23 @@ describe "select" do
91
91
  from features
92
92
  end
93
93
 
94
- expect(result).to eq([{"name" => "f1_1_tag"},
95
- {"name" => "f2_2_tags"},
96
- {"name" => "f3_3_tags"}])
94
+ expect(result).to match_array([{"name" => "f1_1_tag"},
95
+ {"name" => "f2_2_tags"},
96
+ {"name" => "f3_3_tags"}])
97
97
  end
98
98
 
99
99
  it 'should return ids from features' do
100
100
  gs = CQL::Repository.new("#{@feature_fixtures_directory}/scenario/simple2")
101
101
 
102
102
  result = gs.query do
103
- select id
103
+ select raw_element
104
+ as 'id'
105
+ transform 'raw_element' => lambda { |element| element['id'] }
104
106
  from features
105
107
  end
106
108
 
107
109
  expect(result).to eq([{"id" => "test3-feature"}])
108
110
  end
109
111
 
110
- it "should return all, complete, everything from features" do
111
- gr = CQL::Repository.new("#{@feature_fixtures_directory}/scenario/simple2")
112
-
113
- expected = [{"all" => {"keyword" => "Feature",
114
- "name" => "Test3 Feature",
115
- "line" => 2,
116
- "description" => "The cat in the hat",
117
- "tags" => [{"name" => "@top-tag", "line" => 1}],
118
- "id" => "test3-feature",
119
- "uri" => "fake_file.txt",
120
- "elements" => [{"keyword" => "Scenario",
121
- "name" => "Testing the slurping",
122
- "line" => 6,
123
- "description" => "",
124
- "tags" => [{"name" => "@one", "line" => 5}],
125
- "id" => "test3-feature;testing-the-slurping",
126
- "type" => "scenario",
127
- "steps" => [{"keyword" => "Given ", "name" => "something happend", "line" => 7},
128
- {"keyword" => "Then ", "name" => "I expect something else", "line" => 8}]},
129
- {"keyword" => "Scenario",
130
- "name" => "Testing again",
131
- "line" => 11,
132
- "description" => "",
133
- "tags" => [{"name" => "@two", "line" => 10}],
134
- "id" => "test3-feature;testing-again",
135
- "type" => "scenario",
136
- "steps" => [{"keyword" => "Given ", "name" => "something happend", "line" => 12},
137
- {"keyword" => "Then ", "name" => "I expect something else", "line" => 13}]},
138
- {"keyword" => "Scenario",
139
- "name" => "Testing yet again",
140
- "line" => 16,
141
- "description" => "",
142
- "tags" => [{"name" => "@one", "line" => 15}],
143
- "id" => "test3-feature;testing-yet-again",
144
- "type" => "scenario",
145
- "steps" => [{"keyword" => "Given ", "name" => "something happend", "line" => 17},
146
- {"keyword" => "Then ", "name" => "I expect something else", "line" => 18}]},
147
- {"keyword" => "Scenario",
148
- "name" => "Testing yet again part 2",
149
- "line" => 21,
150
- "description" => "",
151
- "tags" => [{"name" => "@one", "line" => 20}, {"name" => "@two", "line" => 20}],
152
- "id" => "test3-feature;testing-yet-again-part-2",
153
- "type" => "scenario",
154
- "steps" => [{"keyword" => "Given ", "name" => "something happend", "line" => 22},
155
- {"keyword" => "Then ", "name" => "I expect something else", "line" => 23}]}]}}]
156
-
157
- result = gr.query do
158
- select all
159
- from features
160
- end
161
- expect(result).to eq(expected)
162
-
163
- result = gr.query do
164
- select complete
165
- from features
166
- end
167
- expect(result).to eq(expected)
168
-
169
- result = gr.query do
170
- select everything
171
- from features
172
- end
173
- expect(result).to eq(expected)
174
- end
175
-
176
- # it 'should return simplified tags' do
177
- # skip
178
- #
179
- # gs = CQL::Repository.new("#{@feature_fixtures_directory}/scenario/tagged_features")
180
- # result = gs.query do
181
- # select name, basic_tag
182
- # from features
183
- # end
184
- #
185
- # expect(result).to eq([{"tags" => nil},
186
- # {"tags" => "@one"},
187
- # {"tags" => "@two"},
188
- # "tags" => "@two"])
189
- # end
190
112
  end
191
113
  end
@@ -8,41 +8,41 @@ describe "select" do
8
8
 
9
9
  result = gs.query do
10
10
  select tags
11
- from scenario_outlines
12
- end
13
-
14
- expect(result).to eq([{"tags" => [{"name" => "@two", "line" => 3}]},
15
- {"tags" => [{"name" => "@one", "line" => 13}]},
16
- {"tags" => nil},
17
- {"tags" => [{"name" => "@two", "line" => 24}]},
18
- {"tags" => [{"name" => "@one", "line" => 30}]},
19
- {"tags" => [{"name" => "@two", "line" => 3}, {"name" => "@four", "line" => 3}]},
20
- {"tags" => [{"name" => "@one", "line" => 13}, {"name" => "@five", "line" => 13}]},
21
- {"tags" => nil},
22
- {"tags" => [{"name" => "@two", "line" => 24}]},
23
- {"tags" => [{"name" => "@one", "line" => 30}]}])
11
+ from outlines
12
+ end
13
+
14
+ expect(result).to match_array([{"tags" => ["@two"]},
15
+ {"tags" => ["@one"]},
16
+ {"tags" => []},
17
+ {"tags" => ["@two"]},
18
+ {"tags" => ["@one"]},
19
+ {"tags" => ["@two", "@four"]},
20
+ {"tags" => ["@one", "@five"]},
21
+ {"tags" => []},
22
+ {"tags" => ["@two"]},
23
+ {"tags" => ["@one"]}])
24
24
  end
25
25
 
26
26
  it 'should return descriptions from scenario outlines' do
27
27
  gs = CQL::Repository.new("#{@feature_fixtures_directory}/scen_outlines/multiple_examples")
28
28
 
29
29
  result = gs.query do
30
- select description
31
- from scenario_outlines
30
+ select description_text
31
+ from outlines
32
32
  end
33
33
 
34
- expect(result).to eq([{"description" => ""}, {"description" => "Outline description."}])
34
+ expect(result).to eq([{"description_text" => ""}, {"description_text" => "\nOutline description."}])
35
35
  end
36
36
 
37
37
  it 'should return lines from scenario outlines' do
38
38
  gs = CQL::Repository.new("#{@feature_fixtures_directory}/scen_outlines/basic")
39
39
 
40
40
  result = gs.query do
41
- select line
42
- from scenario_outlines
41
+ select source_line
42
+ from outlines
43
43
  end
44
44
 
45
- expect(result).to eq([{"line" => 3}])
45
+ expect(result).to eq([{"source_line" => 3}])
46
46
  end
47
47
 
48
48
  it 'should return names from scenario outlines' do
@@ -50,7 +50,7 @@ describe "select" do
50
50
 
51
51
  result = gs.query do
52
52
  select name
53
- from scenario_outlines
53
+ from outlines
54
54
  end
55
55
 
56
56
  expect(result).to eq([{"name" => "An Outline"}])
@@ -60,8 +60,10 @@ describe "select" do
60
60
  gs = CQL::Repository.new("#{@feature_fixtures_directory}/scen_outlines/basic")
61
61
 
62
62
  result = gs.query do
63
- select type
64
- from scenario_outlines
63
+ select raw_element
64
+ as 'type'
65
+ transform 'raw_element' => lambda { |element| element['type'] }
66
+ from outlines
65
67
  end
66
68
 
67
69
  expect(result).to eq([{"type" => "scenario_outline"}])
@@ -71,8 +73,10 @@ describe "select" do
71
73
  gs = CQL::Repository.new("#{@feature_fixtures_directory}/scen_outlines/basic")
72
74
 
73
75
  result = gs.query do
74
- select step_lines
75
- from scenario_outlines
76
+ select raw_element
77
+ as step_lines
78
+ transform 'raw_element' => lambda { |element| element['steps'].collect { |step| step['keyword'] + step['name'] } }
79
+ from outlines
76
80
  end
77
81
 
78
82
  expect(result).to eq([{"step_lines" => ["Given something happend", "Then I expect something else"]}])
@@ -82,8 +86,10 @@ describe "select" do
82
86
  gs = CQL::Repository.new("#{@feature_fixtures_directory}/scen_outlines/basic")
83
87
 
84
88
  result = gs.query do
85
- select id
86
- from scenario_outlines
89
+ select raw_element
90
+ as 'id'
91
+ transform 'raw_element' => lambda { |element| element['id'] }
92
+ from outlines
87
93
  end
88
94
 
89
95
  expect(result).to eq([{"id" => "test-feature;an-outline"}])
@@ -93,8 +99,10 @@ describe "select" do
93
99
  gs = CQL::Repository.new("#{@feature_fixtures_directory}/scen_outlines/basic")
94
100
 
95
101
  result = gs.query do
96
- select steps
97
- from scenario_outlines
102
+ select raw_element
103
+ as steps
104
+ transform 'raw_element' => lambda { |element| element['steps'] }
105
+ from outlines
98
106
  end
99
107
 
100
108
  expect(result).to eq([{"steps" => [{"keyword" => "Given ", "name" => "something happend", "line" => 4}, {"keyword" => "Then ", "name" => "I expect something else", "line" => 5}]}])
@@ -106,11 +114,11 @@ describe "select" do
106
114
 
107
115
  result = gs.query do
108
116
  select name, tags
109
- from scenario_outlines
117
+ from outlines
110
118
  end
111
119
 
112
- expect(result).to eq([{"name" => "An Outline", "tags" => nil},
113
- {"name" => "An Outline with everything", "tags" => [{"name" => "@outline_tag", "line" => 21}]}])
120
+ expect(result).to eq([{"name" => "An Outline", "tags" => []},
121
+ {"name" => "An Outline with everything", "tags" => ["@outline_tag"]}])
114
122
  end
115
123
 
116
124
  it 'should return things from multiple feature files' do
@@ -118,19 +126,19 @@ describe "select" do
118
126
 
119
127
  result = gr.query do
120
128
  select name
121
- from scenario_outlines
122
- end
123
-
124
- expect(result).to eq([{"name" => "Has a table"},
125
- {"name" => "Next"},
126
- {"name" => "Another"},
127
- {"name" => "Blah"},
128
- {"name" => "Another"},
129
- {"name" => "Has a table hmmm"},
130
- {"name" => "Next"},
131
- {"name" => "Another"},
132
- {"name" => "Blah blah"},
133
- {"name" => "Another"}])
129
+ from outlines
130
+ end
131
+
132
+ expect(result).to match_array([{"name" => "Has a table"},
133
+ {"name" => "Next"},
134
+ {"name" => "Another"},
135
+ {"name" => "Blah"},
136
+ {"name" => "Another"},
137
+ {"name" => "Has a table hmmm"},
138
+ {"name" => "Next"},
139
+ {"name" => "Another"},
140
+ {"name" => "Blah blah"},
141
+ {"name" => "Another"}])
134
142
  end
135
143
 
136
144
  it 'should return multiple scenario outlines as a list of maps' do
@@ -138,7 +146,7 @@ describe "select" do
138
146
 
139
147
  result = gr.query do
140
148
  select name
141
- from scenario_outlines
149
+ from outlines
142
150
  end
143
151
 
144
152
  expect(result).to be_an_instance_of(Array)
@@ -151,8 +159,10 @@ describe "select" do
151
159
  it "should return the examples from scenario outlines" do
152
160
  gr = CQL::Repository.new("#{@feature_fixtures_directory}/scen_outlines/basic")
153
161
  result = gr.query do
154
- select examples
155
- from scenario_outlines
162
+ select raw_element
163
+ as examples
164
+ transform 'raw_element' => lambda { |element| element['examples'] }
165
+ from outlines
156
166
  end
157
167
 
158
168
  expect(result).to eq([{"examples" => [{"keyword" => "Examples", "name" => "", "line" => 6,
@@ -167,8 +177,10 @@ describe "select" do
167
177
  it "should return multiple examples used for a single scenario outline" do
168
178
  gr = CQL::Repository.new("#{@feature_fixtures_directory}/scen_outlines/multiple_examples")
169
179
  result = gr.query do
170
- select examples
171
- from scenario_outlines
180
+ select raw_element
181
+ as examples
182
+ transform 'raw_element' => lambda { |element| element['examples'] }
183
+ from outlines
172
184
  end
173
185
 
174
186
  expect(result).to eq([{"examples" => [{"keyword" => "Examples", "name" => "One", "line" => 6, "description" => "", "id" => "test-feature;an-outline;one",
@@ -189,126 +201,23 @@ describe "select" do
189
201
  {"cells" => ["2", "b"], "line" => 42, "id" => "test-feature;an-outline-with-everything;two;3"}]}]}])
190
202
  end
191
203
 
192
-
193
- it "should return all, complete, everything from scenario_outlines" do
194
- gr = CQL::Repository.new("#{@feature_fixtures_directory}/scen_outlines/multiple_examples")
195
-
196
-
197
- expected = [{"all" => {"keyword" => "Scenario Outline",
198
- "name" => "An Outline",
199
- "line" => 3,
200
- "description" => "",
201
- "id" => "test-feature;an-outline",
202
- "type" => "scenario_outline",
203
- "steps" => [{"keyword" => "Given ",
204
- "name" => "something happend",
205
- "line" => 4},
206
- {"keyword" => "Then ",
207
- "name" => "I expect something else",
208
- "line" => 5}],
209
- "examples" => [{"keyword" => "Examples",
210
- "name" => "One",
211
- "line" => 6,
212
- "description" => "",
213
- "id" => "test-feature;an-outline;one",
214
- "rows" => [{"cells" => ["var_a", "var_b"],
215
- "line" => 7,
216
- "id" => "test-feature;an-outline;one;1"},
217
- {"cells" => ["1", "a"],
218
- "line" => 8,
219
- "id" => "test-feature;an-outline;one;2"},
220
- {"cells" => ["2", "b"],
221
- "line" => 9,
222
- "id" => "test-feature;an-outline;one;3"}]},
223
- {"keyword" => "Examples",
224
- "name" => "Two",
225
- "line" => 11,
226
- "description" => "",
227
- "id" => "test-feature;an-outline;two",
228
- "rows" => [{"cells" => ["var_a", "var_b"],
229
- "line" => 12,
230
- "id" => "test-feature;an-outline;two;1"},
231
- {"cells" => ["1", "a"],
232
- "line" => 13,
233
- "id" => "test-feature;an-outline;two;2"},
234
- {"cells" => ["2", "b"],
235
- "line" => 14,
236
- "id" => "test-feature;an-outline;two;3"}]}]}},
237
- {"all" => {"keyword" => "Scenario Outline",
238
- "name" => "An Outline with everything",
239
- "line" => 22,
240
- "description" => "\nOutline description.",
241
- "tags" => [{"name" => "@outline_tag",
242
- "line" => 21}],
243
- "id" => "test-feature;an-outline-with-everything",
244
- "type" => "scenario_outline",
245
- "steps" => [{"keyword" => "Given ",
246
- "name" => "something happend",
247
- "line" => 26,
248
- "rows" => [{"cells" => ["a", "a"],
249
- "line" => 27},
250
- {"cells" => ["s", "a"],
251
- "line" => 28},
252
- {"cells" => ["s", "s"],
253
- "line" => 29}]},
254
- {"keyword" => "Then ",
255
- "name" => "I expect something else",
256
- "line" => 30}],
257
- "examples" => [{"keyword" => "Examples",
258
- "name" => "One",
259
- "line" => 31,
260
- "description" => "This is example One.",
261
- "id" => "test-feature;an-outline-with-everything;one",
262
- "rows" => [{"cells" => ["var_a", "var_b"],
263
- "line" => 34,
264
- "id" => "test-feature;an-outline-with-everything;one;1"},
265
- {"cells" => ["1", "a"],
266
- "line" => 35,
267
- "id" => "test-feature;an-outline-with-everything;one;2"},
268
- {"cells" => ["2", "b"],
269
- "line" => 36,
270
- "id" => "test-feature;an-outline-with-everything;one;3"}]},
271
- {"keyword" => "Examples",
272
- "name" => "Two",
273
- "line" => 39,
274
- "description" => "",
275
- "tags" => [{"name" => "@example_tag",
276
- "line" => 38}],
277
- "id" => "test-feature;an-outline-with-everything;two",
278
- "rows" => [{"cells" => ["var_a", "var_b"],
279
- "line" => 40,
280
- "id" => "test-feature;an-outline-with-everything;two;1"},
281
- {"cells" => ["1", "a"],
282
- "line" => 41,
283
- "id" => "test-feature;an-outline-with-everything;two;2"},
284
- {"cells" => ["2", "b"],
285
- "line" => 42,
286
- "id" => "test-feature;an-outline-with-everything;two;3"}]}]}}]
287
-
288
- result = gr.query do
289
- select all
290
- from scenario_outlines
291
- end
292
- expect(result).to eq(expected)
293
-
294
- result = gr.query do
295
- select complete
296
- from scenario_outlines
297
- end
298
- expect(result).to eq(expected)
299
-
300
- result = gr.query do
301
- select everything
302
- from scenario_outlines
303
- end
304
- expect(result).to eq(expected)
305
- end
306
-
307
204
  it 'should return scenario outlines name and line numbers as a map' do
308
205
  gs = CQL::Repository.new("#{@feature_fixtures_directory}/scen_outlines/basic")
309
206
  result = gs.query do
310
- select name, line, type, step_lines, id, steps
311
- from scenario_outlines
207
+ select name, source_line, raw_element, raw_element, raw_element, raw_element
208
+ as 'source_line' => 'line'
209
+ as 'raw_element' => 'id'
210
+ as 'raw_element' => 'type'
211
+ as 'raw_element' => 'steps'
212
+ as 'raw_element' => 'step_lines'
213
+
214
+ transform 'raw_element' => lambda { |element| element['id'] }
215
+ transform 'raw_element' => lambda { |element| element['type'] }
216
+ transform 'raw_element' => lambda { |element| element['steps'] }
217
+ transform 'raw_element' => lambda { |element| element['steps'].collect { |step| step['keyword'] + step['name'] } }
218
+
219
+
220
+ from outlines
312
221
  end
313
222
 
314
223
  expect(result).to eq([{'name' => "An Outline",