cuke_modeler 1.0.4 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -54,17 +54,16 @@ describe 'Tag, Integration' do
54
54
  describe 'getting ancestors' do
55
55
 
56
56
  before(:each) do
57
- source = ['@feature_tag',
58
- 'Feature: Test feature',
59
- '',
60
- ' Scenario Outline: Test test',
61
- ' * a step',
62
- '',
63
- ' @example_tag',
64
- ' Examples: Test example',
65
- ' | a param |',
66
- ' | a value |']
67
- source = source.join("\n")
57
+ source = "@feature_tag
58
+ #{@feature_keyword}: Test feature
59
+
60
+ #{@outline_keyword}: Test test
61
+ #{@step_keyword} a step
62
+
63
+ @example_tag
64
+ #{@example_keyword}: Test example
65
+ | a param |
66
+ | a value |"
68
67
 
69
68
  file_path = "#{@default_file_directory}/tag_test_file.feature"
70
69
  File.open(file_path, 'w') { |file| file.write(source) }
@@ -96,11 +95,11 @@ describe 'Tag, Integration' do
96
95
  context 'a tag that is part of a scenario' do
97
96
 
98
97
  before(:each) do
99
- source = 'Feature: Test feature
98
+ source = "#{@feature_keyword}: Test feature
100
99
 
101
100
  @a_tag
102
- Scenario: Test scenario
103
- * a step'
101
+ #{@scenario_keyword}: Test scenario
102
+ #{@step_keyword} a step"
104
103
 
105
104
  file_path = "#{@default_file_directory}/tag_test_file.feature"
106
105
  File.open(file_path, 'w') { |file| file.write(source) }
@@ -121,14 +120,14 @@ describe 'Tag, Integration' do
121
120
  context 'a tag that is part of an outline' do
122
121
 
123
122
  before(:each) do
124
- source = 'Feature: Test feature
123
+ source = "#{@feature_keyword}: Test feature
125
124
 
126
125
  @a_tag
127
- Scenario Outline: Test outline
128
- * a step
129
- Examples:
126
+ #{@outline_keyword}: Test outline
127
+ #{@step_keyword} a step
128
+ #{@example_keyword}:
130
129
  | param |
131
- | value |'
130
+ | value |"
132
131
 
133
132
  file_path = "#{@default_file_directory}/tag_test_file.feature"
134
133
  File.open(file_path, 'w') { |file| file.write(source) }
@@ -149,14 +148,14 @@ describe 'Tag, Integration' do
149
148
  context 'a tag that is part of an example' do
150
149
 
151
150
  before(:each) do
152
- source = 'Feature: Test feature
151
+ source = "#{@feature_keyword}: Test feature
153
152
 
154
- Scenario Outline: Test outline
155
- * a step
153
+ #{@outline_keyword}: Test outline
154
+ #{@step_keyword} a step
156
155
  @a_tag
157
- Examples:
156
+ #{@example_keyword}:
158
157
  | param |
159
- | value |'
158
+ | value |"
160
159
  file_path = "#{@default_file_directory}/tag_test_file.feature"
161
160
  File.open(file_path, 'w') { |file| file.write(source) }
162
161
  end
@@ -195,11 +194,11 @@ describe 'Tag, Integration' do
195
194
  end
196
195
 
197
196
  it "models the tag's source line" do
198
- source_text = "Feature:
197
+ source_text = "#{@feature_keyword}:
199
198
 
200
199
  @a_tag
201
- Scenario:
202
- * step"
200
+ #{@scenario_keyword}:
201
+ #{@step_keyword} step"
203
202
  tag = CukeModeler::Feature.new(source_text).tests.first.tags.first
204
203
 
205
204
  expect(tag.source_line).to eq(3)
@@ -21,6 +21,40 @@ require "#{this_dir}/unit/shared/bare_bones_models_unit_specs"
21
21
  require "#{this_dir}/unit/shared/prepopulated_models_unit_specs"
22
22
  require "#{this_dir}/unit/shared/sourced_models_unit_specs"
23
23
  require "#{this_dir}/unit/shared/parsed_models_unit_specs"
