cuke_modeler 1.0.4 → 1.1.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.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +12 -0
  3. data/lib/cuke_modeler/adapters/gherkin_2_adapter.rb +5 -5
  4. data/lib/cuke_modeler/adapters/gherkin_3_adapter.rb +8 -5
  5. data/lib/cuke_modeler/adapters/gherkin_4_adapter.rb +8 -5
  6. data/lib/cuke_modeler/containing.rb +12 -7
  7. data/lib/cuke_modeler/models/background.rb +7 -2
  8. data/lib/cuke_modeler/models/cell.rb +2 -1
  9. data/lib/cuke_modeler/models/doc_string.rb +2 -1
  10. data/lib/cuke_modeler/models/example.rb +8 -4
  11. data/lib/cuke_modeler/models/feature.rb +4 -1
  12. data/lib/cuke_modeler/models/outline.rb +6 -2
  13. data/lib/cuke_modeler/models/row.rb +2 -1
  14. data/lib/cuke_modeler/models/scenario.rb +7 -2
  15. data/lib/cuke_modeler/models/step.rb +2 -1
  16. data/lib/cuke_modeler/models/table.rb +2 -1
  17. data/lib/cuke_modeler/models/tag.rb +2 -1
  18. data/lib/cuke_modeler/parsing.rb +45 -0
  19. data/lib/cuke_modeler/version.rb +1 -1
  20. data/testing/cucumber/features/modeling/background_modeling.feature +7 -0
  21. data/testing/cucumber/features/modeling/background_output.feature +6 -1
  22. data/testing/cucumber/features/modeling/directory_output.feature +6 -1
  23. data/testing/cucumber/features/modeling/doc_string_output.feature +6 -1
  24. data/testing/cucumber/features/modeling/example_modeling.feature +7 -0
  25. data/testing/cucumber/features/modeling/example_output.feature +6 -1
  26. data/testing/cucumber/features/modeling/feature_file_output.feature +6 -1
  27. data/testing/cucumber/features/modeling/feature_modeling.feature +7 -0
  28. data/testing/cucumber/features/modeling/feature_output.feature +6 -1
  29. data/testing/cucumber/features/modeling/model_output.feature +1 -8
  30. data/testing/cucumber/features/modeling/outline_modeling.feature +7 -0
  31. data/testing/cucumber/features/modeling/outline_output.feature +6 -1
  32. data/testing/cucumber/features/modeling/row_output.feature +6 -1
  33. data/testing/cucumber/features/modeling/scenario_modeling.feature +7 -0
  34. data/testing/cucumber/features/modeling/scenario_output.feature +6 -1
  35. data/testing/cucumber/features/modeling/step_output.feature +6 -1
  36. data/testing/cucumber/features/modeling/table_output.feature +6 -1
  37. data/testing/cucumber/features/modeling/tag_output.feature +6 -1
  38. data/testing/cucumber/step_definitions/verification_steps.rb +21 -12
  39. data/testing/dialect_helper.rb +48 -0
  40. data/testing/rspec/spec/integration/background_integration_spec.rb +93 -88
  41. data/testing/rspec/spec/integration/cell_integration_spec.rb +26 -27
  42. data/testing/rspec/spec/integration/directory_integration_spec.rb +4 -4
  43. data/testing/rspec/spec/integration/doc_string_integration_spec.rb +38 -39
  44. data/testing/rspec/spec/integration/example_integration_spec.rb +97 -95
  45. data/testing/rspec/spec/integration/feature_file_integration_spec.rb +5 -5
  46. data/testing/rspec/spec/integration/feature_integration_spec.rb +157 -155
  47. data/testing/rspec/spec/integration/gherkin_2_adapter_spec.rb +17 -17
  48. data/testing/rspec/spec/integration/gherkin_3_adapter_spec.rb +17 -17
  49. data/testing/rspec/spec/integration/gherkin_4_adapter_spec.rb +17 -17
  50. data/testing/rspec/spec/integration/outline_integration_spec.rb +359 -354
  51. data/testing/rspec/spec/integration/parsing_integration_spec.rb +30 -2
  52. data/testing/rspec/spec/integration/row_integration_spec.rb +23 -25
  53. data/testing/rspec/spec/integration/scenario_integration_spec.rb +238 -235
  54. data/testing/rspec/spec/integration/step_integration_spec.rb +69 -64
  55. data/testing/rspec/spec/integration/table_integration_spec.rb +32 -36
  56. data/testing/rspec/spec/integration/tag_integration_spec.rb +26 -27
  57. data/testing/rspec/spec/spec_helper.rb +43 -0
  58. data/testing/rspec/spec/unit/background_unit_spec.rb +7 -0
  59. data/testing/rspec/spec/unit/example_unit_spec.rb +7 -0
  60. data/testing/rspec/spec/unit/feature_unit_spec.rb +7 -0
  61. data/testing/rspec/spec/unit/outline_unit_spec.rb +7 -0
  62. data/testing/rspec/spec/unit/parsing_unit_spec.rb +33 -0
  63. data/testing/rspec/spec/unit/scenario_unit_spec.rb +7 -0
  64. data/testing/rspec/spec/unit/shared/keyworded_models_unit_specs.rb +58 -0
  65. data/testing/rspec/spec/unit/step_unit_spec.rb +1 -23
  66. data/testing/test_languages.json +45 -0
  67. data/todo.txt +1 -1
  68. metadata +6 -3
