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,54 @@
1
+ Then /^(?:the )?(?:feature "([^"]*)" )?(?:test(?: "([^"]*)")? )?(?:step(?: "([^"]*)") )?table has the following contents:$/ do |file, test, step, contents|
2
+ file ||= 1
3
+ test ||= 1
4
+ step ||= 1
5
+
6
+ expected = contents.raw
7
+
8
+ @parsed_files[file - 1].feature.tests[test - 1].steps[step - 1].block.row_elements.collect { |row| row.cells }.should == expected
9
+ # todo - remove once #contents is no longer supported
10
+ @parsed_files[file - 1].feature.tests[test - 1].steps[step - 1].block.contents.should == expected
11
+ end
12
+
13
+ Then /^(?:the )?(?:feature "([^"]*)" )?(?:test(?: "([^"]*)")? )?(?:step(?: "([^"]*)") )?table correctly stores its underlying implementation$/ do |file, test, step|
14
+ file ||= 1
15
+ test ||= 1
16
+ step ||= 1
17
+
18
+ raw_element = @parsed_files[file - 1].feature.tests[test - 1].steps[step - 1].block.raw_element
19
+
20
+ raw_element.is_a?(Array).should be_true
21
+ raw_element.each { |row| row.has_key?('cells').should be_true }
22
+ end
23
+
24
+ Given(/^a table row element$/) do
25
+ @element = CukeModeler::TableRow.new
26
+ end
27
+
28
+ When(/^the table row element has no cells$/) do
29
+ @element.cells = []
30
+ end
31
+
32
+ Given(/^a table row element based on the following gherkin:$/) do |row_text|
33
+ @element = CukeModeler::TableRow.new(row_text)
34
+ end
35
+
36
+ Then(/^the table row has convenient output$/) do
37
+ @parsed_files.first.feature.tests.first.steps.first.block.row_elements.first.method(:to_s).owner.should == CukeModeler::TableRow
38
+ end
39
+
40
+ Given(/^a table element$/) do
41
+ @element = CukeModeler::Table.new
42
+ end
43
+
44
+ When(/^the table element has no rows$/) do
45
+ @element.row_elements = []
46
+ end
47
+
48
+ Then(/^the table has convenient output$/) do
49
+ @parsed_files.first.feature.tests.first.steps.first.block.method(:to_s).owner.should == CukeModeler::Table
50
+ end
51
+
52
+ Given(/^a table element based on the following gherkin:$/) do |table_text|
53
+ @element = CukeModeler::Table.new(table_text)
54
+ end
@@ -0,0 +1,61 @@
1
+ Then /^the feature tag correctly stores its underlying implementation$/ do
2
+ raw_element = @parsed_files.first.feature.tag_elements.first.raw_element
3
+
4
+ raw_element.has_key?('name').should be_true
5
+ end
6
+
7
+ When(/^the test tag correctly stores its underlying implementation$/) do
8
+ raw_element = @parsed_files.first.feature.tests.first.tag_elements.first.raw_element
9
+
10
+ raw_element.has_key?('name').should be_true
11
+ end
12
+
13
+ When(/^the example tag correctly stores its underlying implementation$/) do
14
+ raw_element = @parsed_files.first.feature.tests.first.examples.first.tag_elements.first.raw_element
15
+
16
+ raw_element.has_key?('name').should be_true
17
+ end
18
+
19
+ Then(/^the feature tag name is "([^"]*)"$/) do |tag_name|
20
+ tag = @parsed_files.first.feature.tag_elements.first
21
+
22
+ tag.name.should == tag_name
23
+ end
24
+
25
+ When(/^the test tag name is "([^"]*)"$/) do |tag_name|
26
+ tag = @parsed_files.first.feature.tests.first.tag_elements.first
27
+
28
+ tag.name.should == tag_name
29
+ end
30
+
31
+ When(/^the example tag name is "([^"]*)"$/) do |tag_name|
32
+ tag = @parsed_files.first.feature.tests.first.examples.first.tag_elements.first
33
+
34
+ tag.name.should == tag_name
35
+ end
36
+
37
+ Then(/^the feature tag source line "([^"]*)"$/) do |line|
38
+ tag = @parsed_files.first.feature.tag_elements.first
39
+
40
+ tag.source_line.should == line
41
+ end
42
+
43
+ When(/^the test tag source line "([^"]*)"$/) do |line|
44
+ tag = @parsed_files.first.feature.tests.first.tag_elements.first
45
+
46
+ tag.source_line.should == line
47
+ end
48
+
49
+ When(/^the example tag source line "([^"]*)"$/) do |line|
50
+ tag = @parsed_files.first.feature.tests.first.examples.first.tag_elements.first
51
+
52
+ tag.source_line.should == line
53
+ end
54
+
55
+ Then(/^the tag has convenient output$/) do
56
+ @parsed_files.first.feature.tag_elements.first.method(:to_s).owner.should == CukeModeler::Tag
57
+ end
58
+
59
+ Given(/^a tag element based on the following gherkin:$/) do |tag_text|
60
+ @element = CukeModeler::Tag.new(tag_text)
61
+ end
@@ -0,0 +1,114 @@
1
+ Then /^(?:the )?(?:feature "([^"]*)" )?test(?: "([^"]*)")? is found to have the following properties:$/ do |file, test, properties|
2
+ file ||= 1
3
+ test ||= 1
4
+
5
+ properties = properties.rows_hash
6
+
7
+ properties.each do |property, value|
8
+ assert value == @parsed_files[file - 1].feature.tests[test - 1].send(property.to_sym).to_s
9
+ end
10
+ end
11
+
12
+ Then /^(?:the )?(?:feature "([^"]*)" )?test(?: "([^"]*)")? has the following description:$/ do |file, test, text|
13
+ file ||= 1
14
+ test ||= 1
15
+
16
+ new_description = @parsed_files[file - 1].feature.tests[test - 1].description_text
17
+ old_description = @parsed_files[file - 1].feature.tests[test - 1].description
18
+
19
+ new_description.should == text
20
+ old_description.should == remove_whitespace(text)
21
+ end
22
+
23
+ Then /^(?:the )?(?:feature "([^"]*)" )?test(?: "([^"]*)")? steps are as follows:$/ do |file, test, steps|
24
+ file ||= 1
25
+ test ||= 1
26
+
27
+ steps = steps.raw.flatten.collect do |step|
28
+ if step.start_with? "'"
29
+ step.slice(1..step.length - 2)
30
+ else
31
+ step
32
+ end
33
+ end
34
+
35
+ actual_steps = Array.new.tap do |steps|
36
+ @parsed_files[file - 1].feature.tests[test - 1].steps.each do |step|
37
+ steps << step.base
38
+ end
39
+ end
40
+
41
+ assert actual_steps.flatten == steps
42
+ end
43
+
44
+ Then /^(?:the )?(?:feature "([^"]*)" )?test(?: "([^"]*)")? is found to have the following tags:$/ do |file, test, expected_tags|
45
+ file ||= 1
46
+ test ||= 1
47
+
48
+ expected_tags = expected_tags.raw.flatten
49
+
50
+ @parsed_files[file - 1].feature.tests[test - 1].tags.should == expected_tags
51
+ @parsed_files[file - 1].feature.tests[test - 1].tag_elements.collect { |tag| tag.name }.should == expected_tags
52
+ end
53
+
54
+ Then /^(?:the )?(?:feature "([^"]*)" )?test(?: "([^"]*)")? is found to have the following applied tags:$/ do |file, test, expected_tags|
55
+ file ||= 1
56
+ test ||= 1
57
+
58
+ expected_tags = expected_tags.raw.flatten
59
+
60
+ @parsed_files[file - 1].feature.tests[test - 1].applied_tags.should == expected_tags
61
+ @parsed_files[file - 1].feature.tests[test - 1].applied_tag_elements.collect { |tag| tag.name }.should == expected_tags
62
+ end
63
+
64
+ Then /^(?:the )?(?:feature "([^"]*)" )?test(?: "([^"]*)")? step "([^"]*)" has the following block:$/ do |file, test, step, block|
65
+ file ||= 1
66
+ test ||= 1
67
+
68
+ block = block.raw.flatten.collect do |line|
69
+ if line.start_with? "'"
70
+ line.slice(1..line.length - 2)
71
+ else
72
+ line
73
+ end
74
+ end
75
+
76
+ assert @parsed_files[file - 1].feature.tests[test - 1].steps[step - 1].block == block
77
+ end
78
+
79
+ Then /^(?:the )?(?:feature "([^"]*)" )?test(?: "([^"]*)")? is equal to test "([^"]*)"$/ do |file, first_test, second_test|
80
+ file ||= 1
81
+ first_test ||= 1
82
+
83
+ expected = true
84
+ actual = @parsed_files[file - 1].feature.tests[first_test - 1] == @parsed_files[file - 1].feature.tests[second_test - 1]
85
+
86
+ assert(actual == expected, "Expected: #{expected}\n but was: #{actual}")
87
+ end
88
+
89
+ Then /^(?:the )?(?:feature "([^"]*)" )?test(?: "([^"]*)")? is not equal to test "([^"]*)"$/ do |file, first_test, second_test|
90
+ file ||= 1
91
+ first_test ||= 1
92
+
93
+ assert @parsed_files[file - 1].feature.tests[first_test - 1] != @parsed_files[file - 1].feature.tests[second_test - 1]
94
+ end
95
+
96
+ Then /^(?:the )?(?:feature "([^"]*)" )?test(?: "([^"]*)")? correctly stores its underlying implementation$/ do |file, test|
97
+ file ||= 1
98
+ test ||= 1
99
+
100
+ raw_element = @parsed_files[file - 1].feature.tests[test - 1].raw_element
101
+
102
+ expected = ['Scenario', 'Scenario Outline']
103
+ actual = raw_element['keyword']
104
+
105
+ expected.include?(actual).should be_true
106
+ end
107
+
108
+ Then(/^the scenario has convenient output$/) do
109
+ @parsed_files.first.feature.tests.first.method(:to_s).owner.should == CukeModeler::Scenario
110
+ end
111
+
112
+ Given(/^a scenario element based on the following gherkin:$/) do |scenario_text|
113
+ @element = CukeModeler::Scenario.new(scenario_text)
114
+ end
@@ -0,0 +1,9 @@
1
+ Then(/^the following text is provided:$/) do |expected_text|
2
+ expected_text.sub!('path_to', @default_file_directory)
3
+
4
+ @output.should == expected_text
5
+ end
6
+
7
+ Then(/^the text provided is "(.*)"$/) do |text_string|
8
+ @output.should == text_string.gsub('\n', "\n")
9
+ end
@@ -0,0 +1,27 @@
1
+ unless RUBY_VERSION.to_s < '1.9.0'
2
+ require 'simplecov'
3
+ SimpleCov.command_name('cucumber_tests')
4
+ end
5
+
6
+ require 'test/unit/assertions'
7
+ include Test::Unit::Assertions
8
+
9
+ require File.dirname(__FILE__) + '/../../lib/cuke_modeler'
10
+
11
+
12
+ Before do
13
+ @default_file_directory = "#{File.dirname(__FILE__)}/../temp_files"
14
+ @default_feature_file_name = 'test_feature.feature'
15
+ @default_step_file_name = 'test_steps.rb'
16
+ @test_file_directory = "#{File.dirname(__FILE__)}/../test_files"
17
+ @test_step_file_location = "#{@default_file_directory}/#{@default_step_file_name}"
18
+ @spec_directory = "#{File.dirname(__FILE__)}/../../spec"
19
+
20
+ FileUtils.mkdir(@default_file_directory)
21
+ end
22
+
23
+ After do
24
+ FileUtils.remove_dir(@default_file_directory, true)
25
+ end
26
+
27
+
@@ -0,0 +1,3 @@
1
+ Transform /^(-?\d+)$/ do |number|
2
+ number.to_i
3
+ end
@@ -0,0 +1,29 @@
1
+ require "cuke_modeler/version"
2
+
3
+ require 'cuke_modeler/parsing'
4
+ require 'cuke_modeler/containing'
5
+ require 'cuke_modeler/taggable'
6
+ require 'cuke_modeler/raw'
7
+ require 'cuke_modeler/sourceable'
8
+ require 'cuke_modeler/nested'
9
+ require 'cuke_modeler/feature_file'
10
+ require 'cuke_modeler/directory'
11
+ require 'cuke_modeler/feature_element.rb'
12
+ require 'cuke_modeler/feature'
13
+ require 'cuke_modeler/test_element.rb'
14
+ require 'cuke_modeler/background'
15
+ require 'cuke_modeler/scenario'
16
+ require 'cuke_modeler/outline'
17
+ require 'cuke_modeler/example'
18
+ require 'cuke_modeler/step'
19
+ require 'cuke_modeler/doc_string'
20
+ require 'cuke_modeler/table'
21
+ require 'cuke_modeler/world'
22
+ require 'cuke_modeler/row'
23
+ require 'cuke_modeler/table_row'
24
+ require 'cuke_modeler/tag'
25
+
26
+
27
+ module CukeModeler
28
+ # Your code goes here...
29
+ end
@@ -0,0 +1,38 @@
1
+ module CukeModeler
2
+
3
+ # A class modeling a Cucumber feature's Background.
4
+
5
+ class Background < TestElement
6
+
7
+ # Creates a new Background object and, if *source* is provided, populates
8
+ # the object.
9
+ def initialize(source = nil)
10
+ parsed_background = process_source(source)
11
+
12
+ super(parsed_background)
13
+
14
+ build_background(parsed_background) if parsed_background
15
+ end
16
+
17
+ # Returns gherkin representation of the background.
18
+ def to_s
19
+ text = ''
20
+
21
+ text << "Background:#{name_output_string}"
22
+ text << "\n" + description_output_string unless description_text.empty?
23
+ text << "\n" unless steps.empty? || description_text.empty?
24
+ text << "\n" + steps_output_string unless steps.empty?
25
+
26
+ text
27
+ end
28
+
29
+
30
+ private
31
+
32
+
33
+ def build_background(parsed_background)
34
+ # Just a stub in case something specific needs to be done
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,18 @@
1
+ module CukeModeler
2
+
3
+
4
+ module Containing
5
+
6
+
7
+ private
8
+
9
+
10
+ def build_child_element(clazz, element_data)
11
+ element = clazz.new(element_data)
12
+ element.parent_element = self
13
+
14
+ element
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,86 @@
1
+ module CukeModeler
2
+
3
+ # A class modeling a directory containing .feature files.
4
+
5
+ class Directory
6
+
7
+ include Containing
8
+ include Nested
9
+
10
+
11
+ # The FeatureFile objects contained by the Directory
12
+ attr_accessor :feature_files
13
+
14
+ # The Directory objects contained by the Directory
15
+ attr_accessor :directories
16
+
17
+
18
+ # Creates a new Directory object and, if *directory_parsed* is provided,
19
+ # populates the object.
20
+ def initialize(directory_parsed = nil)
21
+ @directory = directory_parsed
22
+
23
+ @feature_files = []
24
+ @directories = []
25
+
26
+ if directory_parsed
27
+ raise(ArgumentError, "Unknown directory: #{directory_parsed.inspect}") unless File.exists?(directory_parsed)
28
+ build_directory
29
+ end
30
+ end
31
+
32
+ # Returns the name of the directory.
33
+ def name
34
+ File.basename(@directory.gsub('\\', '/'))
35
+ end
36
+
37
+ # Returns the path of the directory.
38
+ def path
39
+ @directory
40
+ end
41
+
42
+ # Returns the number of sub-directories contained in the directory.
43
+ def directory_count
44
+ @directories.count
45
+ end
46
+
47
+ # Returns the number of features files contained in the directory.
48
+ def feature_file_count
49
+ @feature_files.count
50
+ end
51
+
52
+ # Returns the immediate child elements of the directory (i.e. its Directory
53
+ # and FeatureFile objects).
54
+ def contains
55
+ @feature_files + @directories
56
+ end
57
+
58
+ # Returns the path of the directory.
59
+ def to_s
60
+ path.to_s
61
+ end
62
+
63
+
64
+ private
65
+
66
+
67
+ def build_directory
68
+ entries = Dir.entries(@directory)
69
+ entries.delete '.'
70
+ entries.delete '..'
71
+
72
+ entries.each do |entry|
73
+ entry = "#{@directory}/#{entry}"
74
+
75
+ case
76
+ when File.directory?(entry)
77
+ @directories << build_child_element(Directory, entry)
78
+ when entry =~ /\.feature$/
79
+ @feature_files << build_child_element(FeatureFile, entry)
80
+ end
81
+ end
82
+
83
+ end
84
+
85
+ end
86
+ end