24
+ require "#{this_dir}/unit/shared/keyworded_models_unit_specs"
25
+
26
+ require "#{this_dir}/../../dialect_helper"
27
+
28
+
29
+ # Use a fake dialect for testing in order to avoid hard coded language assumptions in the
30
+ # implementation. Only possible with newer versions of Gherkin.
31
+ if Gem.loaded_specs['gherkin'].version.version[/^2/]
32
+ CukeModeler::DialectHelper.set_dialect(Gherkin::I18n::LANGUAGES['en'])
33
+ CukeModeler::Parsing.dialect = 'en'
34
+ else
35
+ dialect_file_path = "#{this_dir}/../../test_languages.json"
36
+ test_dialects = JSON.parse File.open(dialect_file_path, 'r:UTF-8').read
37
+
38
+ Gherkin::DIALECTS.merge!(test_dialects)
39
+
40
+
41
+ # Making the test dialect the default dialect so that language headers aren't
42
+ # needed for all of the test code.
43
+ module Gherkin
44
+ class Parser
45
+
46
+ alias_method :original_parse, :parse
47
+
48
+ def parse(token_scanner, token_matcher = TokenMatcher.new('cm-test'))
49
+ original_parse(token_scanner, token_matcher)
50
+ end
51
+
52
+ end
53
+ end
54
+
55
+ CukeModeler::DialectHelper.set_dialect(test_dialects['cm-test'])
56
+ CukeModeler::Parsing.dialect = 'cm-test'
57
+ end
24
58
 
25
59
 
26
60
  RSpec.configure do |config|
@@ -40,6 +74,15 @@ RSpec.configure do |config|
40
74
  end
41
75
 
42
76
  config.before(:all) do
77
+ @feature_keyword = CukeModeler::DialectHelper.feature_keyword
78
+ @background_keyword = CukeModeler::DialectHelper.background_keyword
79
+ @scenario_keyword = CukeModeler::DialectHelper.scenario_keyword
80
+ @outline_keyword = CukeModeler::DialectHelper.outline_keyword
81
+ @example_keyword = CukeModeler::DialectHelper.example_keyword
82
+ @step_keyword = CukeModeler::DialectHelper.step_keyword
83
+ @given_keyword = CukeModeler::DialectHelper.given_keyword
84
+ @then_keyword = CukeModeler::DialectHelper.then_keyword
85
+
43
86
  @default_file_directory = "#{this_dir}/temp_files"
44
87
  @default_feature_file_name = 'test_feature.feature'
45
88
  end
@@ -10,6 +10,7 @@ describe 'Background, Unit', :unit_test => true do
10
10
  describe 'common behavior' do
11
11
 
12
12
  it_should_behave_like 'a model'
13
+ it_should_behave_like 'a keyworded model'
13
14
  it_should_behave_like 'a named model'
14
15
  it_should_behave_like 'a described model'
15
16
  it_should_behave_like 'a stepped model'
@@ -60,6 +61,12 @@ describe 'Background, Unit', :unit_test => true do
60
61
  expect { background.to_s }.to_not raise_error
61
62
  end
62
63
 
64
+ it 'can output a background that has only a keyword' do
65
+ background.keyword = 'foo'
66
+
67
+ expect(background.to_s).to eq('foo:')
68
+ end
69
+
63
70
  it 'can output a background that has only a name' do
64
71
  background.name = 'a name'
65
72
 
@@ -9,6 +9,7 @@ describe 'Example, Unit', :unit_test => true do
9
9
  describe 'common behavior' do
10
10
 
11
11
  it_should_behave_like 'a model'
12
+ it_should_behave_like 'a keyworded model'
12
13
  it_should_behave_like 'a named model'
13
14
  it_should_behave_like 'a described model'
14
15
  it_should_behave_like 'a tagged model'
@@ -110,6 +111,12 @@ describe 'Example, Unit', :unit_test => true do
110
111
  expect { example.to_s }.to_not raise_error
111
112
  end
112
113
 
114
+ it 'can output an example that has only a keyword' do
115
+ example.keyword = 'foo'
116
+
117
+ expect(example.to_s).to eq('foo:')
118
+ end
119
+
113
120
  it 'can output an example that has only a name' do
114
121
  example.name = 'a name'
115
122
 
@@ -10,6 +10,7 @@ describe 'Feature, Unit', :unit_test => true do
10
10
  describe 'common behavior' do
11
11
 
12
12
  it_should_behave_like 'a model'
13
+ it_should_behave_like 'a keyworded model'
13
14
  it_should_behave_like 'a named model'
14
15
  it_should_behave_like 'a described model'