@@ -4,6 +4,7 @@ module CukeModeler
4
4
 
5
5
  class Table < Model
6
6
 
7
+ include Parsing
7
8
  include Parsed
8
9
  include Sourceable
9
10
 
@@ -41,7 +42,7 @@ module CukeModeler
41
42
 
42
43
 
43
44
  def parse_source(source_text)
44
- base_file_string = "Feature:\nScenario:\n* step\n"
45
+ base_file_string = "#{dialect_feature_keyword}:\n#{dialect_scenario_keyword}:\n#{dialect_step_keyword} step\n"
45
46
  source_text = base_file_string + source_text
46
47
 
47
48
  parsed_file = Parsing::parse_text(source_text, 'cuke_modeler_stand_alone_table.feature')
@@ -4,6 +4,7 @@ module CukeModeler
4
4
 
5
5
  class Tag < Model
6
6
 
7
+ include Parsing
7
8
  include Parsed
8
9
  include Sourceable
9
10
 
@@ -34,7 +35,7 @@ module CukeModeler
34
35
 
35
36
 
36
37
  def parse_source(source_text)
37
- base_file_string = "\nFeature: Fake feature to parse"
38
+ base_file_string = "\n#{dialect_feature_keyword}: Fake feature to parse"
38
39
  source_text = source_text + base_file_string
39
40
 
40
41
  parsed_file = Parsing::parse_text(source_text, 'cuke_modeler_stand_alone_tag.feature')
@@ -73,6 +73,24 @@ module CukeModeler
73
73
 
74
74
  class << self
75
75
 
76
+ # The dialect that will be used to parse snippets of Gherkin text
77
+ attr_writer :dialect
78
+
79
+
80
+ # The dialect that will be used to parse snippets of Gherkin text
81
+ def dialect
82
+ @dialect || 'en'
83
+ end
84
+
85
+ # The dialects currently known by the gherkin gem
86
+ def dialects
87
+ unless @dialects
88
+ @dialects = Gem.loaded_specs['gherkin'].version.version[/^2/] ? Gherkin::I18n::LANGUAGES : Gherkin::DIALECTS
89
+ end
90
+
91
+ @dialects
92
+ end
93
+
76
94
  # Parses the Cucumber feature given in *source_text* and returns an array
77
95
  # containing the hash representation of its logical structure.
78
96
  def parse_text(source_text, filename = 'cuke_modeler_fake_file.feature')
