cql 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. data/cql.gemspec +2 -2
  2. data/fixtures/features/scen_outlines/{test_with_scenarios.feature → basic/test_with_scenarios.feature} +0 -0
  3. data/fixtures/features/scen_outlines/multiple_examples/test_with_scenarios.feature +19 -0
  4. data/fixtures/features/{simple → scenario/simple}/simple.feature +0 -0
  5. data/fixtures/features/{simple → scenario/simple}/test.feature +1 -1
  6. data/fixtures/features/scenario/simple/test2.feature +5 -0
  7. data/fixtures/features/{simple2 → scenario/simple}/test_full.feature +1 -1
  8. data/fixtures/features/{simple → scenario/simple2}/test_full.feature +1 -0
  9. data/fixtures/features/{table → scenario/table}/simple.feature +0 -0
  10. data/fixtures/features/{tagged_features → scenario/tagged_features}/simple.feature +0 -0
  11. data/fixtures/features/{tagged_features → scenario/tagged_features}/test.feature +0 -0
  12. data/fixtures/features/{tagged_features → scenario/tagged_features}/test2.feature +0 -0
  13. data/fixtures/features/{tagged_features → scenario/tagged_features}/test_full.feature +0 -0
  14. data/fixtures/features/{tags → scenario/tags}/simple.feature +0 -0
  15. data/fixtures/features/{tags2 → scenario/tags2}/simple.feature +0 -0
  16. data/fixtures/features/{tags2 → scenario/tags2}/simple2.feature +0 -0
  17. data/lib/dsl.rb +22 -17
  18. data/lib/map_reduce.rb +64 -0
  19. data/lib/{gherkin_repo.rb → repo.rb} +1 -5
  20. data/spec/filter_dsl_spec.rb +57 -10
  21. data/spec/map_reduce_spec.rb +34 -69
  22. data/spec/select_feature_dsl_spec.rb +50 -0
  23. data/spec/select_scen_outline_dsl_spec.rb +126 -0
  24. data/spec/select_scenario_dsl_spec.rb +73 -0
  25. data/spec/unit_spec.rb +1 -1
  26. metadata +25 -22
  27. data/fixtures/features/simple/test2.feature +0 -5
  28. data/lib/gherkin_map_reduce.rb +0 -68
  29. data/spec/select_dsl_spec.rb +0 -53
data/cql.gemspec CHANGED
@@ -4,7 +4,7 @@ require "cucumber/platform"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = 'cql'
7
- s.version = "0.0.1"
7
+ s.version = "0.0.2"
8
8
  s.authors = ["Jarrod Folino"]
9
9
  s.description = 'Cucumber Query Language'