15
16
  it_should_behave_like 'a tagged model'
@@ -134,6 +135,12 @@ describe 'Feature, Unit', :unit_test => true do
134
135
  expect { feature.to_s }.to_not raise_error
135
136
  end
136
137
 
138
+ it 'can output a feature that has only a keyword' do
139
+ feature.keyword = 'foo'
140
+
141
+ expect(feature.to_s).to eq('foo:')
142
+ end
143
+
137
144
  it 'can output a feature that has only a name' do
138
145
  feature.name = 'a name'
139
146
 
@@ -10,6 +10,7 @@ describe 'Outline, Unit', :unit_test => true do
10
10
  describe 'common behavior' do
11
11
 
12
12
  it_should_behave_like 'a model'
13
+ it_should_behave_like 'a keyworded model'
13
14
  it_should_behave_like 'a named model'
14
15
  it_should_behave_like 'a described model'
15
16
  it_should_behave_like 'a stepped model'
@@ -94,6 +95,12 @@ describe 'Outline, Unit', :unit_test => true do
94
95
  expect { outline.to_s }.to_not raise_error
95
96
  end
96
97
 
98
+ it 'can output an outline that has only a keyword' do
99
+ outline.keyword = 'foo'
100
+
101
+ expect(outline.to_s).to eq('foo:')
102
+ end
103
+
97
104
  it 'can output an outline that has only a name' do
98
105
  outline.name = 'a name'
99
106
 
@@ -6,6 +6,16 @@ describe 'Parsing, Unit', :unit_test => true do
6
6
  let(:nodule) { CukeModeler::Parsing }
7
7
 
8
8
 
9
+ before(:all) do
10
+ @original_dialect = CukeModeler::Parsing.dialect
11
+ end
12
+
13
+ # Making sure that our changes don't escape a test and ruin the rest of the suite
14
+ after(:all) do
15
+ CukeModeler::Parsing.dialect = @original_dialect
16
+ end
17
+
18
+
9
19
  describe 'unique behavior' do
10
20
 
11
21
  it 'can parse text' do
@@ -16,6 +26,29 @@ describe 'Parsing, Unit', :unit_test => true do
16
26
  expect(nodule.method(:parse_text).arity).to eq(-2)
17
27
  end
18
28
 
29
+ it 'knows all of the available Gherkin dialects' do
30
+ expect(nodule).to respond_to(:dialects)
31
+ end
32
+
33
+ it 'has an expected dialect to use for parsing' do
34
+ expect(nodule).to respond_to(:dialect)
35
+ end
36
+
37
+ it 'can change its expected dialect' do
38
+ expect(nodule).to respond_to(:dialect=)
39
+
40
+ nodule.dialect = :some_dialect
41
+ expect(nodule.dialect).to eq(:some_dialect)
42
+ nodule.dialect = :some_other_dialect
43
+ expect(nodule.dialect).to eq(:some_other_dialect)
44
+ end
45
+
46
+ it 'defaults to English if no dialect is set' do
47
+ nodule.dialect = nil
48
+
49
+ expect(nodule.dialect).to eq('en')
50
+ end
51
+
19
52
  end
20
53
 
21
54
  end
@@ -10,6 +10,7 @@ describe 'Scenario, Unit', :unit_test => true do
10
10
  describe 'common behavior' do
11
11
 
12
12
  it_should_behave_like 'a model'
13
+ it_should_behave_like 'a keyworded model'
13
14
  it_should_behave_like 'a named model'
14
15
  it_should_behave_like 'a described model'
15
16
  it_should_behave_like 'a stepped model'
@@ -63,6 +64,12 @@ describe 'Scenario, Unit', :unit_test => true do
63
64
  expect { scenario.to_s }.to_not raise_error
64
65
  end
65
66
 
67
+ it 'can output a scenario that has only a keyword' do
68
+ scenario.keyword = 'foo'
69
+
70
+ expect(scenario.to_s).to eq('foo:')
71
+ end
72
+
66
73
  it 'can output a scenario that has only a name' do
67
74
  scenario.name = 'a name'
68
75
 
