cql 0.3.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cql.rb +86 -34
- data/lib/cql/dsl.rb +152 -0
- data/lib/cql/feature_filters.rb +14 -0
- data/lib/cql/filters.rb +74 -0
- data/lib/cql/map_reduce.rb +48 -0
- data/lib/cql/sso_filters.rb +26 -0
- data/lib/cql/version.rb +3 -0
- data/spec/dsl_spec.rb +51 -0
- data/spec/filter_example_spec.rb +65 -0
- data/spec/filter_feature_dsl_spec.rb +13 -12
- data/spec/filter_sso_spec.rb +54 -14
- data/spec/line_count_filterable_specs.rb +4 -4
- data/spec/map_reduce_spec.rb +13 -11
- data/spec/multiple_queries_spec.rb +5 -9
- data/spec/name_filterable_specs.rb +1 -1
- data/spec/repository_spec.rb +17 -0
- data/spec/select_feature_dsl_spec.rb +28 -106
- data/spec/select_scen_outline_dsl_spec.rb +75 -166
- data/spec/select_scenario_dsl_spec.rb +37 -72
- data/spec/spec_helper.rb +4 -1
- data/spec/tag_filterable_specs.rb +5 -5
- metadata +79 -12
- checksums.yaml +0 -15
- data/lib/dsl.rb +0 -111
- data/lib/feature_filters.rb +0 -89
- data/lib/map_reduce.rb +0 -104
- data/lib/sso_filters.rb +0 -82
checksums.yaml
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
---
|
2
|
-
!binary "U0hBMQ==":
|
3
|
-
metadata.gz: !binary |-
|
4
|
-
ODIxODczMTZmOTQwODJjMGFjODIwZjE5Zjk2OWJhYzY2YTQ0MzMzNA==
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
OWMyODEwMzRmOGZkMDlkZGFhNzcyOTQ2OTNlZTViZmQ4OTVhOTk0Nw==
|
7
|
-
!binary "U0hBNTEy":
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
Yzg2YzE0YjNjZmY1NGMxNDMzY2QxNDFiZTMxOTU5NDE5NDNhMmZlMTJkY2Vi
|
10
|
-
YzRiNjQwMzk2OGYyNjYzNTg1NzM3YmM3M2M1OTBhNzM2ZWY1NDZjN2I2N2Mx
|
11
|
-
MjYzMmYyNTA2NzJiNzExOTk2MmFlMzI4NmQ3ZWFkNzliYTQwNzI=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
NDg5MGNjNmYxZGRkODE0ODNmNmU1M2MyNjlkY2RhOGE0NDNjZDhiZjExYzhh
|
14
|
-
YTAzNzE3YTc4NDU4ZDg1MGNkM2M0MGMxYmFhMGIyN2I5YjcxYWViOGQ1YmM5
|
15
|
-
Nzk0ZTZlN2UyNmIzZGUzNTM4NWI5MDQxMDk0M2Y4MjI3ZjcwZjM=
|
data/lib/dsl.rb
DELETED
@@ -1,111 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/map_reduce"
|
2
|
-
module CQL
|
3
|
-
module Dsl
|
4
|
-
#Select clause
|
5
|
-
def select *what
|
6
|
-
@what = what
|
7
|
-
end
|
8
|
-
|
9
|
-
(CQL::QUERY_VALUES + %w(all step_lines examples)).each do |method_name|
|
10
|
-
define_method(method_name) { |*args|
|
11
|
-
return method_name if args.size == 0
|
12
|
-
{method_name=>args}
|
13
|
-
}
|
14
|
-
end
|
15
|
-
|
16
|
-
alias :everything :all
|
17
|
-
alias :complete :all
|
18
|
-
|
19
|
-
def name *args
|
20
|
-
return 'name' if args.size == 0
|
21
|
-
CQL::NameFilter.new args[0]
|
22
|
-
end
|
23
|
-
|
24
|
-
def line *args
|
25
|
-
return 'line' if args.size == 0
|
26
|
-
CQL::LineFilter.new args.first
|
27
|
-
end
|
28
|
-
|
29
|
-
#from clause
|
30
|
-
def from where
|
31
|
-
@from = where
|
32
|
-
@data
|
33
|
-
end
|
34
|
-
|
35
|
-
%w(features scenario_outlines scenarios).each do |method_name|
|
36
|
-
define_method(method_name) { |*args|
|
37
|
-
return method_name if args.size == 0
|
38
|
-
{method_name=>args}
|
39
|
-
}
|
40
|
-
end
|
41
|
-
|
42
|
-
#with clause
|
43
|
-
def with filter
|
44
|
-
@data = filter.execute(@data)
|
45
|
-
end
|
46
|
-
|
47
|
-
class Comparison
|
48
|
-
attr_accessor :op, :amount
|
49
|
-
|
50
|
-
def initialize op, amount
|
51
|
-
@op = op
|
52
|
-
@amount = amount
|
53
|
-
end
|
54
|
-
|
55
|
-
def operator
|
56
|
-
{"lt"=>'<', 'lte'=>'<=', 'gt'=>'>', 'gte'=>'>='}[@op]
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
|
61
|
-
def tc comparison
|
62
|
-
if @from == 'features'
|
63
|
-
FeatureTagCountFilter.new('tc', comparison)
|
64
|
-
else
|
65
|
-
SsoTagCountFilter.new 'tc', comparison
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def lc comparison
|
70
|
-
CQL::SsoLineCountFilter.new('lc', comparison)
|
71
|
-
end
|
72
|
-
|
73
|
-
def ssoc comparison
|
74
|
-
Filter.new('ssoc', comparison)
|
75
|
-
end
|
76
|
-
|
77
|
-
def sc comparison
|
78
|
-
Filter.new('sc', comparison)
|
79
|
-
end
|
80
|
-
|
81
|
-
def soc comparison
|
82
|
-
Filter.new('soc', comparison)
|
83
|
-
end
|
84
|
-
|
85
|
-
def gt amount
|
86
|
-
Comparison.new 'gt', amount
|
87
|
-
end
|
88
|
-
|
89
|
-
def gte amount
|
90
|
-
Comparison.new 'gte', amount
|
91
|
-
end
|
92
|
-
|
93
|
-
def lt amount
|
94
|
-
Comparison.new 'lt', amount
|
95
|
-
end
|
96
|
-
|
97
|
-
def lte amount
|
98
|
-
Comparison.new 'lte', amount
|
99
|
-
end
|
100
|
-
|
101
|
-
def tags *tags
|
102
|
-
return "tags" if tags.size == 0
|
103
|
-
if @from == 'features'
|
104
|
-
FeatureTagFilter.new tags
|
105
|
-
else
|
106
|
-
CQL::SsoTagFilter.new tags
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
end
|
111
|
-
end
|
data/lib/feature_filters.rb
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
module CQL
|
2
|
-
class NameFilter
|
3
|
-
attr_reader :name
|
4
|
-
|
5
|
-
def initialize name
|
6
|
-
@name = name
|
7
|
-
end
|
8
|
-
|
9
|
-
def execute input
|
10
|
-
if name.class == String
|
11
|
-
input = input.find_all { |feature| feature.name == name }
|
12
|
-
elsif name.class == Regexp
|
13
|
-
input = input.find_all { |feature| feature.name =~ name }
|
14
|
-
end
|
15
|
-
|
16
|
-
input
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
class Filter
|
21
|
-
attr_reader :type, :comparison
|
22
|
-
|
23
|
-
def initialize type, comparison
|
24
|
-
@type = type
|
25
|
-
@comparison = comparison
|
26
|
-
end
|
27
|
-
|
28
|
-
def full_type
|
29
|
-
{"sc"=>["Scenario"], "soc"=>["Scenario Outline"], "ssoc"=>["Scenario", "Scenario Outline"]}[@type]
|
30
|
-
end
|
31
|
-
|
32
|
-
def execute input
|
33
|
-
input.find_all do |feature|
|
34
|
-
size = feature.tests.find_all { |test|
|
35
|
-
|
36
|
-
element_class = test.class.to_s[/::.*$/].gsub(':', '')
|
37
|
-
|
38
|
-
case element_class
|
39
|
-
when 'Outline'
|
40
|
-
element_class = 'Scenario Outline'
|
41
|
-
when 'Scenario'
|
42
|
-
element_class = 'Scenario'
|
43
|
-
else
|
44
|
-
raise "Unknown class: #{element_class}"
|
45
|
-
end
|
46
|
-
|
47
|
-
full_type.include?(element_class)
|
48
|
-
}.size
|
49
|
-
|
50
|
-
size.send(comparison.operator, comparison.amount)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
55
|
-
|
56
|
-
class FeatureTagCountFilter < Filter
|
57
|
-
def execute input
|
58
|
-
input.find_all do |feature|
|
59
|
-
feature.tags && feature.tags.size.send(comparison.operator, comparison.amount)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
class TagFilter
|
65
|
-
attr_reader :tags
|
66
|
-
|
67
|
-
def initialize tags
|
68
|
-
@tags = tags
|
69
|
-
end
|
70
|
-
|
71
|
-
def has_tags given, search
|
72
|
-
return false if given == nil
|
73
|
-
search.count do |tag_for_search|
|
74
|
-
given.map { |t| t["name"] }.include?(tag_for_search)
|
75
|
-
end ==search.size
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
class FeatureTagFilter < TagFilter
|
80
|
-
def initialize tags
|
81
|
-
super tags
|
82
|
-
end
|
83
|
-
|
84
|
-
def execute input
|
85
|
-
input.find_all { |feature| has_tags feature.raw_element['tags'], tags }
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
end
|
data/lib/map_reduce.rb
DELETED
@@ -1,104 +0,0 @@
|
|
1
|
-
require_relative "dsl"
|
2
|
-
require_relative "feature_filters"
|
3
|
-
require_relative "sso_filters"
|
4
|
-
|
5
|
-
require 'set'
|
6
|
-
|
7
|
-
module CQL
|
8
|
-
QUERY_VALUES = %w(name uri line description type steps id tags examples)
|
9
|
-
|
10
|
-
class MapReduce
|
11
|
-
|
12
|
-
def self.name(data)
|
13
|
-
data = data.dup
|
14
|
-
data.map { |element| element.name }
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.uri(data)
|
18
|
-
data = data.dup
|
19
|
-
data.map { |element| element.parent_element.path }
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.description(data)
|
23
|
-
data = data.dup
|
24
|
-
data.map { |element| element.description.join("\n") }
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.tags(data)
|
28
|
-
data = data.dup
|
29
|
-
data.map { |element| element.raw_element['tags'] }
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.line(data)
|
33
|
-
data = data.dup
|
34
|
-
data.map { |element| element.source_line }
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.examples(data)
|
38
|
-
data = data.dup
|
39
|
-
data.map { |element| element.examples.collect { |example| example.raw_element } }
|
40
|
-
end
|
41
|
-
|
42
|
-
def self.steps(data)
|
43
|
-
data = data.dup
|
44
|
-
data.map { |element| element.steps.collect { |step| step.raw_element } }
|
45
|
-
end
|
46
|
-
|
47
|
-
def self.type(data)
|
48
|
-
data = data.dup
|
49
|
-
data.map do |element|
|
50
|
-
element_class = element.class.to_s[/::.*$/].gsub(':', '')
|
51
|
-
|
52
|
-
case element_class
|
53
|
-
when 'Outline'
|
54
|
-
type = 'scenario_outline'
|
55
|
-
when 'Scenario'
|
56
|
-
type = 'scenario'
|
57
|
-
else
|
58
|
-
raise "Unknown class: #{element_class}"
|
59
|
-
end
|
60
|
-
|
61
|
-
type
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def self.id(data)
|
66
|
-
data = data.dup
|
67
|
-
data.map { |element| element.raw_element['id'] }
|
68
|
-
end
|
69
|
-
|
70
|
-
%w(all everything complete).each do |method_name|
|
71
|
-
define_singleton_method(method_name) { |input| input }
|
72
|
-
end
|
73
|
-
|
74
|
-
def self.step_lines input
|
75
|
-
input = [input] if input.class != Array
|
76
|
-
steps(input).map do |scen|
|
77
|
-
scen.map { |line| line['keyword'] + line['name'] }
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def self.feature_children input, args
|
82
|
-
results = []
|
83
|
-
|
84
|
-
input.each do |feature|
|
85
|
-
feature.contains.each do |element|
|
86
|
-
|
87
|
-
case args['what']
|
88
|
-
when 'scenario'
|
89
|
-
results.push element if element.class.to_s[/::.*$/].gsub(':', '') == 'Scenario'
|
90
|
-
when 'scenario_outline'
|
91
|
-
results.push element if element.class.to_s[/::.*$/].gsub(':', '') == 'Outline'
|
92
|
-
else
|
93
|
-
raise "Unknown type: #{args['what']}"
|
94
|
-
end
|
95
|
-
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
results
|
100
|
-
end
|
101
|
-
|
102
|
-
end
|
103
|
-
|
104
|
-
end
|
data/lib/sso_filters.rb
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
module CQL
|
2
|
-
|
3
|
-
class SsoTagCountFilter < Filter
|
4
|
-
def execute input
|
5
|
-
input.each_with_index do |feature, index|
|
6
|
-
filtered_elements= feature.tests.find_all do |sso|
|
7
|
-
sso.tags.size.send(comparison.operator, comparison.amount)
|
8
|
-
end
|
9
|
-
|
10
|
-
input[index].tests = filtered_elements
|
11
|
-
end
|
12
|
-
|
13
|
-
input
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class SsoTagFilter < TagFilter
|
18
|
-
def execute input
|
19
|
-
input.each_with_index do |feature, index|
|
20
|
-
features_with_contents_filtered = feature.tests.find_all do |sso|
|
21
|
-
has_tags(sso.raw_element['tags'], tags)
|
22
|
-
end
|
23
|
-
|
24
|
-
input[index].tests = features_with_contents_filtered
|
25
|
-
end
|
26
|
-
|
27
|
-
input
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
class SsoLineCountFilter < Filter
|
32
|
-
def execute input
|
33
|
-
input.each_with_index do |feature, index|
|
34
|
-
filtered_elements = feature.tests.find_all do |sso|
|
35
|
-
sso.steps.size.send(comparison.operator, comparison.amount)
|
36
|
-
end
|
37
|
-
|
38
|
-
input[index].tests = filtered_elements
|
39
|
-
end
|
40
|
-
|
41
|
-
input
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
class LineFilter
|
46
|
-
attr_reader :line
|
47
|
-
|
48
|
-
def initialize line
|
49
|
-
@line = line
|
50
|
-
end
|
51
|
-
|
52
|
-
def execute input
|
53
|
-
input.each_with_index do |feature, index|
|
54
|
-
filtered_elements = feature.tests.find_all do |sso|
|
55
|
-
raw_step_lines = sso.steps.map { |sl| sl.base }
|
56
|
-
result = nil
|
57
|
-
|
58
|
-
if line.class == String
|
59
|
-
result = raw_step_lines.include? line
|
60
|
-
elsif line.class == Regexp
|
61
|
-
result = filter_by_regexp(raw_step_lines)
|
62
|
-
end
|
63
|
-
|
64
|
-
result
|
65
|
-
end
|
66
|
-
|
67
|
-
input[index].tests = filtered_elements
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def filter_by_regexp(raw_step_lines)
|
72
|
-
result = raw_step_lines.find { |l| l =~line }
|
73
|
-
if result.class == String
|
74
|
-
result = result.size > 0
|
75
|
-
else
|
76
|
-
result = false
|
77
|
-
end
|
78
|
-
result
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
end
|