10
10
  s.summary = "cucumber-#{s.version}"
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
14
14
  s.post_install_message = %{
15
15
  (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::)
16
16
 
17
- Thank you for installing gql (Gherkin Query Language)
17
+ Thank you for installing cql (Cucumber Query Language)
18
18
 
19
19
  (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::)
20
20
 
@@ -0,0 +1,19 @@
1
+ Feature: Test Feature
2
+
3
+ Scenario Outline: An Outline
4
+ Given something happend
5
+ Then I expect something else
6
+ Examples: One
7
+ | var_a | var_b |
8
+ | 1 | a |
9
+ | 2 | b |
10
+
11
+ Examples: Two
12
+ | var_a | var_b |
13
+ | 1 | a |
14
+ | 2 | b |
15
+
16
+
17
+ Scenario: A Scenario
18
+ Given something happend
19
+ Then I expect something else
@@ -1,6 +1,6 @@
1
1
  Feature: Test Feature
2
2
 
3
- Scenario: Testing the slurping
3
+ Scenario: Testing the slurping 1
4
4
  Given something happend
5
5
  Then I expect something else
6
6
 
@@ -0,0 +1,5 @@
1
+ Feature: Test2 Feature
2
+
3
+ Scenario: Testing the slurping 2
4
+ Given something happend
5
+ Then I expect something else
@@ -2,7 +2,7 @@
2
2
  Feature: Test3 Feature
3
3
 
4
4
  @one
5
- Scenario: Testing the slurping
5
+ Scenario: Testing the slurping 3
6
6
  Given something happend
7
7
  Then I expect something else
8
8
 
@@ -1,5 +1,6 @@
1
1
  @top-tag
2
2
  Feature: Test3 Feature
3
+ The cat in the hat
3
4
 
4
5
  @one
5
6
  Scenario: Testing the slurping
data/lib/dsl.rb CHANGED
@@ -1,11 +1,18 @@
1
+ require File.dirname(__FILE__) + "/map_reduce"
1
2
  module CQL
3
+ DSL_KEYWORDS = %w(features scenario_outlines scenarios all step_lines examples)
2
4
  module Dsl
3
-
4
- %w(names features scenario_outlines uri scenarios).each do |method_name|
5
- define_method(method_name) { method_name }
5
+ (CQL::QUERY_VALUES + CQL::DSL_KEYWORDS).each do |method_name|
6
+ define_method(method_name) { |*args|
7
+ return method_name if args.size == 0
8
+ {method_name=>args}
9
+ }
6
10
  end
7
11
 
8
- def select what
12
+ alias :everything :all
13
+ alias :complete :all
14
+
15
+ def select *what
9
16
  @what = what
10
17
  end
11
18
 
@@ -15,12 +22,15 @@ module CQL
15
22
  end
16
23
 
17
24
  def tags *tags
25
+ return "tags" if tags.size == 0
18
26
  {'tags'=>tags}
19
27
  end
20
28
 
21
29
  def with filter
22
30
  if filter.has_key? 'tags'
23
- @data = CQL::MapReduce.find_feature(@data, 'tags'=>filter['tags'])
31
+ @data = CQL::MapReduce.filter_features(@data, 'tags'=>filter['tags'])
32
+ elsif filter.has_key? 'name'
33
+ @data = CQL::MapReduce.filter_features(@data, 'feature'=>filter['name'])
24
34
  end
25
35
  @data
26
36
  end
@@ -32,20 +42,15 @@ module CQL
32
42
  def initialize features, &block
33
43
  @data = features
34
44
  @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')
45
+
46
+ @data= CQL::MapReduce.filter_sso(@data, 'what'=>@from[0, @from.size-1]) if @from != "features"
47
+ result = Array.new(@data.size)
48
+ result = result.map { |e| {} }
49
+ @what.each do |w|
50
+ CQL::MapReduce.send(w, @data).each_with_index { |e, i| result[i][w]=e }
44
51
  end
45
- @data
52
+ @data = result.size == 1 ? result.first : result
46
53
  end
47
54
  end
48
-
49
55
  end
50
-
51
56
  end
data/lib/map_reduce.rb ADDED
@@ -0,0 +1,64 @@
1
+ require File.dirname(__FILE__) + "/dsl"
2
+ module CQL
3
+
4
+ QUERY_VALUES = %w(name uri line description type steps id tags examples)
5
+
6
+ class MapReduce
7
+
8
+ CQL::QUERY_VALUES.each do |property|
9
+ define_singleton_method(property) do |input|
10
+ input = [input] if input.class != Array
11
+ input.map { |a| a[property] }
12
+ end
13
+ end
14
+
15
+ %w(all everything complete).each do |method_name|
16
+ define_singleton_method(method_name){|input|input}
17
+ end
18
+
19
+ def self.step_lines input
20
+ input = [input] if input.class != Array
21
+ steps(input).map do |scen|
22
+ scen.map { |line| line['keyword'] + line['name'] }
23
+ end
24
+ end
25
+
26
+ def self.filter_features input, args
27
+ if args.has_key?('feature') && args['feature'][0].class == String
28
+ input = input.find_all { |feature| feature['name'] == args['feature'][0] }
29
+ elsif args.has_key?('feature') && args['feature'][0].class == Regexp
30
+ input = input.find_all { |feature| feature['name'] =~ args['feature'][0] }
31
+ end
32
+ input = input.find_all { |feature| has_tags feature['tags'], args['tags'] } if args.has_key? 'tags'
33
+ input
34
+ end
35
+
36
+ def self.filter_sso input, args
37
+ results = []
38
+ input = filter_features(input, 'feature'=>args['feature']) if args.has_key?('feature')
39
+ input.each do |feature|
40
+ feature['elements'].each do |element|
41
+ results.push element if element['type'] == args['what']
42
+ end
43
+ end
44
+ results
45
+ end
46
+
47
+ def self.tag_set input
48
+ tags = Set.new
49
+ input.each do |feature|
50
+ feature['elements'].each do |element|
51
+ break if element['tags'] == nil
52
+ element['tags'].each { |tag| tags.add tag['name'] }
53
+ end
54
+ end
55
+ tags.to_a
56
+ end
57
+
58
+ def self.has_tags given, search
59
+ return false if given == nil
60
+ search.count { |tag_for_search| given.map { |t| t["name"] }.include?(tag_for_search) }==search.size
61
+ end
62
+
63
+ end
64
+ end
@@ -1,14 +1,10 @@
1
1
  require 'gherkin/parser/parser'
2
2
  require 'gherkin/formatter/json_formatter'
3
3
  require 'stringio'
4
- require 'json'
5
- require 'set'
6
-
7
- require File.dirname(__FILE__) + "/gherkin_map_reduce"
8
4
  require File.dirname(__FILE__) + "/dsl"
9
5
 
10
6
  module CQL
11
- class GherkinRepository
7
+ class Repository
12
8
  include Dsl
13
9
  attr_reader :parsed_feature_files
14
10
 
@@ -1,39 +1,86 @@
1
1
  require 'rspec'
2
- require File.dirname(__FILE__) + "/../lib/" + "gherkin_repo"
2
+ require File.dirname(__FILE__) + "/../lib/repo"
3
3
 
4
4
  describe "cql" do
5
5
 
6
- describe 'filter' do
6
+ describe 'filter features by name' do
7
+ it 'should filter by name' do
8
+ gs = CQL::Repository.new File.dirname(__FILE__) + "/../fixtures/features/scenario/tagged_features"
9
+
10
+ result = gs.query do
11
+ select name
12
+ from features
13
+ with name 'Test2 Feature'
14
+ end
15
+
16
+ result.should == {"name"=> "Test2 Feature"}
17
+ end
18
+
19
+ it 'should filter by name regexp' do
20
+ gs = CQL::Repository.new File.dirname(__FILE__) + "/../fixtures/features/scenario/tagged_features"
21
+
22
+ result = gs.query do
23
+ select name
24
+ from features
25
+ with name /Test2 Feature/
26
+ end
27
+
28
+ result.should == {"name"=> "Test2 Feature"}
29
+
30
+ result = gs.query do
31
+ select name
32
+ from features
33
+ with name /Feature/
34
+ end
35
+
36
+ result.size.should == 3
37
+ end
38
+ end
39
+
40
+ describe 'filter features by tag' do
7
41
  it 'should filter by a single tag' do
8
- gs = CQL::GherkinRepository.new File.dirname(__FILE__) + "/../fixtures/features/tagged_features"
42
+ gs = CQL::Repository.new File.dirname(__FILE__) + "/../fixtures/features/scenario/tagged_features"
9
43
 
10
44
  result = gs.query do
11
- select names
45
+ select name
12
46
  from features
13
47
  with tags '@one'
14
48
  end
15
49
 
16
- result.should == ["Test Feature", "Test3 Feature"]
50
+ result.should == [{"name"=> "Test Feature"}, {"name"=>"Test3 Feature"}]
51
+
52
+ result = gs.query do
53
+ select name
54
+ from features
55
+ with tags '@two'
56
+ end
57
+
58
+ result.should == [{"name"=> "Test2 Feature"}, {"name"=>"Test3 Feature"}]
59
+ end
60
+
61
+ it 'should filter by multiple filters' do
62
+ gs = CQL::Repository.new File.dirname(__FILE__) + "/../fixtures/features/scenario/tagged_features"
17
63
 
18
64
  result = gs.query do
19
- select names
65
+ select name
20
66
  from features
21
67
  with tags '@two'
68
+ with tags '@one'
22
69
  end
23
70
 
24
- result.should == ["Test2 Feature", "Test3 Feature"]
71
+ result.should == {"name"=>"Test3 Feature"}
25
72
  end
26
73
 
27
74
  it 'should filter by a multiple tags' do
28
- gs = CQL::GherkinRepository.new File.dirname(__FILE__) + "/../fixtures/features/tagged_features"
75
+ gs = CQL::Repository.new File.dirname(__FILE__) + "/../fixtures/features/scenario/tagged_features"
29
76
 
30
77
  result = gs.query do
31
- select names
78
+ select name
32
79
  from features
33
80
  with tags '@one', '@two'
34
81
  end
35
82
 
36
- result.should == "Test3 Feature"
83
+ result.should == {"name"=>"Test3 Feature"}
37
84
  end
38
85
  end
39
86
 
@@ -1,11 +1,11 @@
1
1
  require 'rspec'
2
- require File.dirname(__FILE__) + "/../lib/" + "gherkin_repo"
2
+ require File.dirname(__FILE__) + "/../lib/repo"
3
3
 
4
4
  describe "cql" do
5
5
 
6
6
  describe "file parsing" do
7
7
  it 'should find the physical files' do
8
- gs = CQL::GherkinRepository.new File.dirname(__FILE__) + "/../fixtures/features/simple"
8
+ gs = CQL::Repository.new File.dirname(__FILE__) + "/../fixtures/features/scenario/simple"
9
9
  result = CQL::MapReduce.uri(gs.parsed_feature_files)
10
10
  result[0].should =~ /simple\.feature/
11
11
  result[1].should =~ /test\.feature/
@@ -16,8 +16,8 @@ describe "cql" do
16
16
 
17
17
  describe "tags" do
18
18
  it "retrieve tags from a scenario" do
19
- gs = CQL::GherkinRepository.new File.dirname(__FILE__) + "/../fixtures/features/tags2"
20
- CQL::MapReduce.tags(gs.parsed_feature_files).sort.should == ["@five", "@four", "@one", "@two"].sort
19
+ gs = CQL::Repository.new File.dirname(__FILE__) + "/../fixtures/features/scenario/tags2"
20
+ CQL::MapReduce.tag_set(gs.parsed_feature_files).sort.should == ["@five", "@four", "@one", "@two"].sort
21
21
  end
22
22
 
23
23
  it 'should filter features by tag' do
@@ -25,32 +25,39 @@ describe "cql" do
25
25
  {"keyword"=>"Feature", "name"=>"Test Feature", "line"=>2, "description"=>"", "tags"=>[{"name"=>"@one", "line"=>1}], "id"=>"test-feature"},
26
26
  {"keyword"=>"Feature", "name"=>"Test2 Feature", "line"=>1, "description"=>"", "id"=>"test2-feature"},
27
27
  {"keyword"=>"Feature", "name"=>"Test3 Feature", "line"=>2, "description"=>"", "tags"=>[{"name"=>"@one", "line"=>1}], "id"=>"test3-feature"}]