@@ -0,0 +1,58 @@
1
+ require "#{File.dirname(__FILE__)}/../../spec_helper"
2
+
3
+
4
+ shared_examples_for 'a keyworded model' do
5
+
6
+ # clazz must be defined by the calling file
7
+
8
+ let(:model) { clazz.new }
9
+
10
+
11
+ it 'has a keyword' do
12
+ expect(model).to respond_to(:keyword)
13
+ end
14
+
15
+ it 'can change its keyword' do
16
+ expect(model).to respond_to(:keyword=)
17
+
18
+ model.keyword = :some_keyword
19
+ expect(model.keyword).to eq(:some_keyword)
20
+ model.keyword = :some_other_keyword
21
+ expect(model.keyword).to eq(:some_other_keyword)
22
+ end
23
+
24
+
25
+ describe 'abstract instantiation' do
26
+
27
+ context 'a new object' do
28
+
29
+ let(:model) { clazz.new }
30
+
31
+
32
+ it 'starts with no keyword' do
33
+ expect(model.keyword).to be_nil
34
+ end
35
+
36
+ end
37
+
38
+ end
39
+
40
+
41
+ describe 'model output' do
42
+
43
+ context 'from abstract instantiation' do
44
+
45
+ let(:model) { clazz.new }
46
+
47
+
48
+ it 'can output a model that has only a keyword' do
49
+ model.keyword = 'foo'
50
+
51
+ expect { model.to_s }.to_not raise_error
52
+ end
53
+
54
+ end
55
+
56
+ end
57
+
58
+ end
@@ -10,6 +10,7 @@ describe 'Step, Unit', :unit_test => true do
10
10
  describe 'common behavior' do
11
11
 
12
12
  it_should_behave_like 'a model'
13
+ it_should_behave_like 'a keyworded model'
13
14
  it_should_behave_like 'a sourced model'
14
15
  it_should_behave_like 'a parsed model'
15
16
 
@@ -44,19 +45,6 @@ describe 'Step, Unit', :unit_test => true do
44
45
  expect(step.block).to eq(:some_other_block)
45
46
  end
46
47
 
47
- it 'has a keyword' do
48
- expect(step).to respond_to(:keyword)
49
- end
50
-
51
- it 'can change its keyword' do
52
- expect(step).to respond_to(:keyword=)
53
-
54
- step.keyword = :some_keyword
55
- expect(step.keyword).to eq(:some_keyword)
56
- step.keyword = :some_other_keyword
57
- expect(step.keyword).to eq(:some_other_keyword)
58
- end
59
-
60
48
 
61
49
  describe 'abstract instantiation' do
62
50
 
@@ -73,10 +61,6 @@ describe 'Step, Unit', :unit_test => true do
73
61
  expect(step.block).to be_nil
74
62
  end
75
63
 
76
- it 'starts with no keyword' do
77
- expect(step.keyword).to be_nil
78
- end
79
-
80
64
  end
81
65
 
82
66
  end
@@ -107,12 +91,6 @@ describe 'Step, Unit', :unit_test => true do
107
91
  expect { step.to_s }.to_not raise_error
108
92
  end
109
93
 
110
- it 'can output a step that has only a keyword' do
111
- step.keyword = '*'
112
-
113
- expect { step.to_s }.to_not raise_error
114
- end
115
-
116
94
  it 'can output a step that has only a text' do
117
95
  step.text = 'step text'
118
96
 
@@ -0,0 +1,45 @@
1
+ {
2
+ "cm-test": {
3
+ "and": [
4
+ "CM-* ",
5
+ "CM-And "
6
+ ],
7
+ "background": [
8
+ "CM-Background"
9
+ ],
10
+ "but": [
11
+ "CM-* ",
12
+ "CM-But "
13
+ ],
14
+ "examples": [
15
+ "CM-Examples",
16
+ "CM-Scenarios"
17
+ ],
18
+ "feature": [
19
+ "CM-Feature",
20
+ "CM-Business Need",
21
+ "CM-Ability"
22
+ ],
23
+ "given": [
24
+ "CM-* ",
25
+ "CM-Given "
26
+ ],
27
+ "name": "CukeModeler Test Language",
28
+ "native": "CMT",
29
+ "scenario": [
30
+ "CM-Scenario"
31
+ ],
32
+ "scenarioOutline": [
33
+ "CM-Scenario Outline",
34
+ "CM-Scenario Template"
35
+ ],
36
+ "then": [
37
+ "CM-* ",
38
+ "CM-Then "
39
+ ],
40
+ "when": [
41
+ "CM-* ",
42
+ "CM-When "
43
+ ]
44
+ }
45
+ }