cuke_modeler 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/History.rdoc +8 -0
  3. data/features/step_definitions/feature_steps.rb +1 -1
  4. data/features/step_definitions/test_steps.rb +6 -2
  5. data/lib/cuke_modeler/directory.rb +7 -10
  6. data/lib/cuke_modeler/version.rb +1 -1
  7. data/spec/integration/background_integration_spec.rb +53 -40
  8. data/spec/integration/directory_integration_spec.rb +39 -26
  9. data/spec/integration/doc_string_integration_spec.rb +51 -43
  10. data/spec/integration/example_integration_spec.rb +71 -60
  11. data/spec/integration/feature_file_integration_spec.rb +36 -22
  12. data/spec/integration/feature_integration_spec.rb +113 -104
  13. data/spec/integration/outline_integration_spec.rb +71 -56
  14. data/spec/integration/row_integration_spec.rb +72 -0
  15. data/spec/integration/scenario_integration_spec.rb +61 -46
  16. data/spec/integration/step_integration_spec.rb +126 -117
  17. data/spec/integration/table_integration_spec.rb +67 -52
  18. data/spec/integration/table_row_integration_spec.rb +48 -40
  19. data/spec/integration/tag_integration_spec.rb +53 -45
  20. data/spec/integration/world_integration_spec.rb +2 -1
  21. data/spec/spec_helper.rb +15 -12
  22. data/spec/unit/background_unit_spec.rb +65 -50
  23. data/spec/unit/bare_bones_unit_specs.rb +2 -3
  24. data/spec/unit/containing_element_unit_specs.rb +6 -7
  25. data/spec/unit/directory_unit_spec.rb +103 -64
  26. data/spec/unit/doc_string_unit_spec.rb +113 -95
  27. data/spec/unit/example_unit_spec.rb +235 -219
  28. data/spec/unit/feature_element_unit_spec.rb +6 -6
  29. data/spec/unit/feature_element_unit_specs.rb +28 -24
  30. data/spec/unit/feature_file_unit_spec.rb +73 -63
  31. data/spec/unit/feature_unit_spec.rb +145 -111
  32. data/spec/unit/nested_element_unit_specs.rb +14 -13
  33. data/spec/unit/nested_unit_spec.rb +24 -21
  34. data/spec/unit/outline_unit_spec.rb +92 -78
  35. data/spec/unit/parsing_unit_spec.rb +55 -51
  36. data/spec/unit/prepopulated_unit_specs.rb +2 -3
  37. data/spec/unit/raw_element_unit_specs.rb +12 -11
  38. data/spec/unit/raw_unit_spec.rb +15 -12
  39. data/spec/unit/row_unit_spec.rb +68 -52
  40. data/spec/unit/scenario_unit_spec.rb +76 -62
  41. data/spec/unit/sourceable_unit_spec.rb +8 -6
  42. data/spec/unit/sourced_element_unit_specs.rb +4 -6
  43. data/spec/unit/step_unit_spec.rb +231 -203
  44. data/spec/unit/table_row_unit_spec.rb +68 -52
  45. data/spec/unit/table_unit_spec.rb +100 -82
  46. data/spec/unit/tag_unit_spec.rb +62 -48
  47. data/spec/unit/taggable_unit_spec.rb +58 -51
  48. data/spec/unit/tagged_element_unit_specs.rb +28 -26
  49. data/spec/unit/test_element_unit_spec.rb +33 -27
  50. data/spec/unit/test_element_unit_specs.rb +15 -14
  51. data/spec/unit/world_unit_spec.rb +94 -84
  52. metadata +4 -2
@@ -4,27 +4,28 @@ shared_examples_for 'a nested element' do
4
4
 
5
5
  # clazz must be defined by the calling file
6
6
 
7
- before(:each) do
8
- @nested_element = clazz.new
9
- end
7
+ let(:nested_element) { clazz.new }
8
+
10
9
 
11
- it 'has a parent element - #parent_element' do
12
- @nested_element.should respond_to(:parent_element)
10
+ it 'has a parent element' do
11
+ nested_element.should respond_to(:parent_element)
13
12
  end
14
13
 
15
- it 'can get and set its parent element - #parent_element, #parent_element=' do
16
- @nested_element.parent_element = :some_parent_element
17
- @nested_element.parent_element.should == :some_parent_element
18
- @nested_element.parent_element = :some_other_parent_element
19
- @nested_element.parent_element.should == :some_other_parent_element
14
+ it 'can change its parent element' do
15
+ expect(nested_element).to respond_to(:parent_element=)
16
+
17
+ nested_element.parent_element = :some_parent_element
18
+ nested_element.parent_element.should == :some_parent_element
19
+ nested_element.parent_element = :some_other_parent_element
20
+ nested_element.parent_element.should == :some_other_parent_element
20
21
  end