@@ -92,5 +110,32 @@ module CukeModeler
92
110
  end
93
111
 
94
112
  end
113
+
114
+
115
+ private
116
+
117
+
118
+ def dialect_feature_keyword
119
+ get_word(Parsing.dialects[Parsing.dialect]['feature'])
120
+ end
121
+
122
+ def dialect_scenario_keyword
123
+ get_word(Parsing.dialects[Parsing.dialect]['scenario'])
124
+ end
125
+
126
+ def dialect_outline_keyword
127
+ get_word(Parsing.dialects[Parsing.dialect]['scenarioOutline'] || Parsing.dialects[Parsing.dialect]['scenario_outline'])
128
+ end
129
+
130
+ def dialect_step_keyword
131
+ get_word(Parsing.dialects[Parsing.dialect]['given'])
132
+ end
133
+
134
+ def get_word(word_set)
135
+ word_set = word_set.is_a?(Array) ? word_set : word_set.split('|')
136
+
137
+ word_set.first
138
+ end
139
+
95
140
  end
96
141
  end
@@ -1,4 +1,4 @@
1
1
  module CukeModeler
2
2
  # The gem version
3
- VERSION = "1.0.4"
3
+ VERSION = "1.1.0"
4
4
  end
@@ -24,6 +24,13 @@ Feature: Background modeling
24
24
  """
25
25
 
26
26
 
27
+ Scenario: Modeling a backgrounds's keyword
28
+ When the backgrounds's keyword is requested
29
+ """
30
+ @model.keyword
31
+ """
32
+ Then the model returns "Background"
33
+
27
34
  Scenario: Modeling a backgrounds's name
28
35
  When the background's name is requested
29
36
  """
@@ -1,6 +1,7 @@
1
1
  Feature: Background output
2
2
 
3
- A background model's string output is a Gherkin representation of itself.
3
+ A background model's string output is a Gherkin representation of itself. As such, output from a background model can be used as
4
+ input for the same kind of model.
4
5
 
5
6
 
6
7
  Scenario: Outputting a background model
@@ -40,3 +41,7 @@ Feature: Background output
40
41
  some string
41
42
  \"\"\"
42
43
  """
44
+ And the output can be used to make an equivalent model
45
+ """
46
+ CukeModeler::Background.new(@model.to_s)
47
+ """
@@ -1,6 +1,7 @@
1
1
  Feature: Directory output
2
2
 
3
- A directory model's string output is simply the file path of the directory that it models.
3
+ A directory model's string output is simply the file path of the directory that it models. As such, output from a directory model can be used as
4
+ input for the same kind of model.
4
5
 
5
6
 
6
7
  Scenario: Outputting a directory model
@@ -10,3 +11,7 @@ Feature: Directory output
10
11
  """
11
12
  <path_to>/some_directory
12
13
  """
14
+ And the output can be used to make an equivalent model
15
+ """
16
+ CukeModeler::Directory.new(@model.to_s)
17
+ """
@@ -1,6 +1,7 @@
1
1
  Feature: Doc string output
2
2
 
3
- A doc string model's string output is a Gherkin representation of itself.
3
+ A doc string model's string output is a Gherkin representation of itself. As such, output from a doc string model can be used as
4
+ input for the same kind of model.
4
5
 
5
6
 
6
7
  Scenario: Outputting a doc string model
@@ -30,3 +31,7 @@ Feature: Doc string output
30
31
 
31
32
  \"\"\"
32
33
  """
34
+ And the output can be used to make an equivalent model
35
+ """
36
+ CukeModeler::DocString.new(@model.to_s)
37
+ """
@@ -25,6 +25,13 @@ Feature: Example modeling
25
25
  """
26
26
 
27
27
 
28
+ Scenario: Modeling an example's keyword
29
+ When the example's keyword is requested
30
+ """
31
+ @model.keyword
32
+ """
33
+ Then the model returns "Examples"
34
+
28
35
  Scenario: Modeling an example's name
29
36
  When the example's name is requested
30
37
  """
