cuke_modeler 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.simplecov +8 -0
  4. data/Gemfile +4 -0
  5. data/History.rdoc +3 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +73 -0
  8. data/Rakefile +38 -0
  9. data/cuke_modeler.gemspec +29 -0
  10. data/features/analysis/test_comparison.feature +123 -0
  11. data/features/analysis/test_manipulation.feature +37 -0
  12. data/features/modeling/background_modeling.feature +75 -0
  13. data/features/modeling/background_output.feature +130 -0
  14. data/features/modeling/directory_modeling.feature +120 -0
  15. data/features/modeling/directory_output.feature +13 -0
  16. data/features/modeling/doc_string_modeling.feature +63 -0
  17. data/features/modeling/doc_string_output.feature +71 -0
  18. data/features/modeling/example_modeling.feature +111 -0
  19. data/features/modeling/example_output.feature +192 -0
  20. data/features/modeling/feature_file_modeling.feature +64 -0
  21. data/features/modeling/feature_file_output.feature +13 -0
  22. data/features/modeling/feature_modeling.feature +164 -0
  23. data/features/modeling/feature_output.feature +244 -0
  24. data/features/modeling/outline_modeling.feature +100 -0
  25. data/features/modeling/outline_output.feature +197 -0
  26. data/features/modeling/row_modeling.feature +77 -0
  27. data/features/modeling/row_output.feature +27 -0
  28. data/features/modeling/scenario_modeling.feature +89 -0
  29. data/features/modeling/scenario_output.feature +147 -0
  30. data/features/modeling/step_modeling.feature +85 -0
  31. data/features/modeling/step_output.feature +52 -0
  32. data/features/modeling/table_modeling.feature +52 -0
  33. data/features/modeling/table_output.feature +42 -0
  34. data/features/modeling/table_row_modeling.feature +67 -0
  35. data/features/modeling/table_row_output.feature +27 -0
  36. data/features/modeling/tag_modeling.feature +58 -0
  37. data/features/modeling/tag_output.feature +16 -0
  38. data/features/step_definitions/action_steps.rb +3 -0
  39. data/features/step_definitions/background_steps.rb +81 -0
  40. data/features/step_definitions/directory_steps.rb +52 -0
  41. data/features/step_definitions/doc_string_steps.rb +63 -0
  42. data/features/step_definitions/feature_file_steps.rb +41 -0
  43. data/features/step_definitions/feature_steps.rb +96 -0
  44. data/features/step_definitions/outline_steps.rb +252 -0
  45. data/features/step_definitions/setup_steps.rb +50 -0
  46. data/features/step_definitions/spec_steps.rb +18 -0
  47. data/features/step_definitions/step_steps.rb +159 -0
  48. data/features/step_definitions/table_steps.rb +54 -0
  49. data/features/step_definitions/tag_steps.rb +61 -0
  50. data/features/step_definitions/test_steps.rb +114 -0
  51. data/features/step_definitions/verification_steps.rb +9 -0
  52. data/features/support/env.rb +27 -0
  53. data/features/support/transforms.rb +3 -0
  54. data/lib/cuke_modeler.rb +29 -0
  55. data/lib/cuke_modeler/background.rb +38 -0
  56. data/lib/cuke_modeler/containing.rb +18 -0
  57. data/lib/cuke_modeler/directory.rb +86 -0
  58. data/lib/cuke_modeler/doc_string.rb +87 -0
  59. data/lib/cuke_modeler/example.rb +184 -0
  60. data/lib/cuke_modeler/feature.rb +147 -0
  61. data/lib/cuke_modeler/feature_element.rb +73 -0
  62. data/lib/cuke_modeler/feature_file.rb +77 -0
  63. data/lib/cuke_modeler/nested.rb +34 -0
  64. data/lib/cuke_modeler/outline.rb +68 -0
  65. data/lib/cuke_modeler/parsing.rb +32 -0
  66. data/lib/cuke_modeler/raw.rb +20 -0
  67. data/lib/cuke_modeler/row.rb +64 -0
  68. data/lib/cuke_modeler/scenario.rb +45 -0
  69. data/lib/cuke_modeler/sourceable.rb +20 -0
  70. data/lib/cuke_modeler/step.rb +214 -0
  71. data/lib/cuke_modeler/table.rb +90 -0
  72. data/lib/cuke_modeler/table_row.rb +64 -0
  73. data/lib/cuke_modeler/tag.rb +62 -0
  74. data/lib/cuke_modeler/taggable.rb +54 -0
  75. data/lib/cuke_modeler/test_element.rb +77 -0
  76. data/lib/cuke_modeler/version.rb +3 -0
  77. data/lib/cuke_modeler/world.rb +113 -0
  78. data/spec/integration/background_integration_spec.rb +72 -0
  79. data/spec/integration/directory_integration_spec.rb +48 -0
  80. data/spec/integration/doc_string_integration_spec.rb +66 -0
  81. data/spec/integration/example_integration_spec.rb +94 -0
  82. data/spec/integration/feature_file_integration_spec.rb +44 -0
  83. data/spec/integration/feature_integration_spec.rb +152 -0
  84. data/spec/integration/outline_integration_spec.rb +92 -0
  85. data/spec/integration/scenario_integration_spec.rb +80 -0
  86. data/spec/integration/step_integration_spec.rb +184 -0
  87. data/spec/integration/table_integration_spec.rb +86 -0
  88. data/spec/integration/table_row_integration_spec.rb +68 -0
  89. data/spec/integration/tag_integration_spec.rb +67 -0
  90. data/spec/integration/world_integration_spec.rb +13 -0
  91. data/spec/spec_helper.rb +30 -0
  92. data/spec/unit/background_unit_spec.rb +55 -0
  93. data/spec/unit/bare_bones_unit_specs.rb +13 -0
  94. data/spec/unit/containing_element_unit_specs.rb +17 -0
  95. data/spec/unit/directory_unit_spec.rb +103 -0
  96. data/spec/unit/doc_string_unit_spec.rb +109 -0
  97. data/spec/unit/example_unit_spec.rb +251 -0
  98. data/spec/unit/feature_element_unit_spec.rb +19 -0
  99. data/spec/unit/feature_element_unit_specs.rb +46 -0
  100. data/spec/unit/feature_file_unit_spec.rb +94 -0
  101. data/spec/unit/feature_unit_spec.rb +135 -0
  102. data/spec/unit/nested_element_unit_specs.rb +36 -0
  103. data/spec/unit/nested_unit_spec.rb +37 -0
  104. data/spec/unit/outline_unit_spec.rb +91 -0
  105. data/spec/unit/parsing_unit_spec.rb +21 -0
  106. data/spec/unit/prepopulated_unit_specs.rb +13 -0
  107. data/spec/unit/raw_element_unit_specs.rb +24 -0
  108. data/spec/unit/raw_unit_spec.rb +25 -0
  109. data/spec/unit/row_unit_spec.rb +55 -0
  110. data/spec/unit/scenario_unit_spec.rb +71 -0
  111. data/spec/unit/sourceable_unit_spec.rb +17 -0
  112. data/spec/unit/sourced_element_unit_specs.rb +18 -0
  113. data/spec/unit/step_unit_spec.rb +259 -0
  114. data/spec/unit/table_row_unit_spec.rb +55 -0
  115. data/spec/unit/table_unit_spec.rb +96 -0
  116. data/spec/unit/tag_unit_spec.rb +51 -0
  117. data/spec/unit/taggable_unit_spec.rb +78 -0
  118. data/spec/unit/tagged_element_unit_specs.rb +63 -0
  119. data/spec/unit/test_element_unit_spec.rb +40 -0
  120. data/spec/unit/test_element_unit_specs.rb +31 -0
  121. data/spec/unit/world_unit_spec.rb +130 -0
  122. metadata +364 -0
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ SimpleCov.command_name('Tag') unless RUBY_VERSION.to_s < '1.9.0'
4
+
5
+ describe 'Tag, Integration' do
6
+
7
+ context 'getting stuff' do
8
+
9
+ before(:each) do
10
+ source = ['@feature_tag',
11
+ 'Feature: Test feature',
12
+ '',
13
+ ' Scenario Outline: Test test',
14
+ ' * a step',
15
+ '',
16
+ ' @example_tag',
17
+ ' Examples: Test example',
18
+ ' | a param |']
19
+ source = source.join("\n")
20
+
21
+ file_path = "#{@default_file_directory}/tag_test_file.feature"
22
+ File.open(file_path, 'w') { |file| file.write(source) }
23
+
24
+ @directory = CukeModeler::Directory.new(@default_file_directory)
25
+ @tag = @directory.feature_files.first.features.first.tests.first.examples.first.tag_elements.first
26
+ @high_level_tag = @directory.feature_files.first.features.first.tag_elements.first
27
+ end
28
+
29
+
30
+ it 'can get its directory' do
31
+ directory = @tag.get_ancestor(:directory)
32
+
33
+ directory.should equal @directory
34
+ end
35
+
36
+ it 'can get its feature file' do
37
+ feature_file = @tag.get_ancestor(:feature_file)
38
+
39
+ feature_file.should equal @directory.feature_files.first
40
+ end
41
+
42
+ it 'can get its feature' do
43
+ feature = @tag.get_ancestor(:feature)
44
+
45
+ feature.should equal @directory.feature_files.first.features.first
46
+ end
47
+
48
+ it 'can get its test' do
49
+ test = @tag.get_ancestor(:test)
50
+
51
+ test.should equal @directory.feature_files.first.features.first.tests.first
52
+ end
53
+
54
+ it 'can get its example' do
55
+ example = @tag.get_ancestor(:example)
56
+
57
+ example.should equal @directory.feature_files.first.features.first.tests.first.examples.first
58
+ end
59
+
60
+ it 'returns nil if it does not have the requested type of ancestor' do
61
+ example = @high_level_tag.get_ancestor(:example)
62
+
63
+ example.should be_nil
64
+ end
65
+
66
+ end
67
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ SimpleCov.command_name('World') unless RUBY_VERSION.to_s < '1.9.0'
4
+
5
+ describe 'World, Integration' do
6
+
7
+ before(:each) do
8
+ @world = CukeModeler::World
9
+ @world.loaded_step_patterns.clear
10
+ end
11
+
12
+ # Nothing left to do here for now.
13
+ end
@@ -0,0 +1,30 @@
1
+ require 'simplecov' unless RUBY_VERSION.to_s < '1.9.0'
2
+
3
+
4
+ require "#{File.dirname(__FILE__)}/../lib/cuke_modeler"
5
+
6
+ require "#{File.dirname(__FILE__)}/unit/feature_element_unit_specs"
7
+ require "#{File.dirname(__FILE__)}/unit/nested_element_unit_specs"
8
+ require "#{File.dirname(__FILE__)}/unit/tagged_element_unit_specs"
9
+ require "#{File.dirname(__FILE__)}/unit/containing_element_unit_specs"
10
+ require "#{File.dirname(__FILE__)}/unit/bare_bones_unit_specs"
11
+ require "#{File.dirname(__FILE__)}/unit/test_element_unit_specs"
12
+ require "#{File.dirname(__FILE__)}/unit/prepopulated_unit_specs"
13
+ require "#{File.dirname(__FILE__)}/unit/sourced_element_unit_specs"
14
+ require "#{File.dirname(__FILE__)}/unit/raw_element_unit_specs"
15
+
16
+ RSpec.configure do |config|
17
+ config.before(:all) do
18
+ @default_file_directory = "#{File.dirname(__FILE__)}/temp_files"
19
+ @default_feature_file_name = 'test_feature.feature'
20
+ end
21
+
22
+ config.before(:each) do
23
+ FileUtils.mkdir(@default_file_directory)
24
+ end
25
+
26
+ config.after(:each) do
27
+ FileUtils.remove_dir(@default_file_directory, true)
28
+ end
29
+ end
30
+
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ SimpleCov.command_name('Background') unless RUBY_VERSION.to_s < '1.9.0'
4
+
5
+ describe 'Background, Unit' do
6
+
7
+ clazz = CukeModeler::Background
8
+
9
+ it_should_behave_like 'a feature element', clazz
10
+ it_should_behave_like 'a nested element', clazz
11
+ it_should_behave_like 'a containing element', clazz
12
+ it_should_behave_like 'a bare bones element', clazz
13
+ it_should_behave_like 'a prepopulated element', clazz
14
+ it_should_behave_like 'a test element', clazz
15
+ it_should_behave_like 'a sourced element', clazz
16
+ it_should_behave_like 'a raw element', clazz
17
+
18
+ it 'can be parsed from stand alone text' do
19
+ source = 'Background: test background'
20
+
21
+ expect { @element = clazz.new(source) }.to_not raise_error
22
+
23
+ # Sanity check in case instantiation failed in a non-explosive manner
24
+ @element.name.should == 'test background'
25
+ end
26
+
27
+ context 'background output edge cases' do
28
+
29
+ before(:each) do
30
+ @background = clazz.new
31
+ end
32
+
33
+ it 'is a String' do
34
+ @background.to_s.should be_a(String)
35
+ end
36
+
37
+ it 'can output an empty background' do
38
+ expect { @background.to_s }.to_not raise_error
39
+ end
40
+
41
+ it 'can output a background that has only a name' do
42
+ @background.name = 'a name'
43
+
44
+ expect { @background.to_s }.to_not raise_error
45
+ end
46
+
47
+ it 'can output a background that has only a description' do
48
+ @background.description_text = 'a description'
49
+
50
+ expect { @background.to_s }.to_not raise_error
51
+ end
52
+
53
+ end
54
+
55
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ shared_examples_for 'a bare bones element' do |clazz|
4
+
5
+ before(:each) do
6
+ @element = clazz.new
7
+ end
8
+
9
+ it 'can be initialized empty' do
10
+ expect { clazz.new }.to_not raise_error
11
+ end
12
+
13
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ shared_examples_for 'a containing element' do |clazz|
4
+
5
+ before(:each) do
6
+ @element = clazz.new
7
+ end
8
+
9
+ it 'has children - #contains' do
10
+ @element.should respond_to(:contains)
11
+ end
12
+
13
+ it 'returns a collection of children - #contains' do
14
+ @element.contains.is_a?(Array).should be_true
15
+ end
16
+
17
+ end
@@ -0,0 +1,103 @@
1
+ require 'spec_helper'
2
+
3
+ SimpleCov.command_name('Directory') unless RUBY_VERSION.to_s < '1.9.0'
4
+
5
+ describe 'Directory, Unit' do
6
+
7
+ clazz = CukeModeler::Directory
8
+
9
+ it_should_behave_like 'a nested element', clazz
10
+ it_should_behave_like 'a containing element', clazz
11
+ it_should_behave_like 'a bare bones element', clazz
12
+ it_should_behave_like 'a prepopulated element', clazz
13
+
14
+ before(:each) do
15
+ @directory = clazz.new
16
+ end
17
+
18
+ it 'cannot model a non-existent directory' do
19
+ path = "#{@default_file_directory}/missing_directory"
20
+
21
+ expect { CukeModeler::Directory.new(path) }.to raise_error(ArgumentError)
22
+ end
23
+
24
+ it 'knows the name of the directory that it is modeling' do
25
+ path = "#{@default_file_directory}"
26
+
27
+ directory = CukeModeler::Directory.new(path)
28
+
29
+ directory.name.should == 'temp_files'
30
+ end
31
+
32
+ it 'knows the path of the directory that it is modeling' do
33
+ path = "#{@default_file_directory}"
34
+
35
+ directory = CukeModeler::Directory.new(path)
36
+
37
+ directory.path.should == path
38
+ end
39
+
40
+ it 'has feature files - #feature_files' do
41
+ @directory.should respond_to(:feature_files)
42
+ end
43
+
44
+ it 'can get and set its feature files - #feature_files, #feature_files=' do
45
+ @directory.feature_files = :some_feature_files
46
+ @directory.feature_files.should == :some_feature_files
47
+ @directory.feature_files = :some_other_feature_files
48
+ @directory.feature_files.should == :some_other_feature_files
49
+ end
50
+
51
+ it 'knows how many feature files it has - #feature_file_count' do
52
+ @directory.feature_files = [:file_1, :file_2, :file_3]
53
+
54
+ @directory.feature_file_count.should == 3
55
+ end
56
+
57
+ it 'has directories - #directories' do
58
+ @directory.should respond_to(:directories)
59
+ end
60
+
61
+ it 'can get and set its directories - #directories, #directories=' do
62
+ @directory.directories = :some_directories
63
+ @directory.directories.should == :some_directories
64
+ @directory.directories = :some_other_directories
65
+ @directory.directories.should == :some_other_directories
66
+ end
67
+
68
+ it 'knows how many directories it has - #directory_count' do
69
+ @directory.directories = [:directory_1, :directory_2, :directory_3]
70
+
71
+ @directory.directory_count.should == 3
72
+ end
73
+
74
+ it 'starts with no feature files or directories' do
75
+ @directory.feature_files.should == []
76
+ @directory.directories.should == []
77
+ end
78
+
79
+ it 'contains feature files and directories' do
80
+ directories = [:directory_1, :directory_2, :directory_3]
81
+ files = [:file_1, :file_2, :file_3]
82
+ everything = files + directories
83
+
84
+ @directory.directories = directories
85
+ @directory.feature_files = files
86
+
87
+ @directory.contains.should =~ everything
88
+ end
89
+
90
+ context 'directory output edge cases' do
91
+
92
+ it 'is a String' do
93
+ @directory.to_s.should be_a(String)
94
+ end
95
+
96
+ it 'can output an empty directory' do
97
+ expect { @directory.to_s }.to_not raise_error
98
+ end
99
+
100
+ end
101
+
102
+ end
103
+
@@ -0,0 +1,109 @@
1
+ require 'spec_helper'
2
+
3
+ SimpleCov.command_name('DocString') unless RUBY_VERSION.to_s < '1.9.0'
4
+
5
+ describe 'DocString, Unit' do
6
+
7
+ clazz = CukeModeler::DocString
8
+
9
+ it_should_behave_like 'a nested element', clazz
10
+ it_should_behave_like 'a bare bones element', clazz
11
+ it_should_behave_like 'a prepopulated element', clazz
12
+ it_should_behave_like 'a raw element', clazz
13
+
14
+ it 'can be parsed from stand alone text' do
15
+ source = "\"\"\"\nsome doc string\n\"\"\""
16
+
17
+ expect { @element = clazz.new(source) }.to_not raise_error
18
+
19
+ # Sanity check in case instantiation failed in a non-explosive manner
20
+ @element.contents_text.should == "some doc string"
21
+ #todo Remove once Array contents is no longer supported
22
+ @element.contents.should == ["some doc string"]
23
+ end
24
+
25
+ before(:each) do
26
+ @doc_string = clazz.new
27
+ end
28
+
29
+ it 'has a content type - #content_type' do
30
+ @doc_string.should respond_to(:content_type)
31
+ end
32
+
33
+ it 'can get and set its content type - #content_type, #content_type=' do
34
+ @doc_string.content_type = :some_content_type
35
+ @doc_string.content_type.should == :some_content_type
36
+ @doc_string.content_type = :some_other_content_type
37
+ @doc_string.content_type.should == :some_other_content_type
38
+ end
39
+
40
+ it 'starts with no content type' do
41
+ @doc_string.content_type.should == nil
42
+ end
43
+
44
+ it 'has contents' do
45
+ #todo Remove once Array contents is no longer supported
46
+ @doc_string.should respond_to(:contents)
47
+ @doc_string.should respond_to(:contents_text)
48
+ end
49
+
50
+ it 'can get and set its contents' do
51
+ #todo Remove once Array contents is no longer supported
52
+ @doc_string.contents = :some_contents
53
+ @doc_string.contents.should == :some_contents
54
+ @doc_string.contents = :some_other_contents
55
+ @doc_string.contents.should == :some_other_contents
56
+
57
+ @doc_string.contents_text = :some_contents
58
+ @doc_string.contents_text.should == :some_contents
59
+ @doc_string.contents_text = :some_other_contents
60
+ @doc_string.contents_text.should == :some_other_contents
61
+ end
62
+
63
+ it 'starts with no contents' do
64
+ #todo Remove once Array contents is no longer supported
65
+ @doc_string.contents.should == []
66
+ @doc_string.contents_text.should == ''
67
+ end
68
+
69
+ #todo Remove once Array contents is no longer supported
70
+ it 'stores its contents as an array of strings - deprecated' do
71
+ source = "\"\"\"\nsome text\nsome more text\n\"\"\""
72
+ doc_string = CukeModeler::DocString.new(source)
73
+
74
+ contents = doc_string.contents
75
+
76
+ contents.is_a?(Array).should be_true
77
+ contents.each do |line|
78
+ line.is_a?(String).should be_true
79
+ end
80
+ end
81
+
82
+ it 'stores its contents as a String' do
83
+ source = "\"\"\"\nsome text\nsome more text\n\"\"\""
84
+ doc_string = clazz.new(source)
85
+
86
+ contents = doc_string.contents_text
87
+
88
+ contents.is_a?(String).should be_true
89
+ end
90
+
91
+ context 'doc string output edge cases' do
92
+
93
+ it 'is a String' do
94
+ @doc_string.to_s.should be_a(String)
95
+ end
96
+
97
+ it 'can output an empty doc string' do
98
+ expect { @doc_string.to_s }.to_not raise_error
99
+ end
100
+
101
+ it 'can output a doc string that has only a content type' do
102
+ @doc_string.content_type = 'some type'
103
+
104
+ expect { @doc_string.to_s }.to_not raise_error
105
+ end
106
+
107
+ end
108
+
109
+ end
@@ -0,0 +1,251 @@
1
+ require 'spec_helper'
2
+
3
+ SimpleCov.command_name('Example') unless RUBY_VERSION.to_s < '1.9.0'
4
+
5
+ describe 'Example, Unit' do
6
+
7
+ clazz = CukeModeler::Example
8
+
9
+ it_should_behave_like 'a feature element', clazz
10
+ it_should_behave_like 'a nested element', clazz
11
+ it_should_behave_like 'a tagged element', clazz
12
+ it_should_behave_like 'a bare bones element', clazz
13
+ it_should_behave_like 'a prepopulated element', clazz
14
+ it_should_behave_like 'a sourced element', clazz
15
+ it_should_behave_like 'a containing element', clazz
16
+ it_should_behave_like 'a raw element', clazz
17
+
18
+
19
+ it 'can be parsed from stand alone text' do
20
+ source = ['Examples: test example',
21
+ '|param| ']
22
+
23
+ source = source.join("\n")
24
+
25
+ expect { @element = clazz.new(source) }.to_not raise_error
26
+
27
+ # Sanity check in case instantiation failed in a non-explosive manner
28
+ @element.name.should == 'test example'
29
+ end
30
+
31
+
32
+ before(:each) do
33
+ @example = clazz.new
34
+ end
35
+
36
+
37
+ it 'has parameters - #parameters' do
38
+ @example.should respond_to(:parameters)
39
+ end
40
+
41
+ it 'can get and set its parameters - #parameters, #parameters=' do
42
+ @example.parameters = :some_parameters
43
+ @example.parameters.should == :some_parameters
44
+ @example.parameters = :some_other_parameters
45
+ @example.parameters.should == :some_other_parameters
46
+ end
47
+
48
+ it 'starts with no parameters' do
49
+ @example.parameters.should == []
50
+ end
51
+
52
+ it 'has rows - #rows' do
53
+ @example.should respond_to(:rows)
54
+ end
55
+
56
+ #todo - remove once Hash rows are no longer supported
57
+ it 'can get and set its rows - #rows, #rows=' do
58
+ @example.rows = :some_rows
59
+ @example.rows.should == :some_rows
60
+ @example.rows = :some_other_rows
61
+ @example.rows.should == :some_other_rows
62
+ end
63
+
64
+ #todo - remove once Hash rows are no longer supported
65
+ it 'starts with no rows' do
66
+ @example.rows.should == []
67
+ end
68
+
69
+ #todo - remove once Hash rows are no longer supported
70
+ it 'stores its rows as an nested array of hashes' do
71
+ source = "Examples:\n|param1|param2|\n|value1|value2|"
72
+ example = CukeModeler::Example.new(source)
73
+
74
+ rows = example.rows
75
+
76
+ rows.is_a?(Array).should be_true
77
+ rows.empty?.should be_false
78
+ rows.each { |row| row.is_a?(Hash).should be_true }
79
+ end
80
+
81
+ it 'does not include the parameter row as a row' do
82
+ source = "Examples:\n|param1|param2|\n|value1|value2|\n|value3|value4|"
83
+ example = CukeModeler::Example.new(source)
84
+
85
+ rows = example.rows
86
+
87
+ rows.should == [{'param1' => 'value1', 'param2' => 'value2'}, {'param1' => 'value3', 'param2' => 'value4'}]
88
+ end
89
+
90
+ it 'has row elements - #row_elements' do
91
+ @example.should respond_to(:row_elements)
92
+ end
93
+
94
+ it 'can get and set its row elements - #row_elements, #row_elements=' do
95
+ @example.row_elements = :some_row_elements
96
+ @example.row_elements.should == :some_row_elements
97
+ @example.row_elements = :some_other_row_elements
98
+ @example.row_elements.should == :some_other_row_elements
99
+ end
100
+
101
+ it 'starts with no row elements' do
102
+ @example.row_elements.should == []
103
+ end
104
+
105
+ context '#add_row' do
106
+
107
+ it 'can add a new example row' do
108
+ clazz.new.should respond_to(:add_row)
109
+ end
110
+
111
+ it 'can add a new row as a hash' do
112
+ source = "Examples:\n|param1|param2|\n|value1|value2|"
113
+ example = CukeModeler::Example.new(source)
114
+
115
+ new_row = {'param1' => 'value3', 'param2' => 'value4'}
116
+ example.add_row(new_row)
117
+
118
+ #todo - remove once Hash rows are no longer supported
119
+ example.rows.should == [{'param1' => 'value1', 'param2' => 'value2'}, {'param1' => 'value3', 'param2' => 'value4'}]
120
+ example.row_elements.collect { |row| row.cells }[1..example.row_elements.count].should == [['value1', 'value2'], ['value3', 'value4']]
121
+ end
122
+
123
+ it 'can add a new row as an array' do
124
+ source = "Examples:\n|param1|param2|\n|value1|value2|"
125
+ example = CukeModeler::Example.new(source)
126
+
127
+ new_row = ['value3', 'value4']
128
+ example.add_row(new_row)
129
+
130
+ #todo - remove once Hash rows are no longer supported
131
+ example.rows.should == [{'param1' => 'value1', 'param2' => 'value2'}, {'param1' => 'value3', 'param2' => 'value4'}]
132
+ example.row_elements.collect { |row| row.cells }[1..example.row_elements.count].should == [['value1', 'value2'], ['value3', 'value4']]
133
+ end
134
+
135
+ it 'can only use a Hash or an Array to add a new row' do
136
+ expect { @example.add_row({}) }.to_not raise_error
137
+ expect { @example.add_row([]) }.to_not raise_error
138
+ expect { @example.add_row(:a_row) }.to raise_error(ArgumentError)
139
+ end
140
+
141
+ it 'trims whitespace from added rows' do
142
+ source = "Examples:\n|param1|param2|\n|value1|value2|"
143
+ example = CukeModeler::Example.new(source)
144
+
145
+ hash_row = {'param1' => 'value3 ', 'param2' => ' value4'}
146
+ array_row = ['value5', ' value6 ']
147
+ example.add_row(hash_row)
148
+ example.add_row(array_row)
149
+
150
+ #todo - remove once Hash rows are no longer supported
151
+ example.rows.should == [{'param1' => 'value1', 'param2' => 'value2'}, {'param1' => 'value3', 'param2' => 'value4'}, {'param1' => 'value5', 'param2' => 'value6'}]
152
+ example.row_elements.collect { |row| row.cells }[1..example.row_elements.count].should == [['value1', 'value2'], ['value3', 'value4'], ['value5', 'value6']]
153
+ end
154
+ end
155
+
156
+ context '#remove_row' do
157
+
158
+ it 'can remove an existing example row' do
159
+ clazz.new.should respond_to(:remove_row)
160
+ end
161
+
162
+ it 'can remove an existing row as a hash' do
163
+ source = "Examples:\n|param1|param2|\n|value1|value2|\n|value3|value4|"
164
+ example = CukeModeler::Example.new(source)
165
+
166
+ old_row = {'param1' => 'value3', 'param2' => 'value4'}
167
+ example.remove_row(old_row)
168
+
169
+ #todo - remove once Hash rows are no longer supported
170
+ example.rows.should == [{'param1' => 'value1', 'param2' => 'value2'}]
171
+ example.row_elements.collect { |row| row.cells }[1..example.row_elements.count].should == [['value1', 'value2']]
172
+ end
173
+
174
+ it 'can remove an existing row as an array' do
175
+ source = "Examples:\n|param1|param2|\n|value1|value2|\n|value3|value4|"
176
+ example = CukeModeler::Example.new(source)
177
+
178
+ old_row = ['value3', 'value4']
179
+ example.remove_row(old_row)
180
+
181
+ #todo - remove once Hash rows are no longer supported
182
+ example.rows.should == [{'param1' => 'value1', 'param2' => 'value2'}]
183
+ example.row_elements.collect { |row| row.cells }[1..example.row_elements.count].should == [['value1', 'value2']]
184
+ end
185
+
186
+ it 'can only use a Hash or an Array to remove an existing row' do
187
+ expect { @example.remove_row({}) }.to_not raise_error
188
+ expect { @example.remove_row([]) }.to_not raise_error
189
+ expect { @example.remove_row(:a_row) }.to raise_error(ArgumentError)
190
+ end
191
+
192
+ it 'trims whitespace from removed rows' do
193
+ source = "Examples:\n|param1|param2|\n|value1|value2|\n|value3|value4|\n|value5|value6|"
194
+ example = CukeModeler::Example.new(source)
195
+
196
+ hash_row = {'param1' => 'value3 ', 'param2' => ' value4'}
197
+ array_row = ['value5', ' value6 ']
198
+ example.remove_row(hash_row)
199
+ example.remove_row(array_row)
200
+
201
+ #todo - remove once Hash rows are no longer supported
202
+ example.rows.should == [{'param1' => 'value1', 'param2' => 'value2'}]
203
+ example.row_elements.collect { |row| row.cells }[1..example.row_elements.count].should == [['value1', 'value2']]
204
+ end
205
+ end
206
+
207
+ context 'example output edge cases' do
208
+
209
+ it 'is a String' do
210
+ @example.to_s.should be_a(String)
211
+ end
212
+
213
+ it 'can output an empty example' do
214
+ expect { @example.to_s }.to_not raise_error
215
+ end
216
+
217
+ it 'can output an example that has only a name' do
218
+ @example.name = 'a name'
219
+
220
+ expect { @example.to_s }.to_not raise_error
221
+ end
222
+
223
+ it 'can output an example that has only a description' do
224
+ @example.description_text = 'a description'
225
+
226
+ expect { @example.to_s }.to_not raise_error
227
+ end
228
+
229
+ it 'can output an example that has only a tags' do
230
+ @example.tags = ['a tag']
231
+
232
+ expect { @example.to_s }.to_not raise_error
233
+ end
234
+
235
+ #todo - remove once Hash rows are no longer supported
236
+ it 'can output an example that only has parameters' do
237
+ @example.parameters = ['param1']
238
+
239
+ expect { @example.to_s }.to_not raise_error
240
+ end
241
+
242
+ #todo - remove once Hash rows are no longer supported
243
+ it 'can output an example that only has rows' do
244
+ @example.rows = [{:param1 => 'row1'}]
245
+
246
+ expect { @example.to_s }.to_not raise_error
247
+ end
248
+
249
+ end
250
+
251
+ end