21
22
 
22
23
  it 'starts with no parent element' do
23
- @nested_element.parent_element.should == nil
24
+ nested_element.parent_element.should == nil
24
25
  end
25
26
 
26
27
  it 'has access to its ancestors' do
27
- @nested_element.should respond_to(:get_ancestor)
28
+ nested_element.should respond_to(:get_ancestor)
28
29
  end
29
30
 
30
31
  it 'gets an ancestor based on type' do
@@ -32,7 +33,7 @@ shared_examples_for 'a nested element' do
32
33
  end
33
34
 
34
35
  it 'raises and exception if an unknown ancestor type is requested' do
35
- expect { @nested_element.get_ancestor(:bad_ancestor_type) }.to raise_exception(ArgumentError)
36
+ expect { nested_element.get_ancestor(:bad_ancestor_type) }.to raise_exception(ArgumentError)
36
37
  end
37
38
 
38
39
  end
@@ -4,34 +4,37 @@ SimpleCov.command_name('Nested') unless RUBY_VERSION.to_s < '1.9.0'
4
4
 
5
5
  describe 'Nested, Unit' do
6
6
 
7
- nodule = CukeModeler::Nested
7
+ let(:nodule) { CukeModeler::Nested }
8
+ let(:nested_element) { Object.new.extend(nodule) }
8
9
 
9
- before(:each) do
10
- @nested_element = Object.new.extend(nodule)
11
- end
12
10
 
11
+ describe 'unique behavior' do
13
12
 
14
- it 'has a parent element - #parent_element' do
15
- @nested_element.should respond_to(:parent_element)
16
- end
13
+ it 'has a parent element' do
14
+ nested_element.should respond_to(:parent_element)
15
+ end
17
16
 
18
- it 'can get and set its parent element - #parent_element, #parent_element=' do
19
- @nested_element.parent_element = :some_parent_element
20
- @nested_element.parent_element.should == :some_parent_element
21
- @nested_element.parent_element = :some_other_parent_element
22
- @nested_element.parent_element.should == :some_other_parent_element
23
- end
17
+ it 'can change its parent element' do
18
+ expect(nested_element).to respond_to(:parent_element=)
24
19
 
25
- it 'has access to its ancestors' do
26
- @nested_element.should respond_to(:get_ancestor)
27
- end
20
+ nested_element.parent_element = :some_parent_element
21
+ nested_element.parent_element.should == :some_parent_element
22
+ nested_element.parent_element = :some_other_parent_element
23
+ nested_element.parent_element.should == :some_other_parent_element
24
+ end
28
25
 
29
- it 'gets an ancestor based on type' do
30
- (nodule.instance_method(:get_ancestor).arity == 1).should be_true
31
- end
26
+ it 'has access to its ancestors' do
27
+ nested_element.should respond_to(:get_ancestor)
28
+ end
29
+
30
+ it 'gets an ancestor based on type' do
31
+ (nodule.instance_method(:get_ancestor).arity == 1).should be_true
32
+ end
33
+
34
+ it 'raises and exception if an unknown ancestor type is requested' do
35
+ expect { nested_element.get_ancestor(:bad_ancestor_type) }.to raise_exception(ArgumentError)
36
+ end
32
37
 
33
- it 'raises and exception if an unknown ancestor type is requested' do
34
- expect { @nested_element.get_ancestor(:bad_ancestor_type) }.to raise_exception(ArgumentError)
35
38
  end
36
39
 
37
40
  end
@@ -5,118 +5,132 @@ SimpleCov.command_name('Outline') unless RUBY_VERSION.to_s < '1.9.0'
5
5
  describe 'Outline, Unit' do
6
6
 
7
7
  let(:clazz) { CukeModeler::Outline }
8
+ let(:outline) { clazz.new }
8
9
 
9
- it_should_behave_like 'a feature element'
10
- it_should_behave_like 'a nested element'
11
- it_should_behave_like 'a containing element'
12
- it_should_behave_like 'a tagged element'
13
- it_should_behave_like 'a bare bones element'
14
- it_should_behave_like 'a prepopulated element'
15
- it_should_behave_like 'a test element'
16
- it_should_behave_like 'a sourced element'
17
- it_should_behave_like 'a raw element'
18
10
 
11
+ describe 'common behavior' do
19
12
 