@@ -1,6 +1,7 @@
1
1
  Feature: Example output
2
2
 
3
- An example model's string output is a Gherkin representation of itself.
3
+ An example model's string output is a Gherkin representation of itself. As such, output from an example model can be used as
4
+ input for the same kind of model.
4
5
 
5
6
 
6
7
  Scenario: Outputting an example model
@@ -37,3 +38,7 @@ Feature: Example output
37
38
  | value1 | value2 |
38
39
  | value3 | value4 |
39
40
  """
41
+ And the output can be used to make an equivalent model
42
+ """
43
+ CukeModeler::Example.new(@model.to_s)
44
+ """
@@ -1,6 +1,7 @@
1
1
  Feature: Feature file output
2
2
 
3
- A feature file model's string output is simply the file path of the feature file that it models.
3
+ A feature file model's string output is simply the file path of the feature file that it models. As such, output from a feature file model can be used as
4
+ input for the same kind of model.
4
5
 
5
6
 
6
7
  Scenario: Outputting a feature file model
@@ -10,3 +11,7 @@ Feature: Feature file output
10
11
  """
11
12
  <path_to>/some_feature_file.feature
12
13
  """
14
+ And the output can be used to make an equivalent model
15
+ """
16
+ CukeModeler::FeatureFile.new(@model.to_s)
17
+ """
@@ -43,6 +43,13 @@ present in that feature.
43
43
  """
44
44
 
45
45
 
46
+ Scenario: Modeling a feature's keyword
47
+ When the feature's keyword is requested
48
+ """
49
+ @model.keyword
50
+ """
51
+ Then the model returns "Feature"
52
+
46
53
  Scenario: Modeling a feature's name
47
54
  When the feature's name is requested
48
55
  """
@@ -1,6 +1,7 @@
1
1
  Feature: Feature output
2
2
 
3
- A feature model's string output is a Gherkin representation of itself.
3
+ A feature model's string output is a Gherkin representation of itself. As such, output from a feature model can be used as
4
+ input for the same kind of model.
4
5
 
5
6
 
6
7
  Scenario: Outputting a feature model
@@ -102,3 +103,7 @@ Feature: Feature output
102
103
  | param |
103
104
  | value |
104
105
  """
106
+ And the output can be used to make an equivalent model
107
+ """
108
+ CukeModeler::Feature.new(@model.to_s)
109
+ """
@@ -2,8 +2,7 @@ Feature: Model output
2
2
 
3
3
  All models can be output in text form. For models that represent parts of the file structure, this text
4
4
  will be a path and for models that represent parts of a feature file, this text will be Gherkin (see the
5
- model output documentation for specific models for details). As such, output from a model can be used as
6
- input for the same kind of model.
5
+ model output documentation for specific models for details).
7
6
 
8
7
 
9
8
  Scenario: Outputting a model
@@ -14,9 +13,3 @@ Feature: Model output
14
13
 
15
14
  model.to_s
16
15
  """
17
- And the output can be used to make an equivalent model
18
- """
19
- model = <model_class>.new
20
-
21
- <model_class>.new(model.to_s)
22
- """
@@ -32,6 +32,13 @@ Feature: Outline modeling
32
32
  """
33
33
 
34
34
 
35
+ Scenario: Modeling an outline's keyword
36
+ When the outline's keyword is requested
37
+ """
38
+ @model.keyword
39
+ """
40
+ Then the model returns "Scenario Outline"
41
+
35
42
  Scenario: Modeling an outline's name
36
43
  When the outline's name is requested
37
44
  """
@@ -1,6 +1,7 @@
1
1
  Feature: Outline output
2
2
 
3
- An outline model's string output is a Gherkin representation of itself.
3
+ An outline model's string output is a Gherkin representation of itself. As such, output from an outline model can be used as
4
+ input for the same kind of model.
4
5
 
5
6
 
6
7
  Scenario: Outputting an outline model
@@ -67,3 +68,7 @@ Feature: Outline output
67
68
  | value |
68
69
  | y |
69
70
  """
