cql 0.0.1
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.
- data/Gemfile +3 -0
- data/README.md +4 -0
- data/cql.gemspec +36 -0
- data/fixtures/.gitkeep +0 -0
- data/fixtures/features/scen_outlines/test_with_scenarios.feature +15 -0
- data/fixtures/features/simple/simple.feature +8 -0
- data/fixtures/features/simple/test.feature +9 -0
- data/fixtures/features/simple/test2.feature +5 -0
- data/fixtures/features/simple/test_full.feature +22 -0
- data/fixtures/features/simple2/test_full.feature +22 -0
- data/fixtures/features/table/simple.feature +8 -0
- data/fixtures/features/tagged_features/simple.feature +8 -0
- data/fixtures/features/tagged_features/test.feature +10 -0
- data/fixtures/features/tagged_features/test2.feature +6 -0
- data/fixtures/features/tagged_features/test_full.feature +22 -0
- data/fixtures/features/tags/simple.feature +24 -0
- data/fixtures/features/tags2/simple.feature +24 -0
- data/fixtures/features/tags2/simple2.feature +24 -0
- data/lib/dsl.rb +51 -0
- data/lib/gherkin_map_reduce.rb +68 -0
- data/lib/gherkin_repo.rb +38 -0
- data/projectFilesBackup/.idea/workspace.xml +570 -0
- data/spec/filter_dsl_spec.rb +40 -0
- data/spec/map_reduce_spec.rb +123 -0
- data/spec/select_dsl_spec.rb +53 -0
- data/spec/unit_spec.rb +22 -0
- metadata +146 -0
data/Gemfile
ADDED
data/README.md
ADDED
data/cql.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
3
|
+
require "cucumber/platform"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'cql'
|
7
|
+
s.version = "0.0.1"
|
8
|
+
s.authors = ["Jarrod Folino"]
|
9
|
+
s.description = 'Cucumber Query Language'
|
10
|
+
s.summary = "cucumber-#{s.version}"
|
11
|
+
s.email = 'jdfolino@gmail.com'
|
12
|
+
|
13
|
+
s.platform = Gem::Platform::RUBY
|
14
|
+
s.post_install_message = %{
|
15
|
+
(::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::)
|
16
|
+
|
17
|
+
Thank you for installing gql (Gherkin Query Language)
|
18
|
+
|
19
|
+
(::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::)
|
20
|
+
|
21
|
+
}
|
22
|
+
|
23
|
+
s.add_runtime_dependency 'gherkin', '~> 2.8.0'
|
24
|
+
s.add_runtime_dependency 'json', '>= 1.4.6'
|
25
|
+
|
26
|
+
s.add_development_dependency 'rake', '>= 0.9.2'
|
27
|
+
s.add_development_dependency 'rspec', '~> 2.7.0'
|
28
|
+
|
29
|
+
|
30
|
+
s.rubygems_version = ">= 1.6.1"
|
31
|
+
s.files = `git ls-files`.split("\n").reject {|path| path =~ /\.gitignore$/ }
|
32
|
+
s.test_files = `git ls-files -- {spec}/*`.split("\n")
|
33
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
34
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
35
|
+
s.require_path = "lib"
|
36
|
+
end
|
data/fixtures/.gitkeep
ADDED
File without changes
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Feature: Test Feature
|
2
|
+
|
3
|
+
Scenario Outline: An Outline
|
4
|
+
Given something happend
|
5
|
+
Then I expect something else
|
6
|
+
Examples:
|
7
|
+
| var_a | var_b |
|
8
|
+
| 1 | a |
|
9
|
+
| 2 | b |
|
10
|
+
| 3 | c |
|
11
|
+
| 4 | d |
|
12
|
+
|
13
|
+
Scenario: A Scenario
|
14
|
+
Given something happend
|
15
|
+
Then I expect something else
|
@@ -0,0 +1,22 @@
|
|
1
|
+
@top-tag
|
2
|
+
Feature: Test3 Feature
|
3
|
+
|
4
|
+
@one
|
5
|
+
Scenario: Testing the slurping
|
6
|
+
Given something happend
|
7
|
+
Then I expect something else
|
8
|
+
|
9
|
+
@two
|
10
|
+
Scenario: Testing again
|
11
|
+
Given something happend
|
12
|
+
Then I expect something else
|
13
|
+
|
14
|
+
@one
|
15
|
+
Scenario: Testing yet again
|
16
|
+
Given something happend
|
17
|
+
Then I expect something else
|
18
|
+
|
19
|
+
@one @two
|
20
|
+
Scenario: Testing yet again part 2
|
21
|
+
Given something happend
|
22
|
+
Then I expect something else
|
@@ -0,0 +1,22 @@
|
|
1
|
+
@top-tag
|
2
|
+
Feature: Test3 Feature
|
3
|
+
|
4
|
+
@one
|
5
|
+
Scenario: Testing the slurping
|
6
|
+
Given something happend
|
7
|
+
Then I expect something else
|
8
|
+
|
9
|
+
@two
|
10
|
+
Scenario: Testing again
|
11
|
+
Given something happend
|
12
|
+
Then I expect something else
|
13
|
+
|
14
|
+
@one
|
15
|
+
Scenario: Testing yet again
|
16
|
+
Given something happend
|
17
|
+
Then I expect something else
|
18
|
+
|
19
|
+
@one @two
|
20
|
+
Scenario: Testing yet again part 2
|
21
|
+
Given something happend
|
22
|
+
Then I expect something else
|
@@ -0,0 +1,22 @@
|
|
1
|
+
@one @two
|
2
|
+
Feature: Test3 Feature
|
3
|
+
|
4
|
+
@one
|
5
|
+
Scenario: Testing the slurping
|
6
|
+
Given something happend
|
7
|
+
Then I expect something else
|
8
|
+
|
9
|
+
@two
|
10
|
+
Scenario: Testing again
|
11
|
+
Given something happend
|
12
|
+
Then I expect something else
|
13
|
+
|
14
|
+
@one
|
15
|
+
Scenario: Testing yet again
|
16
|
+
Given something happend
|
17
|
+
Then I expect something else
|
18
|
+
|
19
|
+
@one @two
|
20
|
+
Scenario: Testing yet again part 2
|
21
|
+
Given something happend
|
22
|
+
Then I expect something else
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Feature: Simple
|
2
|
+
|
3
|
+
@two
|
4
|
+
Scenario: Has a table
|
5
|
+
Given Something
|
6
|
+
| a | a |
|
7
|
+
| s | a |
|
8
|
+
| s | s |
|
9
|
+
Then something else
|
10
|
+
|
11
|
+
@one
|
12
|
+
Scenario: Next
|
13
|
+
Given anything
|
14
|
+
|
15
|
+
@two
|
16
|
+
Scenario: Blah
|
17
|
+
Given lalala
|
18
|
+
|
19
|
+
@one
|
20
|
+
Scenario: Another
|
21
|
+
Given a car
|
22
|
+
|
23
|
+
Scenario: Yet Another
|
24
|
+
Given a car
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Feature: Simple
|
2
|
+
|
3
|
+
@two
|
4
|
+
Scenario: Has a table
|
5
|
+
Given Something
|
6
|
+
| a | a |
|
7
|
+
| s | a |
|
8
|
+
| s | s |
|
9
|
+
Then something else
|
10
|
+
|
11
|
+
@one
|
12
|
+
Scenario: Next
|
13
|
+
Given anything
|
14
|
+
|
15
|
+
Scenario: Another
|
16
|
+
Given a car
|
17
|
+
|
18
|
+
@two
|
19
|
+
Scenario: Blah
|
20
|
+
Given lalala
|
21
|
+
|
22
|
+
@one
|
23
|
+
Scenario: Another
|
24
|
+
Given a car
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Feature: Simple 2
|
2
|
+
|
3
|
+
@two @four
|
4
|
+
Scenario: Has a table hmmm
|
5
|
+
Given Something
|
6
|
+
| a | a |
|
7
|
+
| s | a |
|
8
|
+
| s | s |
|
9
|
+
Then something else
|
10
|
+
|
11
|
+
@one @five
|
12
|
+
Scenario: Next
|
13
|
+
Given anything
|
14
|
+
|
15
|
+
Scenario: Another
|
16
|
+
Given a car
|
17
|
+
|
18
|
+
@two
|
19
|
+
Scenario: Blah blah
|
20
|
+
Given lalala
|
21
|
+
|
22
|
+
@one
|
23
|
+
Scenario: Another
|
24
|
+
Given a car
|
data/lib/dsl.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
module CQL
|
2
|
+
module Dsl
|
3
|
+
|
4
|
+
%w(names features scenario_outlines uri scenarios).each do |method_name|
|
5
|
+
define_method(method_name) { method_name }
|
6
|
+
end
|
7
|
+
|
8
|
+
def select what
|
9
|
+
@what = what
|
10
|
+
end
|
11
|
+
|
12
|
+
def from where
|
13
|
+
@from = where
|
14
|
+
@data
|
15
|
+
end
|
16
|
+
|
17
|
+
def tags *tags
|
18
|
+
{'tags'=>tags}
|
19
|
+
end
|
20
|
+
|
21
|
+
def with filter
|
22
|
+
if filter.has_key? 'tags'
|
23
|
+
@data = CQL::MapReduce.find_feature(@data, 'tags'=>filter['tags'])
|
24
|
+
end
|
25
|
+
@data
|
26
|
+
end
|
27
|
+
|
28
|
+
class Query
|
29
|
+
include Dsl
|
30
|
+
attr_reader :data, :what
|
31
|
+
|
32
|
+
def initialize features, &block
|
33
|
+
@data = features
|
34
|
+
@data = self.instance_eval(&block)
|
35
|
+
key = @what + "-" + @from
|
36
|
+
if key=="uri-features"
|
37
|
+
@data = CQL::MapReduce.uri(@data)
|
38
|
+
elsif key== "names-features"
|
39
|
+
@data = CQL::MapReduce.overview(@data)
|
40
|
+
elsif key== "names-scenario_outlines"
|
41
|
+
@data= CQL::MapReduce.find_child(@data, 'what'=>'scenario_outline')
|
42
|
+
elsif key== "names-scenarios"
|
43
|
+
@data = CQL::MapReduce.find_child(@data, 'what'=>'scenario')
|
44
|
+
end
|
45
|
+
@data
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module CQL
|
2
|
+
class MapReduce
|
3
|
+
|
4
|
+
def self.overview input
|
5
|
+
input.class == Array ? input.map { |a| a['name'] } : input['name']
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.uri input
|
9
|
+
input.map { |a| a['uri'] }
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.find_feature input, args
|
13
|
+
input = input.find_all { |feature| feature['name'] == args['feature'] } if args.has_key? 'feature'
|
14
|
+
input = input.find_all { |feature| has_tags feature['tags'], args['tags'] } if args.has_key? 'tags'
|
15
|
+
if input.size == 1
|
16
|
+
input = input.first
|
17
|
+
end
|
18
|
+
input
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.scenario_by_feature_and_tag input, feature_to_find, condition, *tags_to_find
|
22
|
+
scenarios = []
|
23
|
+
input.each do |feature|
|
24
|
+
if feature['name'] == feature_to_find
|
25
|
+
feature['elements'].each do |element|
|
26
|
+
if element['type'] == "scenario" and has_tags(element['tags'], tags_to_find) == condition
|
27
|
+
scenarios.push element['name']
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
scenarios
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.scenario input, args
|
36
|
+
input = find_feature(input, 'feature'=>args['feature'])
|
37
|
+
input['elements'].find{|element|element['name'] == args['child_name'] }
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.find_child input, args
|
41
|
+
results = []
|
42
|
+
input = [find_feature(input, 'feature'=>args['feature'])] if args.has_key?('feature')
|
43
|
+
input.each do |feature|
|
44
|
+
feature['elements'].each do |element|
|
45
|
+
results.push element['name'] if element['type'] == args['what']
|
46
|
+
end
|
47
|
+
end
|
48
|
+
results
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.tags input
|
52
|
+
tags = Set.new
|
53
|
+
input.each do |feature|
|
54
|
+
feature['elements'].each do |element|
|
55
|
+
break if element['tags'] == nil
|
56
|
+
element['tags'].each { |tag| tags.add tag['name'] }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
tags.to_a
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.has_tags given, search
|
63
|
+
return false if given == nil
|
64
|
+
search.count { |tag_for_search| given.map { |t| t["name"] }.include?(tag_for_search) }==search.size
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
data/lib/gherkin_repo.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'gherkin/parser/parser'
|
2
|
+
require 'gherkin/formatter/json_formatter'
|
3
|
+
require 'stringio'
|
4
|
+
require 'json'
|
5
|
+
require 'set'
|
6
|
+
|
7
|
+
require File.dirname(__FILE__) + "/gherkin_map_reduce"
|
8
|
+
require File.dirname(__FILE__) + "/dsl"
|
9
|
+
|
10
|
+
module CQL
|
11
|
+
class GherkinRepository
|
12
|
+
include Dsl
|
13
|
+
attr_reader :parsed_feature_files
|
14
|
+
|
15
|
+
def initialize features_home_dir
|
16
|
+
@parsed_feature_files = load_features(list_features(features_home_dir))
|
17
|
+
end
|
18
|
+
|
19
|
+
def query &block
|
20
|
+
Query.new(parsed_feature_files.clone, &block).data
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
def list_features base_dir
|
25
|
+
Dir.glob(base_dir + "/**/*.feature")
|
26
|
+
end
|
27
|
+
|
28
|
+
def load_features sources
|
29
|
+
io = StringIO.new
|
30
|
+
formatter = Gherkin::Formatter::JSONFormatter.new(io)
|
31
|
+
parser = Gherkin::Parser::Parser.new(formatter)
|
32
|
+
sources.each { |s| parser.parse(IO.read(s), s, 0) }
|
33
|
+
formatter.done
|
34
|
+
JSON.parse(io.string)
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|