20
- it 'can be parsed from stand alone text' do
21
- source = "Scenario Outline: test outline
13
+ it_should_behave_like 'a feature element'
14
+ it_should_behave_like 'a nested element'
15
+ it_should_behave_like 'a containing element'
16
+ it_should_behave_like 'a tagged element'
17
+ it_should_behave_like 'a bare bones element'
18
+ it_should_behave_like 'a prepopulated element'
19
+ it_should_behave_like 'a test element'
20
+ it_should_behave_like 'a sourced element'
21
+ it_should_behave_like 'a raw element'
22
+
23
+ end
24
+
25
+
26
+ describe 'unique behavior' do
27
+
28
+ it 'can be parsed from stand alone text' do
29
+ source = "Scenario Outline: test outline
22
30
  Examples:
23
31
  |param|
24
32
  |value|"
25
33
 
26
- expect { @element = clazz.new(source) }.to_not raise_error
34
+ expect { @element = clazz.new(source) }.to_not raise_error
27
35
 
28
- # Sanity check in case instantiation failed in a non-explosive manner
29
- @element.name.should == 'test outline'
30
- end
36
+ # Sanity check in case instantiation failed in a non-explosive manner
37
+ @element.name.should == 'test outline'
38
+ end
31
39
 
32
- it 'provides a descriptive filename when being parsed from stand alone text' do
33
- source = "bad outline text \n Scenario Outline:\n And a step\n @foo "
40
+ it 'provides a descriptive filename when being parsed from stand alone text' do
41
+ source = "bad outline text \n Scenario Outline:\n And a step\n @foo "
34
42
 
35
- expect { clazz.new(source) }.to raise_error(/'cuke_modeler_stand_alone_outline\.feature'/)
36
- end
43
+ expect { clazz.new(source) }.to raise_error(/'cuke_modeler_stand_alone_outline\.feature'/)
44
+ end
37
45
 
38
- it 'stores the original data generated by the parsing adapter', :gherkin4 => true do
39
- outline = clazz.new("Scenario Outline: test outline\nExamples:\n|param|\n|value|")
40
- raw_data = outline.raw_element
46
+ it 'stores the original data generated by the parsing adapter', :gherkin4 => true do
47
+ outline = clazz.new("Scenario Outline: test outline\nExamples:\n|param|\n|value|")
48
+ raw_data = outline.raw_element
41
49
 
42
- expect(raw_data.keys).to match_array([:type, :tags, :location, :keyword, :name, :steps, :examples])
43
- expect(raw_data[:type]).to eq(:ScenarioOutline)
44
- end
50
+ expect(raw_data.keys).to match_array([:type, :tags, :location, :keyword, :name, :steps, :examples])
51
+ expect(raw_data[:type]).to eq(:ScenarioOutline)
52
+ end
45
53
 
46
- it 'stores the original data generated by the parsing adapter', :gherkin3 => true do
47
- outline = clazz.new("Scenario Outline: test outline\nExamples:\n|param|\n|value|")
48
- raw_data = outline.raw_element
54
+ it 'stores the original data generated by the parsing adapter', :gherkin3 => true do
55
+ outline = clazz.new("Scenario Outline: test outline\nExamples:\n|param|\n|value|")
56
+ raw_data = outline.raw_element
49
57
 
50
- expect(raw_data.keys).to match_array([:type, :tags, :location, :keyword, :name, :steps, :examples])
51
- expect(raw_data[:type]).to eq(:ScenarioOutline)
52
- end
58
+ expect(raw_data.keys).to match_array([:type, :tags, :location, :keyword, :name, :steps, :examples])
59
+ expect(raw_data[:type]).to eq(:ScenarioOutline)
60
+ end
53
61
 
54
- it 'stores the original data generated by the parsing adapter', :gherkin2 => true do
55
- outline = clazz.new("Scenario Outline: test outline\nExamples:\n|param|\n|value|")
56
- raw_data = outline.raw_element
62
+ it 'stores the original data generated by the parsing adapter', :gherkin2 => true do
63
+ outline = clazz.new("Scenario Outline: test outline\nExamples:\n|param|\n|value|")
64
+ raw_data = outline.raw_element
57
65
 
58
- expect(raw_data.keys).to match_array(['keyword', 'name', 'line', 'description', 'id', 'type'])
59
- expect(raw_data['keyword']).to eq('Scenario Outline')
60
- end
66
+ expect(raw_data.keys).to match_array(['keyword', 'name', 'line', 'description', 'id', 'type'])
67
+ expect(raw_data['keyword']).to eq('Scenario Outline')
68
+ end
69
+
70
+ it 'has examples' do
71
+ outline.should respond_to(:examples)
72
+ end
61
73
 