71
+ And the output can be used to make an equivalent model
72
+ """
73
+ CukeModeler::Outline.new(@model.to_s)
74
+ """
@@ -1,6 +1,7 @@
1
1
  Feature: Row output
2
2
 
3
- A row model's string output is a Gherkin representation of itself.
3
+ A row model's string output is a Gherkin representation of itself. As such, output from a row model can be used as
4
+ input for the same kind of model.
4
5
 
5
6
 
6
7
  Scenario: Outputting a row model
@@ -20,3 +21,7 @@ Feature: Row output
20
21
  """
21
22
  | foo | bar |
22
23
  """
24
+ And the output can be used to make an equivalent model
25
+ """
26
+ CukeModeler::Row.new(@model.to_s)
27
+ """
@@ -24,6 +24,13 @@ Feature: Scenario modeling
24
24
  """
25
25
 
26
26
 
27
+ Scenario: Modeling a scenario's keyword
28
+ When the scenario's keyword is requested
29
+ """
30
+ @model.keyword
31
+ """
32
+ Then the model returns "Scenario"
33
+
27
34
  Scenario: Modeling a scenario's name
28
35
  When the scenario's name is requested
29
36
  """
@@ -1,6 +1,7 @@
1
1
  Feature: Scenario output
2
2
 
3
- A scenario model's string output is a Gherkin representation of itself.
3
+ A scenario model's string output is a Gherkin representation of itself. As such, output from a scenario model can be used as
4
+ input for the same kind of model.
4
5
 
5
6
 
6
7
  Scenario: Outputting a scenario model
@@ -43,3 +44,7 @@ Feature: Scenario output
43
44
  some string
44
45
  \"\"\"
45
46
  """
47
+ And the output can be used to make an equivalent model
48
+ """
49
+ CukeModeler::Scenario.new(@model.to_s)
50
+ """
@@ -1,6 +1,7 @@
1
1
  Feature: Step output
2
2
 
3
- A step model's string output is a Gherkin representation of itself.
3
+ A step model's string output is a Gherkin representation of itself. As such, output from a step model can be used as
4
+ input for the same kind of model.
4
5
 
5
6
 
6
7
  Scenario: Outputting a step model
@@ -27,3 +28,7 @@ Feature: Step output
27
28
  | value1 |
28
29
  | value2 |
29
30
  """
31
+ And the output can be used to make an equivalent model
32
+ """
33
+ CukeModeler::Step.new(@model.to_s)
34
+ """
@@ -1,6 +1,7 @@
1
1
  Feature: Table output
2
2
 
3
- A table model's string output is a Gherkin representation of itself.
3
+ A table model's string output is a Gherkin representation of itself. As such, output from a table model can be used as
4
+ input for the same kind of model.
4
5
 
5
6
 
6
7
  Scenario: Outputting a table model
@@ -22,3 +23,7 @@ Feature: Table output
22
23
  | value1 | value2 |
23
24
  | value3 | value4 |
24
25
  """
26
+ And the output can be used to make an equivalent model
27
+ """
28
+ CukeModeler::Table.new(@model.to_s)
29
+ """
@@ -1,6 +1,7 @@
1
1
  Feature: Tag output
2
2
 
3
- A tag model's string output is a Gherkin representation of itself.
3
+ A tag model's string output is a Gherkin representation of itself. As such, output from a tag model can be used as
4
+ input for the same kind of model.
4
5
 
5
6
 
6
7
  Scenario: Outputting a tag model
@@ -20,3 +21,7 @@ Feature: Tag output
20
21
  """
21
22
  @a_tag