28
- result = CQL::MapReduce.find_feature(input, 'tags'=>['@one'])
28
+ result = CQL::MapReduce.filter_features(input, 'tags'=>['@one'])
29
29
  result.size.should == 2
30
30
  result[0]['name'].should == "Test Feature"
31
31
  result[1]['name'].should == "Test3 Feature"
32
32
  end
33
33
 
34
+ it 'should filter by multiple tags' do
35
+ input = [{"keyword"=>"Feature", "name"=>"Simple", "line"=>1, "description"=>"", "id"=>"simple"},
36
+ {"keyword"=>"Feature", "name"=>"Test Feature", "line"=>2, "description"=>"", "tags"=>[{"name"=>"@one", "line"=>1}], "id"=>"test-feature"},
37
+ {"keyword"=>"Feature", "name"=>"Test2 Feature", "line"=>2, "description"=>"", "tags"=>[{"name"=>"@two", "line"=>1}], "id"=>"test2-feature"},
38
+ {"keyword"=>"Feature", "name"=>"Test3 Feature", "line"=>2, "description"=>"", "tags"=>[{"name"=>"@one", "line"=>1}, {"name"=>"@two", "line"=>1}], "id"=>"test3-feature"}]
39
+ result = CQL::MapReduce.filter_features(input, 'tags'=>['@one', '@two'])
40
+ result.should == [{"keyword"=>"Feature", "name"=>"Test3 Feature",
41
+ "line"=>2, "description"=>"",
42
+ "tags"=>[{"name"=>"@one", "line"=>1},
43
+ {"name"=>"@two", "line"=>1}],
44
+ "id"=>"test3-feature"}]
45
+ end
34
46
  end
35
47
 
36
48
  describe 'features query' do
37
49
  it 'should find all feature names' do