74
+ it 'can change its examples' do
75
+ expect(outline).to respond_to(:examples=)
62
76
 
63
- before(:each) do
64
- @outline = clazz.new
65
- end
77
+ outline.examples = :some_examples
78
+ outline.examples.should == :some_examples
79
+ outline.examples = :some_other_examples
80
+ outline.examples.should == :some_other_examples
81
+ end
66
82
 
83
+ it 'starts with no examples' do
84
+ outline.examples.should == []
85
+ end
67
86
 
68
- it 'has examples - #examples' do
69
- @outline.should respond_to(:examples)
70
- end
87
+ it 'contains steps and examples' do
88
+ steps = [:step_1, :step_2, :step_3]
89
+ examples = [:example_1, :example_2, :example_3]
90
+ everything = steps + examples
71
91
 
72
- it 'can get and set its examples - #examples, #examples=' do
73
- @outline.examples = :some_examples
74
- @outline.examples.should == :some_examples
75
- @outline.examples = :some_other_examples
76
- @outline.examples.should == :some_other_examples
77
- end
92
+ outline.steps = steps
93
+ outline.examples = examples
78
94
 
79
- it 'starts with no examples' do
80
- @outline.examples.should == []
81
- end
95
+ outline.contains.should =~ everything
96
+ end
82
97
 
83
- it 'contains steps and examples' do
84
- steps = [:step_1, :step_2, :step_3]
85
- examples = [:example_1, :example_2, :example_3]
86
- everything = steps + examples
98
+ describe 'outline output edge cases' do
87
99
 
88
- @outline.steps = steps
89
- @outline.examples = examples
100
+ it 'is a String' do
101
+ outline.to_s.should be_a(String)
102
+ end
90
103
 
91
- @outline.contains.should =~ everything
92
- end
93
104
 
94
- context 'outline output edge cases' do
105
+ context 'a new outline object' do
95
106
 
96
- it 'is a String' do
97
- @outline.to_s.should be_a(String)
98
- end
107
+ let(:outline) { clazz.new }
99
108
 
100
- it 'can output an empty outline' do
101
- expect { @outline.to_s }.to_not raise_error
102
- end
103
109
 
104
- it 'can output an outline that has only a name' do
105
- @outline.name = 'a name'
110
+ it 'can output an empty outline' do
111
+ expect { outline.to_s }.to_not raise_error
112
+ end
106
113
 
107
- expect { @outline.to_s }.to_not raise_error
108
- end
114
+ it 'can output an outline that has only a name' do
115
+ outline.name = 'a name'
109
116
 
110
- it 'can output an outline that has only a description' do
111
- @outline.description_text = 'a description'
117
+ expect { outline.to_s }.to_not raise_error
118
+ end
112
119
 
113
- expect { @outline.to_s }.to_not raise_error
114
- end
120
+ it 'can output an outline that has only a description' do
121
+ outline.description_text = 'a description'
122
+
123
+ expect { outline.to_s }.to_not raise_error
124
+ end
125
+
126
+ it 'can output an outline that has only tags' do
127
+ outline.tags = ['a tag']
128
+
129
+ expect { outline.to_s }.to_not raise_error
130
+ end
115
131
 
116
- it 'can output an outline that has only a tags' do
117
- @outline.tags = ['a tag']
132
+ end
118
133
 
119
- expect { @outline.to_s }.to_not raise_error
120
134
  end
121
135
 
122
136
  end
@@ -7,79 +7,83 @@ describe 'Parsing, Unit' do
7
7
  let(:nodule) { CukeModeler::Parsing }
8
8
 
9
9
 
10
- it 'can parse text - #parse_text' do
11
- nodule.should respond_to(:parse_text)
12
- end
13
-
14
- it 'can only parse strings' do
15
- expect { nodule.parse_text(5) }.to raise_error(ArgumentError)
16
- expect { nodule.parse_text('Feature:') }.to_not raise_error
17
- end
10
+ describe 'unique behavior' do
18
11
 
19
- it 'returns an Array' do
20
- result = nodule.parse_text('Feature:')
21
- result.is_a?(Array).should be_true
22
- end
12
+ it 'can parse text' do
13
+ nodule.should respond_to(:parse_text)
14
+ end
23
15
 
24
- it 'takes the text that is to be parsed and an optional file name' do
25
- expect(nodule.method(:parse_text).arity).to eq(-2)
26
- end
16
+ it 'can only parse strings' do
17
+ expect { nodule.parse_text(5) }.to raise_error(ArgumentError)
18
+ expect { nodule.parse_text('Feature:') }.to_not raise_error
19
+ end
27
20
 