22
23
  """
24
+ And the output can be used to make an equivalent model
25
+ """
26
+ CukeModeler::Tag.new(@model.to_s)
27
+ """
@@ -1,6 +1,8 @@
1
1
  Then(/^all of them can be output as text appropriate to the model type$/) do |code_text|
2
+ original_text = code_text
3
+
2
4
  @available_model_classes.each do |clazz|
3
- code_text.gsub!('<model_class>', clazz.to_s)
5
+ code_text = original_text.gsub('<model_class>', clazz.to_s)
4
6
 
5
7
  expect(clazz.instance_method(:to_s).owner).to equal(clazz), "#{clazz} does not override #to_s"
6
8
 
@@ -16,8 +18,10 @@ Then(/^the following text is provided:$/) do |expected_text|
16
18
  end
17
19
 
18
20
  Then(/^all of them can be contained inside of another model$/) do |code_text|
21
+ original_text = code_text
22
+
19
23
  @available_model_classes.each do |clazz|
20
- code_text.gsub!('<model_class>', clazz.to_s)
24
+ code_text = original_text.gsub('<model_class>', clazz.to_s)
21
25
 
22
26
  expect(clazz.new).to respond_to(:parent_model)
23
27
 
@@ -27,8 +31,10 @@ Then(/^all of them can be contained inside of another model$/) do |code_text|
27
31
  end
28
32
 
29
33
  And(/^all of them can contain other models$/) do |code_text|
34
+ original_text = code_text
35
+
30
36
  @available_model_classes.each do |clazz|
31
- code_text.gsub!('<model_class>', clazz.to_s)
37
+ code_text = original_text.gsub('<model_class>', clazz.to_s)
32
38
 
33
39
  expect(clazz.new).to respond_to(:children)
34
40
 
@@ -38,8 +44,10 @@ And(/^all of them can contain other models$/) do |code_text|
38
44
  end
39
45
 
40
46
  Then(/^all of them can be created without further context$/) do |code_text|
47
+ original_text = code_text
48
+
41
49
  @available_model_classes.each do |clazz|
42
- code_text.gsub!('<model_class>', clazz.to_s)
50
+ code_text = original_text.gsub('<model_class>', clazz.to_s)
43
51
 
44
52
  expect { clazz.new }.to_not raise_error
45
53
 
@@ -73,18 +81,19 @@ Then(/^the model returns models for the following directories:$/) do |directory_
73
81
  end
74
82
 
75
83
  And(/^the output can be used to make an equivalent model$/) do |code_text|
76
- @available_model_classes.each do |clazz|
77
- code_text.gsub!('<model_class>', clazz.to_s)
84
+ clazz = @model.class
78
85
 
79
- # More specific verification can't be done for this step because every model has a different
80
- # populated shape and abstract shape isn't enough to be useful input to the model again.
86
+ base_output = @model.to_s
87
+ remodeled_output = clazz.new(base_output).to_s
81
88
 
82
- # Make sure that the example code is valid
83
- expect { eval(code_text) }.to_not raise_error
84
- end
89
+ expect(remodeled_output).to eq(base_output)
90
+
91
+ # Make sure that the example code is valid
92
+ expect { eval(code_text) }.to_not raise_error
85
93
  end
86
94
 
87
95
  Then(/^all of them provide access to the parsing data that was used to create them$/) do |code_text|
96
+ original_text = code_text
88
97
  unparsed_models = [CukeModeler::Model, CukeModeler::FeatureFile, CukeModeler::Directory]
89
98
 
90
99
  @available_model_classes.each do |clazz|
@@ -93,7 +102,7 @@ Then(/^all of them provide access to the parsing data that was used to create th
93
102
  expect(clazz.new).to respond_to(:parsing_data)
94
103
 
95
104
  # Make sure that the example code is valid
96
- code_text.gsub!('<model_class>', clazz.to_s)
105
+ code_text = original_text.gsub('<model_class>', clazz.to_s)
97
106
  code_text.gsub!('<source_text>', '')
98
107
 
99
108
  expect { eval(code_text) }.to_not raise_error