38
- gs = CQL::GherkinRepository.new File.dirname(__FILE__) + "/../fixtures/features/simple"
39
- CQL::MapReduce.overview(gs.parsed_feature_files).should eql ["Simple", "Test Feature", "Test2 Feature", "Test3 Feature"]
40
- end
41
-
42
- it 'should filter by a scenario by feature and then by tag' do
43
- gs = CQL::GherkinRepository.new File.expand_path(File.dirname(__FILE__)) + "/../fixtures/features/tags2"
44
- CQL::MapReduce.scenario_by_feature_and_tag(gs.parsed_feature_files, "Not here", "@three").should == []
50
+ gs = CQL::Repository.new File.dirname(__FILE__) + "/../fixtures/features/scenario/simple"
51
+ CQL::MapReduce.name(gs.parsed_feature_files).should eql ["Simple", "Test Feature", "Test2 Feature", "Test3 Feature"]
45
52
  end
46
53
 
47
54
  it 'should retrieve a full feature' do
48
- gs = CQL::GherkinRepository.new File.expand_path(File.dirname(__FILE__)) + "/../fixtures/features/simple"
49
- result = CQL::MapReduce.find_feature(gs.parsed_feature_files, {'feature'=>"Test Feature"})
50
- result['name'].should == "Test Feature"
51
- result['elements'][0]['name'].should == "Testing the slurping"
52
- result['elements'].should == [{"keyword"=>"Scenario", "name"=>"Testing the slurping", "line"=>3,
53
- "description"=>"", "id"=>"test-feature;testing-the-slurping", "type"=>"scenario",
55
+ gs = CQL::Repository.new File.expand_path(File.dirname(__FILE__)) + "/../fixtures/features/scenario/simple"
56
+ result = CQL::MapReduce.filter_features(gs.parsed_feature_files, {'feature'=>["Test Feature"]})
57
+ result[0]['name'].should == "Test Feature"
58
+ result[0]['elements'][0]['name'].should == "Testing the slurping 1"
59
+ result[0]['elements'].should == [{"keyword"=>"Scenario", "name"=>"Testing the slurping 1", "line"=>3,
60
+ "description"=>"", "id"=>"test-feature;testing-the-slurping-1", "type"=>"scenario",
54
61
  "steps"=>[{"keyword"=>"Given ", "name"=>"something happend", "line"=>4},
55
62
  {"keyword"=>"Then ", "name"=>"I expect something else", "line"=>5}]},
56
63
  {"keyword"=>"Scenario", "name"=>"Testing the slurping not to be found", "line"=>7,
@@ -61,62 +68,20 @@ describe "cql" do
61
68
 
62
69
  describe 'scenario query' do
63
70
  it 'should get all scenarios as a list' do
64
- gs = CQL::GherkinRepository.new File.expand_path(File.dirname(__FILE__)) + "/../fixtures/features/scen_outlines"
65
- CQL::MapReduce.find_child(gs.parsed_feature_files, {'feature'=>"Test Feature", 'what'=>'scenario'}).should == ["A Scenario"]
66
- end
67
-
68
- it 'should get a full scenario' do
69
- simple_path = File.expand_path(File.dirname(__FILE__)) + "/../fixtures/features/simple"
70
- gs = CQL::GherkinRepository.new simple_path
71
- expected = {"keyword"=>"Scenario", "name"=>"Testing the slurping", "line"=>3,
72
- "description"=>"", "id"=>"test-feature;testing-the-slurping", "type"=>"scenario",
73
- "steps"=>[{"keyword"=>"Given ", "name"=>"something happend", "line"=>4},
74
- {"keyword"=>"Then ", "name"=>"I expect something else", "line"=>5}]}
75
- CQL::MapReduce.scenario(gs.parsed_feature_files, {'what'=>'scenario', 'feature'=>"Test Feature", 'child_name'=>"Testing the slurping"}).should == expected
76
- end
77
-
78
- it 'should find scenarios by a single tag' do
79
- gs = CQL::GherkinRepository.new File.expand_path(File.dirname(__FILE__)) + "/../fixtures/features/tags"
80
- CQL::MapReduce.scenario_by_feature_and_tag(gs.parsed_feature_files, "Simple", true, "@one").should == ['Next', 'Another']
81
- CQL::MapReduce.scenario_by_feature_and_tag(gs.parsed_feature_files, "Simple", true, "@two").should == ['Has a table', 'Blah']
82
-
83
- gs = CQL::GherkinRepository.new File.expand_path(File.dirname(__FILE__)) + "/../fixtures/features/tags2"
84
- CQL::MapReduce.scenario_by_feature_and_tag(gs.parsed_feature_files, "Simple", true, "@one").should == ['Next', 'Another']
85
- CQL::MapReduce.scenario_by_feature_and_tag(gs.parsed_feature_files, "Simple", true, "@two").should == ['Has a table', 'Blah']
86
- CQL::MapReduce.scenario_by_feature_and_tag(gs.parsed_feature_files, "Simple 2", true, "@one").should == ['Next', 'Another']
87
- CQL::MapReduce.scenario_by_feature_and_tag(gs.parsed_feature_files, "Simple 2", true, "@two").should == ['Has a table hmmm', 'Blah blah']
88
-
89
- CQL::MapReduce.scenario_by_feature_and_tag(gs.parsed_feature_files, "Simple", true, "@three").should == []
90
-
91
- end
92
-
93
- it 'should find scenarios that do not have a specified tag' do
94
- gs = CQL::GherkinRepository.new File.expand_path(File.dirname(__FILE__)) + "/../fixtures/features/tags"
95
- CQL::MapReduce.scenario_by_feature_and_tag(gs.parsed_feature_files, "Simple", false, "@one").should == ['Has a table', 'Blah', 'Yet Another']
96
- #GQL::MapReduce.scenario_by_feature_wo_tag(gs.parsed_feature_files, "Simple", "@two").should == ['Has a table', 'Blah']
97
- end
98
-
99
- it 'should find scenarios by multiple tags' do
100
- gs = CQL::GherkinRepository.new File.expand_path(File.dirname(__FILE__)) + "/../fixtures/features/tags2"
101
- CQL::MapReduce.scenario_by_feature_and_tag(gs.parsed_feature_files, "Simple 2", true, "@two", "@four").should == ['Has a table hmmm']
102
- end
103
-
104
- it 'should retrieve the table data' do
105
- gs = CQL::GherkinRepository.new File.expand_path(File.dirname(__FILE__)) + "/../fixtures/features/table"
106
- expected = {"keyword"=>"Scenario", "name"=>"Has a table", "line"=>3, "description"=>"", "id"=>"simple;has-a-table", "type"=>"scenario",
107
- "steps"=>[{"keyword"=>"Given ", "name"=>"Something", "line"=>4,
108
- "rows"=>[{"cells"=>["a", "a"], "line"=>5},
109
- {"cells"=>["s", "a"], "line"=>6}, {"cells"=>["s", "s"], "line"=>7}]},
110
- {"keyword"=>"Then ", "name"=>"something else", "line"=>8}]}
111
- CQL::MapReduce.scenario(gs.parsed_feature_files, {'what'=>'scenario', 'feature'=>"Simple", 'child_name'=>"Has a table"}).should == expected
71
+ gs = CQL::Repository.new File.expand_path(File.dirname(__FILE__)) + "/../fixtures/features/scen_outlines/basic"
72
+ result = CQL::MapReduce.filter_sso(gs.parsed_feature_files, {'feature'=>["Test Feature"], 'what'=>'scenario'})
73
+ result.should == [{"keyword"=>"Scenario", "name"=>"A Scenario", "line"=>13, "description"=>"", "id"=>"test-feature;a-scenario", "type"=>"scenario", "steps"=>[{"keyword"=>"Given ", "name"=>"something happend", "line"=>14}, {"keyword"=>"Then ", "name"=>"I expect something else", "line"=>15}]}]
112
74
  end
113
75
  end
114
76
 
115
77
  describe 'scenario outline query' do
116
78
  it 'should get scenario outlines as a list' do
117
- gs = CQL::GherkinRepository.new File.expand_path(File.dirname(__FILE__)) + "/../fixtures/features/scen_outlines"
118
- CQL::MapReduce.find_child(gs.parsed_feature_files, {'feature'=>"Test Feature", 'what'=> 'scenario'}).should == ["A Scenario"]
119
- CQL::MapReduce.find_child(gs.parsed_feature_files, {'feature'=> "Test Feature", 'what'=> 'scenario_outline'}).should == ["An Outline"]
79
+ gs = CQL::Repository.new File.expand_path(File.dirname(__FILE__)) + "/../fixtures/features/scen_outlines/basic"
80
+ result = CQL::MapReduce.filter_sso(gs.parsed_feature_files, {'feature'=>["Test Feature"], 'what'=> 'scenario'})
81
+ result.should == [{"keyword"=>"Scenario", "name"=>"A Scenario", "line"=>13, "description"=>"", "id"=>"test-feature;a-scenario", "type"=>"scenario", "steps"=>[{"keyword"=>"Given ", "name"=>"something happend", "line"=>14}, {"keyword"=>"Then ", "name"=>"I expect something else", "line"=>15}]}]
82
+
83
+ result = CQL::MapReduce.filter_sso(gs.parsed_feature_files, {'feature'=> ["Test Feature"], 'what'=> 'scenario_outline'})
84
+ result.should == [{"keyword"=>"Scenario Outline", "name"=>"An Outline", "line"=>3, "description"=>"", "id"=>"test-feature;an-outline", "type"=>"scenario_outline", "steps"=>[{"keyword"=>"Given ", "name"=>"something happend", "line"=>4}, {"keyword"=>"Then ", "name"=>"I expect something else", "line"=>5}], "examples"=>[{"keyword"=>"Examples", "name"=>"", "line"=>6, "description"=>"", "id"=>"test-feature;an-outline;", "rows"=>[{"cells"=>["var_a", "var_b"], "line"=>7, "id"=>"test-feature;an-outline;;1"}, {"cells"=>["1", "a"], "line"=>8, "id"=>"test-feature;an-outline;;2"}, {"cells"=>["2", "b"], "line"=>9, "id"=>"test-feature;an-outline;;3"}, {"cells"=>["3", "c"], "line"=>10, "id"=>"test-feature;an-outline;;4"}, {"cells"=>["4", "d"], "line"=>11, "id"=>"test-feature;an-outline;;5"}]}]}]
120
85
  end
121
86
  end
122
87
 
@@ -0,0 +1,50 @@
1
+ require 'rspec'
2
+ require File.dirname(__FILE__) + "/../lib/repo"
3
+
4
+ describe "select" do
5
+ describe "feature" do
6
+ it 'should return multiple feature file names' do
7
+ gs = CQL::Repository.new File.dirname(__FILE__) + "/../fixtures/features/scenario/simple"
8
+ result = gs.query do
9
+ select name
10
+ from features
11
+ end
12
+ result.should == [{"name"=>"Simple"}, {"name"=>"Test Feature"},
13
+ {"name"=>"Test2 Feature"}, {"name"=>"Test3 Feature"}]
14
+ end
15
+
16
+ it 'should find the feature description' do
17
+ gs = CQL::Repository.new File.dirname(__FILE__) + "/../fixtures/features/scenario/simple2"
18
+ result = gs.query do
19
+ select description
20
+ from features
21
+ end
22
+ result.should == {"description"=>"The cat in the hat"}
23
+ end
24
+
25
+ it 'should find the feature file uri' do
26
+ gs = CQL::Repository.new File.dirname(__FILE__) + "/../fixtures/features/scenario/simple"
27
+ result = gs.query do
28
+ select uri
29
+ from features
30
+ end
31
+ result[0]['uri'].should =~ /simple\.feature/
32
+ result[1]['uri'].should =~ /test\.feature/
33
+ result[2]['uri'].should =~ /test2\.feature/
34
+ result[3]['uri'].should =~ /test\_full\.feature/
35
+ end
36
+
37
+ it 'should return multiple feature file names with associated tags' do
38
+ gs = CQL::Repository.new File.dirname(__FILE__) + "/../fixtures/features/scenario/tagged_features"
39
+ result = gs.query do
40
+ select name, tags
41
+ from features
42
+ end
43
+ result.should == [{"name"=>"Simple", "tags"=>nil},
44
+ {"name"=>"Test Feature", "tags"=>[{"name"=>"@one", "line"=>1}]},
45
+ {"name"=>"Test2 Feature", "tags"=>[{"name"=>"@two", "line"=>1}]},
46
+ {"name"=>"Test3 Feature", "tags"=>[{"name"=>"@one", "line"=>1}, {"name"=>"@two", "line"=>1}]}]
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,126 @@
1
+ require 'rspec'
2
+ require File.dirname(__FILE__) + "/../lib/repo"
3
+
4
+ describe "select" do
5
+ describe "single value, single results" do
6
+ it 'should get scenario outlines line number' do
7
+ gs = CQL::Repository.new File.expand_path(File.dirname(__FILE__)) + "/../fixtures/features/scen_outlines/basic"
8
+ result = gs.query do
9
+ select line
10
+ from scenario_outlines
11
+ end
12
+ result.should == {"line"=>3}
13
+ end
14
+
15
+ it 'should get scenario outlines name' do
16
+ gs = CQL::Repository.new File.expand_path(File.dirname(__FILE__)) + "/../fixtures/features/scen_outlines/basic"
17
+ result = gs.query do
18
+ select name
19
+ from scenario_outlines
20
+ end
21
+ result.should == {"name"=> "An Outline"}
22
+ end
23
+
24
+ it "should return the examples used" do
25
+ gr = CQL::Repository.new File.expand_path(File.dirname(__FILE__)) + "/../fixtures/features/scen_outlines/basic"
26
+ result = gr.query do
27
+ select examples
28
+ from scenario_outlines
29
+ end
30
+ result.should == {"examples"=>[{"keyword"=>"Examples", "name"=>"", "line"=>6,
31
+ "description"=>"", "id"=>"test-feature;an-outline;",
32
+ "rows"=>[{"cells"=>["var_a", "var_b"], "line"=>7, "id"=>"test-feature;an-outline;;1"},
33
+ {"cells"=>["1", "a"], "line"=>8, "id"=>"test-feature;an-outline;;2"},
34
+ {"cells"=>["2", "b"], "line"=>9, "id"=>"test-feature;an-outline;;3"},
35
+ {"cells"=>["3", "c"], "line"=>10, "id"=>"test-feature;an-outline;;4"},
36
+ {"cells"=>["4", "d"], "line"=>11, "id"=>"test-feature;an-outline;;5"}]
37
+ }]}
38
+ end
39
+
40
+ it "should return multiple examples used for a single scenario outline" do
41
+ gr = CQL::Repository.new File.expand_path(File.dirname(__FILE__)) + "/../fixtures/features/scen_outlines/multiple_examples"
42
+ result = gr.query do
43
+ select examples
44
+ from scenario_outlines
45
+ end
46
+ result.should == {"examples"=>[{"keyword"=>"Examples", "name"=>"One", "line"=>6, "description"=>"", "id"=>"test-feature;an-outline;one",
47
+ "rows"=>[{"cells"=>["var_a", "var_b"], "line"=>7, "id"=>"test-feature;an-outline;one;1"},
48
+ {"cells"=>["1", "a"], "line"=>8, "id"=>"test-feature;an-outline;one;2"},
49
+ {"cells"=>["2", "b"], "line"=>9, "id"=>"test-feature;an-outline;one;3"}]},
50
+ {"keyword"=>"Examples", "name"=>"Two", "line"=>11, "description"=>"", "id"=>"test-feature;an-outline;two",
51
+ "rows"=>[{"cells"=>["var_a", "var_b"], "line"=>12, "id"=>"test-feature;an-outline;two;1"},
52
+ {"cells"=>["1", "a"], "line"=>13, "id"=>"test-feature;an-outline;two;2"},
53
+ {"cells"=>["2", "b"], "line"=>14, "id"=>"test-feature;an-outline;two;3"}]}]}
54
+ end
55
+
56
+ end
57
+
58
+ describe "single value, multiple results" do
59
+ it 'should get scenario outlines as is when no select criteria given' do
60
+ expected = {"all"=>{"keyword"=>"Scenario Outline",
61
+ "name"=>"An Outline",
62
+ "line"=>3, "description"=>"",
63
+ "id"=>"test-feature;an-outline", "type"=>"scenario_outline",
64
+ "steps"=>[{"keyword"=>"Given ", "name"=>"something happend", "line"=>4},
65
+ {"keyword"=>"Then ", "name"=>"I expect something else", "line"=>5}],
66
+ "examples"=>[{"keyword"=>"Examples", "name"=>"", "line"=>6, "description"=>"", "id"=>"test-feature;an-outline;",
67
+ "rows"=>[{"cells"=>["var_a", "var_b"], "line"=>7, "id"=>"test-feature;an-outline;;1"},
68
+ {"cells"=>["1", "a"], "line"=>8, "id"=>"test-feature;an-outline;;2"},
69
+ {"cells"=>["2", "b"], "line"=>9, "id"=>"test-feature;an-outline;;3"},
70
+ {"cells"=>["3", "c"], "line"=>10, "id"=>"test-feature;an-outline;;4"},
71
+ {"cells"=>["4", "d"], "line"=>11, "id"=>"test-feature;an-outline;;5"}]}]}}
72
+
73
+ gs = CQL::Repository.new File.expand_path(File.dirname(__FILE__)) + "/../fixtures/features/scen_outlines/basic"
74
+ result = gs.query do
75
+ select all
76
+ from scenario_outlines
77
+ end
78
+ result.should == expected
79
+
80
+ result = gs.query do
81
+ select everything
82
+ from scenario_outlines
83
+ end
84
+ result.should == expected
85
+
86
+ result = gs.query do
87
+ select complete
88
+ from scenario_outlines
89
+ end
90
+ result.should == expected
91
+ end
92
+ end
93
+
94
+ describe "select all" do
95
+
96
+ end
97
+
98
+ describe "special selectors" do
99
+ it 'should get the full step line scenario outlines' do
100
+ gs = CQL::Repository.new File.expand_path(File.dirname(__FILE__)) + "/../fixtures/features/scen_outlines/basic"
101
+ result = gs.query do
102
+ select step_lines
103
+ from scenario_outlines
104
+ end
105
+ result.should == {"step_lines"=> ["Given something happend", "Then I expect something else"]}
106
+ end
107
+ end
108
+
109
+ describe "multiple values" do
110
+ it 'should get scenario outlines name and line numbers as a map' do
111
+ gs = CQL::Repository.new File.expand_path(File.dirname(__FILE__)) + "/../fixtures/features/scen_outlines/basic"
112
+ result = gs.query do
113
+ select name, line, type, step_lines, id, steps
114
+ from scenario_outlines
115
+ end
116
+ result.should == {'name'=>"An Outline",
117
+ 'line'=>3,
118
+ 'id'=>'test-feature;an-outline',
119
+ 'type'=>'scenario_outline',
120
+ "steps"=>[{"keyword"=>"Given ", "name"=>"something happend", "line"=>4}, {"keyword"=>"Then ", "name"=>"I expect something else", "line"=>5}],
121
+ "step_lines"=>["Given something happend", "Then I expect something else"]
122
+ }
123
+ end
124
+
125
+ end
126
+ end
@@ -0,0 +1,73 @@
1
+ require 'rspec'
2
+ require File.dirname(__FILE__) + "/../lib/repo"
3
+
4
+ describe "select" do
5
+
6
+ describe "single value, multiple results" do
7
+ it 'should get scenario line number' do
8
+ gr = CQL::Repository.new File.expand_path(File.dirname(__FILE__)) + "/../fixtures/features/scenario/simple2"
9
+ result = gr.query do
10
+ select line
11
+ from scenarios
12
+ end
13
+ result.should == [{"line"=> 6}, {"line"=> 11}, {"line"=> 16}, {"line"=> 21}]
14
+ end
15
+
16
+ it 'should get scenario name' do
17
+ gr = CQL::Repository.new File.expand_path(File.dirname(__FILE__)) + "/../fixtures/features/scenario/simple2"
18
+ result = gr.query do
19
+ select name
20
+ from scenarios
21
+ end
22
+ result.should == [{"name"=> "Testing the slurping"}, {"name"=> "Testing again"},
23
+ {"name"=> "Testing yet again"}, {"name"=> "Testing yet again part 2"}]
24
+ end
25
+
26
+ it 'should get scenario name from multiple feature files' do
27
+ gr = CQL::Repository.new File.expand_path(File.dirname(__FILE__)) + "/../fixtures/features/scenario/simple"
28
+ result = gr.query do
29
+ select name
30
+ from scenarios
31
+ end
32
+ result.should == [{"name"=> "Has a table"}, {"name"=> "Testing the slurping 1"},
33
+ {"name"=> "Testing the slurping not to be found"}, {"name"=> "Testing the slurping 2"},
34
+ {"name"=> "Testing the slurping 3"}, {"name"=> "Testing again"},
35
+ {"name"=> "Testing yet again"}, {"name"=> "Testing yet again part 2"}]
36
+ end
37
+ end
38
+
39
+ describe "multiple values" do
40
+ it 'should get multiple scenarios as a list of maps' do
41
+ gr = CQL::Repository.new File.expand_path(File.dirname(__FILE__)) + "/../fixtures/features/scenario/simple2"
42
+ result = gr.query do
43
+ select line, name
44
+ from scenarios
45
+ end
46
+ result.should == [{'line'=>6, 'name'=>"Testing the slurping"}, {'line'=>11, 'name'=>"Testing again"},
47
+ {'line'=>16, 'name'=>"Testing yet again"}, {'line'=>21, 'name'=>"Testing yet again part 2"}]
48
+ end
49
+
50
+ it "should select all" do
51
+ gr = CQL::Repository.new File.expand_path(File.dirname(__FILE__)) + "/../fixtures/features/scenario/table"
52
+ expected = {"all"=>{"keyword"=>"Scenario", "name"=>"Has a table", "line"=>3,
53
+ "description"=>"", "id"=>"simple;has-a-table", "type"=>"scenario",
54
+ "steps"=>[{"keyword"=>"Given ", "name"=>"Something", "line"=>4,
55
+ "rows"=>[{"cells"=>["a", "a"], "line"=>5}, {"cells"=>["s", "a"], "line"=>6},
56
+ {"cells"=>["s", "s"], "line"=>7}]},
57
+ {"keyword"=>"Then ", "name"=>"something else", "line"=>8}]}}
58
+
59
+ result = gr.query do
60
+ select all
61
+ from scenarios
62
+ end
63
+ result.should == expected
64
+
65
+ result = gr.query do
66
+ select complete
67
+ from scenarios
68
+ end
69
+ result.should == expected
70
+ end
71
+
72
+ end
73
+ end
data/spec/unit_spec.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'rspec'
2
- require File.dirname(__FILE__) + "/../lib/" + "gherkin_repo"
2
+ require File.dirname(__FILE__) + "/../lib/repo"
3
3
 
4
4
  describe "cql" do
5
5
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-02 00:00:00.000000000 Z
12
+ date: 2012-08-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gherkin
@@ -85,27 +85,30 @@ files:
85
85
  - README.md
86
86
  - cql.gemspec
87
87
  - fixtures/.gitkeep
88
- - fixtures/features/scen_outlines/test_with_scenarios.feature
89
- - fixtures/features/simple/simple.feature
90
- - fixtures/features/simple/test.feature
91
- - fixtures/features/simple/test2.feature
92
- - fixtures/features/simple/test_full.feature
93
- - fixtures/features/simple2/test_full.feature
94
- - fixtures/features/table/simple.feature
95
- - fixtures/features/tagged_features/simple.feature
96
- - fixtures/features/tagged_features/test.feature
97
- - fixtures/features/tagged_features/test2.feature
98
- - fixtures/features/tagged_features/test_full.feature
99
- - fixtures/features/tags/simple.feature
100
- - fixtures/features/tags2/simple.feature
101
- - fixtures/features/tags2/simple2.feature
88
+ - fixtures/features/scen_outlines/basic/test_with_scenarios.feature
89
+ - fixtures/features/scen_outlines/multiple_examples/test_with_scenarios.feature
90
+ - fixtures/features/scenario/simple/simple.feature
91
+ - fixtures/features/scenario/simple/test.feature
92
+ - fixtures/features/scenario/simple/test2.feature
93
+ - fixtures/features/scenario/simple/test_full.feature
94
+ - fixtures/features/scenario/simple2/test_full.feature
95
+ - fixtures/features/scenario/table/simple.feature
96
+ - fixtures/features/scenario/tagged_features/simple.feature
97
+ - fixtures/features/scenario/tagged_features/test.feature
98
+ - fixtures/features/scenario/tagged_features/test2.feature
99
+ - fixtures/features/scenario/tagged_features/test_full.feature
100
+ - fixtures/features/scenario/tags/simple.feature
101
+ - fixtures/features/scenario/tags2/simple.feature
102
+ - fixtures/features/scenario/tags2/simple2.feature
102
103
  - lib/dsl.rb
103
- - lib/gherkin_map_reduce.rb
104
- - lib/gherkin_repo.rb
104
+ - lib/map_reduce.rb
105
+ - lib/repo.rb
105
106
  - projectFilesBackup/.idea/workspace.xml
106
107
  - spec/filter_dsl_spec.rb
107
108
  - spec/map_reduce_spec.rb
108
- - spec/select_dsl_spec.rb
109
+ - spec/select_feature_dsl_spec.rb
110
+ - spec/select_scen_outline_dsl_spec.rb
111
+ - spec/select_scenario_dsl_spec.rb
109
112
  - spec/unit_spec.rb
110
113
  homepage:
111
114
  licenses: []
@@ -114,7 +117,7 @@ post_install_message: ! '
114
117
  (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::)
115
118
 
116
119
 
117
- Thank you for installing gql (Gherkin Query Language)
120
+ Thank you for installing cql (Cucumber Query Language)
118
121
 
119
122
 
120
123
  (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::) (::)
@@ -139,8 +142,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
142
  version: '0'
140
143
  requirements: []
141
144
  rubyforge_project:
142
- rubygems_version: 1.8.23
145
+ rubygems_version: 1.8.24
143
146
  signing_key:
144
147
  specification_version: 3
145
- summary: cucumber-0.0.1
148
+ summary: cucumber-0.0.2
146
149
  test_files: []
@@ -1,5 +0,0 @@
1
- Feature: Test2 Feature
2
-
3
- Scenario: Testing the slurping
4
- Given something happend
5
- Then I expect something else
@@ -1,68 +0,0 @@
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
@@ -1,53 +0,0 @@
1
- require 'rspec'
2
- require File.dirname(__FILE__) + "/../lib/" + "gherkin_repo"
3
-
4
- describe "cql" do
5
- describe "select" do
6
- it 'should find the feature file names' do
7
- gs = CQL::GherkinRepository.new File.dirname(__FILE__) + "/../fixtures/features/simple"
8
-
9
- result = gs.query do
10
- select names
11
- from features
12
- end
13
-
14
- result.should == ["Simple", "Test Feature", "Test2 Feature", "Test3 Feature"]
15
- end
16
-
17
- it 'should find the feature file names' do
18
- gs = CQL::GherkinRepository.new File.dirname(__FILE__) + "/../fixtures/features/simple"
19
-
20
- result = gs.query do
21
- select uri
22
- from features
23
- end
24
-
25
- result[0].should =~ /simple\.feature/
26
- result[1].should =~ /test\.feature/
27
- result[2].should =~ /test2\.feature/
28
- result[3].should =~ /test_full\.feature/
29
- end
30
-
31
- it 'should get scenario outlines as a list' do
32
- gs = CQL::GherkinRepository.new File.expand_path(File.dirname(__FILE__)) + "/../fixtures/features/scen_outlines"
33
-
34
- result = gs.query do
35
- select names
36
- from scenario_outlines
37
- end
38
-
39
- result.should == ["An Outline"]
40
- end
41
-
42
- it 'should get scenario as a list' do
43
- gr = CQL::GherkinRepository.new File.expand_path(File.dirname(__FILE__)) + "/../fixtures/features/simple2"
44
-
45
- result = gr.query do
46
- select names
47
- from scenarios
48
- end
49
-
50
- result.should == ["Testing the slurping", "Testing again", "Testing yet again", "Testing yet again part 2"]
51
- end
52
- end
53
- end