28
- it 'raises and error if an error is encountered while parsing text' do
29
- expect { nodule.parse_text('bad file') }.to raise_error(ArgumentError, /Error encountered while parsing '.*'/)
30
- end
21
+ it 'returns an Array' do
22
+ result = nodule.parse_text('Feature:')
23
+ result.is_a?(Array).should be_true
24
+ end
31
25
 
32
- it 'includes the file parsed in the error that it raises' do
33
- expect { nodule.parse_text('bad file', 'file foo.txt') }.to raise_error(/'file foo\.txt'/)
34
- end
26
+ it 'takes the text that is to be parsed and an optional file name' do
27
+ expect(nodule.method(:parse_text).arity).to eq(-2)
28
+ end
35
29
 
36
- it 'includes the underlying error message in the error that it raises' do
37
- begin
38
- # Custom error type in order to ensure that we are throwing the correct thing
39
- module CukeModeler
40
- class TestError < StandardError
41
- end
42
- end
30
+ it 'raises and error if an error is encountered while parsing text' do
31
+ expect { nodule.parse_text('bad file') }.to raise_error(ArgumentError, /Error encountered while parsing '.*'/)
32
+ end
43
33
 
44
- # Monkey patch Gherkin to throw the error that we need for testing
45
- if Gem.loaded_specs['gherkin'].version.version[/^3|4/]
46
- old_method = Gherkin::Parser.instance_method(:parse)
34
+ it 'includes the file parsed in the error that it raises' do
35
+ expect { nodule.parse_text('bad file', 'file foo.txt') }.to raise_error(/'file foo\.txt'/)
36
+ end
47
37
 
48
- module Gherkin
49
- class Parser
50
- def parse(*args)
51
- raise(CukeModeler::TestError, 'something went wrong')
52
- end
38
+ it 'includes the underlying error message in the error that it raises' do
39
+ begin
40
+ # Custom error type in order to ensure that we are throwing the correct thing
41
+ module CukeModeler
42
+ class TestError < StandardError
53
43
  end
54
44
  end
55
- else
56
- old_method = Gherkin::Parser::Parser.instance_method(:parse)
57
45
 
58
- module Gherkin
59
- module Parser
46
+ # Monkey patch Gherkin to throw the error that we need for testing
47
+ if Gem.loaded_specs['gherkin'].version.version[/^3|4/]
48
+ old_method = Gherkin::Parser.instance_method(:parse)
49
+
50
+ module Gherkin
60
51
  class Parser
61
52
  def parse(*args)
62
53
  raise(CukeModeler::TestError, 'something went wrong')
63
54
  end
64
55
  end
65
56
  end
57
+ else
58
+ old_method = Gherkin::Parser::Parser.instance_method(:parse)
59
+
60
+ module Gherkin
61
+ module Parser
62
+ class Parser
63
+ def parse(*args)
64
+ raise(CukeModeler::TestError, 'something went wrong')
65
+ end
66
+ end
67
+ end
68
+ end
66
69
  end
67
- end
68
70
 
69
- expect { nodule.parse_text('bad file') }.to raise_error(/CukeModeler::TestError.*something went wrong/)
70
- ensure
71
- # Making sure that our changes don't escape a test and ruin the rest of the suite
72
- if Gem.loaded_specs['gherkin'].version.version[/^3|4/]
73
- Gherkin::Parser.send(:define_method, :parse, old_method)
74
- else
75
- Gherkin::Parser::Parser.send(:define_method, :parse, old_method)
71
+ expect { nodule.parse_text('bad file') }.to raise_error(/CukeModeler::TestError.*something went wrong/)
72
+ ensure
73
+ # Making sure that our changes don't escape a test and ruin the rest of the suite
74
+ if Gem.loaded_specs['gherkin'].version.version[/^3|4/]
75
+ Gherkin::Parser.send(:define_method, :parse, old_method)
76
+ else
77
+ Gherkin::Parser::Parser.send(:define_method, :parse, old_method)
78
+ end
76
79
  end
80
+
77
81
  end
78
82
 
79
- end
83
+ it 'has a default file name if one is not provided' do
84
+ expect { nodule.parse_text('bad file') }.to raise_error(ArgumentError, /'cuke_modeler_fake_file\.feature'/)
85
+ end
80
86
 
81
- it 'has a default file name if one is not provided' do
82
- expect { nodule.parse_text('bad file') }.to raise_error(ArgumentError, /'cuke_modeler_fake_file\.feature'/)
83
87
  end
84
88
 
85
89
  end