yard-nrser-cucumber 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +61 -0
  3. data/.rspec +3 -0
  4. data/.yardopts +2 -0
  5. data/Gemfile +6 -0
  6. data/History.txt +288 -0
  7. data/LICENSE.txt +22 -0
  8. data/NAME +1 -0
  9. data/README.md +198 -0
  10. data/Rakefile +27 -0
  11. data/VERSION +1 -0
  12. data/example/README.md +8 -0
  13. data/example/child_feature/README.md +21 -0
  14. data/example/child_feature/child.feature +11 -0
  15. data/example/child_feature/grandchild_feature/grandchild.feature +12 -0
  16. data/example/empty.feature +2 -0
  17. data/example/french.feature +18 -0
  18. data/example/scenario.feature +63 -0
  19. data/example/scenario_outline.feature +100 -0
  20. data/example/scenario_outline_multi.feature +15 -0
  21. data/example/step_definitions/example.step.rb +122 -0
  22. data/example/step_definitions/first.step.rb +21 -0
  23. data/example/step_definitions/french_steps.rb +32 -0
  24. data/example/step_definitions/struct.rb +11 -0
  25. data/example/step_definitions/support/env.rb +7 -0
  26. data/example/step_definitions/support/env_support.rb +12 -0
  27. data/example/step_definitions/support/support.rb +6 -0
  28. data/example/tags.feature +18 -0
  29. data/example/transform.feature +18 -0
  30. data/lib/cucumber/city_builder.rb +412 -0
  31. data/lib/docserver/default/fulldoc/html/js/cucumber.js +85 -0
  32. data/lib/docserver/default/layout/html/headers.erb +13 -0
  33. data/lib/docserver/doc_server/full_list/html/full_list.erb +39 -0
  34. data/lib/docserver/doc_server/full_list/html/setup.rb +18 -0
  35. data/lib/templates/default/feature/html/feature.erb +39 -0
  36. data/lib/templates/default/feature/html/no_steps_defined.erb +1 -0
  37. data/lib/templates/default/feature/html/outline.erb +56 -0
  38. data/lib/templates/default/feature/html/pystring.erb +3 -0
  39. data/lib/templates/default/feature/html/scenario.erb +57 -0
  40. data/lib/templates/default/feature/html/setup.rb +51 -0
  41. data/lib/templates/default/feature/html/steps.erb +39 -0
  42. data/lib/templates/default/feature/html/table.erb +20 -0
  43. data/lib/templates/default/featuredirectory/html/alpha_table.erb +30 -0
  44. data/lib/templates/default/featuredirectory/html/directory.erb +32 -0
  45. data/lib/templates/default/featuredirectory/html/setup.rb +37 -0
  46. data/lib/templates/default/featuretags/html/namespace.erb +159 -0
  47. data/lib/templates/default/featuretags/html/setup.rb +34 -0
  48. data/lib/templates/default/fulldoc/html/css/cucumber.css +226 -0
  49. data/lib/templates/default/fulldoc/html/directories.erb +27 -0
  50. data/lib/templates/default/fulldoc/html/full_list_featuredirectories.erb +11 -0
  51. data/lib/templates/default/fulldoc/html/full_list_features.erb +37 -0
  52. data/lib/templates/default/fulldoc/html/full_list_stepdefinitions.erb +20 -0
  53. data/lib/templates/default/fulldoc/html/full_list_steps.erb +20 -0
  54. data/lib/templates/default/fulldoc/html/full_list_tags.erb +16 -0
  55. data/lib/templates/default/fulldoc/html/js/cucumber.js +333 -0
  56. data/lib/templates/default/fulldoc/html/setup.rb +208 -0
  57. data/lib/templates/default/layout/html/setup.rb +131 -0
  58. data/lib/templates/default/requirements/html/alpha_table.erb +26 -0
  59. data/lib/templates/default/requirements/html/requirements.erb +50 -0
  60. data/lib/templates/default/requirements/html/setup.rb +51 -0
  61. data/lib/templates/default/steptransformers/html/header.erb +12 -0
  62. data/lib/templates/default/steptransformers/html/index.erb +10 -0
  63. data/lib/templates/default/steptransformers/html/setup.rb +94 -0
  64. data/lib/templates/default/steptransformers/html/transformers.erb +80 -0
  65. data/lib/templates/default/steptransformers/html/undefinedsteps.erb +26 -0
  66. data/lib/templates/default/tag/html/alpha_table.erb +33 -0
  67. data/lib/templates/default/tag/html/setup.rb +27 -0
  68. data/lib/templates/default/tag/html/tag.erb +35 -0
  69. data/lib/yard-nrser-cucumber.rb +49 -0
  70. data/lib/yard/code_objects/cucumber/base.rb +24 -0
  71. data/lib/yard/code_objects/cucumber/feature.rb +16 -0
  72. data/lib/yard/code_objects/cucumber/namespace_object.rb +55 -0
  73. data/lib/yard/code_objects/cucumber/scenario.rb +25 -0
  74. data/lib/yard/code_objects/cucumber/scenario_outline.rb +68 -0
  75. data/lib/yard/code_objects/cucumber/step.rb +41 -0
  76. data/lib/yard/code_objects/cucumber/tag.rb +31 -0
  77. data/lib/yard/code_objects/step_definition.rb +4 -0
  78. data/lib/yard/code_objects/step_transform.rb +4 -0
  79. data/lib/yard/code_objects/step_transformer.rb +94 -0
  80. data/lib/yard/handlers/constant_transform_handler.rb +98 -0
  81. data/lib/yard/handlers/cucumber/base.rb +21 -0
  82. data/lib/yard/handlers/cucumber/feature_handler.rb +131 -0
  83. data/lib/yard/handlers/legacy/step_definition_handler.rb +45 -0
  84. data/lib/yard/handlers/legacy/step_transform_handler.rb +24 -0
  85. data/lib/yard/handlers/step_definition_handler.rb +86 -0
  86. data/lib/yard/handlers/step_transform_handler.rb +50 -0
  87. data/lib/yard/nrser/cucumber/version.rb +103 -0
  88. data/lib/yard/parser/cucumber/feature.rb +72 -0
  89. data/lib/yard/server/adapter.rb +43 -0
  90. data/lib/yard/server/commands/list_command.rb +31 -0
  91. data/lib/yard/server/router.rb +32 -0
  92. data/lib/yard/templates/helpers/base_helper.rb +26 -0
  93. data/lib/yard/templates/helpers/html_helper.rb +153 -0
  94. data/yard-nrser-cucumber.gemspec +75 -0
  95. metadata +220 -0
@@ -0,0 +1,45 @@
1
+ class YARD::Handlers::Ruby::Legacy::StepDefinitionHandler < YARD::Handlers::Ruby::Legacy::Base
2
+ STEP_DEFINITION_MATCH = /^((When|Given|And|Then)\s*(\/.+\/)\s+do(?:\s*\|.+\|)?\s*)$/ unless defined?(STEP_DEFINITION_MATCH)
3
+ handles STEP_DEFINITION_MATCH
4
+
5
+ @@unique_name = 0
6
+
7
+ def process
8
+ keyword = statement.tokens.to_s[STEP_DEFINITION_MATCH,2]
9
+ step_definition = statement.tokens.to_s[STEP_DEFINITION_MATCH,3]
10
+
11
+ @@unique_name = @@unique_name + 1
12
+
13
+ stepdef_instance = StepDefinitionObject.new(YARD::CodeObjects::Cucumber::CUCUMBER_STEPTRANSFORM_NAMESPACE, "definition_#{@@unique_name}") do |o|
14
+ o.source = "#{keyword} #{step_definition} do #{statement.block.to_s =~ /^\s*\|.+/ ? '' : "\n "}#{statement.block.to_s}\nend"
15
+ o.value = step_definition
16
+ o.keyword = keyword
17
+ end
18
+
19
+ obj = register stepdef_instance
20
+ parse_block :owner => obj
21
+
22
+ rescue YARD::Handlers::NamespaceMissingError
23
+ end
24
+
25
+ #
26
+ # Step Definitions can contain defined steps within them. While it is likely that they could not
27
+ # very easily be parsed because of variables that are only calculated at runtime, it would be nice
28
+ # to at least list those in use within a step definition and if you can find a match, go ahead and
29
+ # make it
30
+ #
31
+ def find_steps_defined_in_block(block)
32
+ #log.debug "#{block} #{block.class}"
33
+ block.each_with_index do |token,index|
34
+ #log.debug "Token #{token.class} #{token.text}"
35
+ if token.is_a?(YARD::Parser::Ruby::Legacy::RubyToken::TkCONSTANT) &&
36
+ token.text =~ /^(given|when|then|and)$/i &&
37
+ block[index + 2].is_a?(YARD::Parser::Ruby::Legacy::RubyToken::TkSTRING)
38
+ log.debug "Step found in Step Definition: #{block[index + 2].text} "
39
+ end
40
+
41
+ end
42
+
43
+ end
44
+
45
+ end
@@ -0,0 +1,24 @@
1
+ class YARD::Handlers::Ruby::Legacy::StepTransformHandler < YARD::Handlers::Ruby::Legacy::Base
2
+ STEP_TRANSFORM_MATCH = /^(Transform\s*(\/.+\/)\s+do(?:\s*\|.+\|)?\s*)$/ unless defined?(STEP_TRANSFORM_MATCH)
3
+ handles STEP_TRANSFORM_MATCH
4
+
5
+ @@unique_name = 0
6
+
7
+ def process
8
+ transform = statement.tokens.to_s[STEP_TRANSFORM_MATCH,2]
9
+ @@unique_name = @@unique_name + 1
10
+
11
+ instance = StepTransformObject.new(YARD::CodeObjects::Cucumber::CUCUMBER_STEPTRANSFORM_NAMESPACE, "transform_#{@@unique_name}") do |o|
12
+ o.source = "Transform #{transform} do #{statement.block.to_s}\nend"
13
+ o.value = transform
14
+ o.keyword = "Transform"
15
+ end
16
+
17
+ obj = register instance
18
+ parse_block :owner => obj
19
+
20
+ rescue YARD::Handlers::NamespaceMissingError
21
+ end
22
+
23
+ end
24
+
@@ -0,0 +1,86 @@
1
+ #
2
+ # Finds and processes all the step definitions defined in the ruby source
3
+ # code. By default the english gherkin language will be parsed.
4
+ #
5
+ # To override the language you can define the step definitions in the YARD
6
+ # configuration file `~./yard/config`:
7
+ #
8
+ # @example `~/.yard/config` with LOLCatz step definitions
9
+ #
10
+ # :"yard-cucumber":
11
+ # language:
12
+ # step_definitions: [ 'WEN', 'I CAN HAZ', 'AN', 'DEN' ]
13
+ #
14
+ # @example `~/.yard/config` with French step definitions
15
+ #
16
+ # :"yard-cucumber":
17
+ # language:
18
+ # step_definitions: [ 'Soit', 'Etantdonné', 'Lorsque', 'Lorsqu', 'Alors', 'Et' ]
19
+ #
20
+ class YARD::Handlers::Ruby::StepDefinitionHandler < YARD::Handlers::Ruby::Base
21
+
22
+ def self.default_step_definitions
23
+ [ "When", "Given", "And", "Then" ]
24
+ end
25
+
26
+ def self.custom_step_definitions
27
+ YARD::Config.options["yard-cucumber"]["language"]["step_definitions"]
28
+ end
29
+
30
+ def self.custom_step_definitions_defined?
31
+ YARD::Config.options["yard-cucumber"] and
32
+ YARD::Config.options["yard-cucumber"]["language"] and
33
+ YARD::Config.options["yard-cucumber"]["language"]["step_definitions"]
34
+ end
35
+
36
+ def self.step_definitions
37
+ if custom_step_definitions_defined?
38
+ custom_step_definitions
39
+ else
40
+ default_step_definitions
41
+ end
42
+ end
43
+
44
+ step_definitions.each { |step_def| handles method_call(step_def) }
45
+
46
+ process do
47
+
48
+ instance = YARD::CodeObjects::StepDefinitionObject.new(step_transform_namespace,step_definition_name) do |o|
49
+ o.source = statement.source
50
+ o.comments = statement.comments
51
+ o.keyword = statement.method_name.source
52
+ o.value = statement.parameters.source
53
+ o.pending = pending_keyword_used?(statement.block)
54
+ end
55
+
56
+ obj = register instance
57
+ parse_block(statement[2],:owner => obj)
58
+
59
+ end
60
+
61
+ def pending_keyword
62
+ "pending"
63
+ end
64
+
65
+ def pending_command_statement?(line)
66
+ (line.type == :command || line.type == :vcall) && line.first.source == pending_keyword
67
+ end
68
+
69
+ def pending_keyword_used?(block)
70
+ code_in_block = block.last
71
+ code_in_block.find { |line| pending_command_statement?(line) }
72
+ end
73
+
74
+ def step_transform_namespace
75
+ YARD::CodeObjects::Cucumber::CUCUMBER_STEPTRANSFORM_NAMESPACE
76
+ end
77
+
78
+ def step_definition_name
79
+ "step_definition#{self.class.generate_unique_id}"
80
+ end
81
+
82
+ def self.generate_unique_id
83
+ @step_definition_count = @step_definition_count.to_i + 1
84
+ end
85
+
86
+ end
@@ -0,0 +1,50 @@
1
+
2
+ class YARD::Handlers::Ruby::StepTransformHandler < YARD::Handlers::Ruby::Base
3
+ handles method_call(:Transform)
4
+ handles method_call(:ParameterType)
5
+
6
+ process do
7
+
8
+ nextStatement = nil
9
+ instance = YARD::CodeObjects::StepTransformObject.new(step_transform_namespace,step_transformer_name) do |o|
10
+ o.source = statement.source
11
+ o.comments = statement.comments
12
+ o.keyword = statement[0].source
13
+ if (o.keyword == 'Transform')
14
+ o.value = statement[1].source.gsub(/(^\(?\/|\/\)?$)/, '').gsub(/(^\^|\$$)/, '')
15
+ nextStatement = statement[2]
16
+ elsif (o.keyword == 'ParameterType')
17
+ o.value = find(statement, :label, 'regexp:').parent.children[1].source.gsub(/(^\(?\/|\/\)?$)/, '').gsub(/(^\^|\$$)/, '')
18
+ nextStatement = find(statement, :label, 'transformer:').parent.children[1]
19
+ end
20
+ end
21
+
22
+ obj = register instance
23
+ parse_block(nextStatement,:owner => obj)
24
+
25
+ end
26
+
27
+ def step_transform_namespace
28
+ YARD::CodeObjects::Cucumber::CUCUMBER_STEPTRANSFORM_NAMESPACE
29
+ end
30
+
31
+ def step_transformer_name
32
+ # If the owner is a constant then we get the name of the constant so that the reference from the constant will work
33
+ if (owner.is_a?(YARD::CodeObjects::ConstantObject))
34
+ owner.name
35
+ else
36
+ "step_transform#{self.class.generate_unique_id}"
37
+ end
38
+ end
39
+
40
+ def self.generate_unique_id
41
+ @step_transformer_count = @step_transformer_count.to_i + 1
42
+ end
43
+
44
+ private
45
+
46
+ def find(node, node_type, value)
47
+ node.traverse { |child| return(child) if node_type == child.type && child.source == value }
48
+ self
49
+ end
50
+ end
@@ -0,0 +1,103 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+ ##############################################################################
5
+ #
6
+ # This file is special - it should not have any dependencies outside the
7
+ # stdlib. It should be loadable without dependencies or paths or bundler
8
+ # or anything in place.
9
+ #
10
+ # This makes it easy for things that are not at all connected to this package
11
+ # or it's environment or whatever to load it up and get some basic info about
12
+ # what's going on.
13
+ #
14
+ ##############################################################################
15
+
16
+ # Requirements (Stdlib Only!)
17
+ # =======================================================================
18
+
19
+ require 'pathname'
20
+ require 'singleton'
21
+
22
+
23
+ # Namespace
24
+ # =======================================================================
25
+
26
+ module YARD
27
+ module NRSER
28
+ module Cucumber
29
+
30
+
31
+ # Definitions
32
+ # =======================================================================
33
+
34
+ # Absolute, expanded path to the gem's root directory.
35
+ #
36
+ # @return [Pathname]
37
+ #
38
+ ROOT = Pathname.new( __dir__ ).join( '..', '..', '..', '..' ).expand_path
39
+
40
+
41
+ # String version read from `//VERSION` and used in the gemspec.
42
+ #
43
+ # @return [String]
44
+ #
45
+ VERSION = (ROOT + 'VERSION').read.chomp
46
+
47
+
48
+ # The gem name, read from the `//NAME` file, and used in the gemspec.
49
+ #
50
+ # @return [String]
51
+ #
52
+ NAME = (ROOT + 'NAME').read.chomp
53
+
54
+
55
+ def self.repo?
56
+ ROOT.join( 'dev' ).directory?
57
+ end
58
+
59
+ # {Singleton} extension of {Gem::Version} that loads {Locd::VERSION} and
60
+ # provides some convenient methods.
61
+ #
62
+ class Version < Gem::Version
63
+ include ::Singleton
64
+
65
+ # Private method to instantiate the {#instance} using the {Locd::VERSION}
66
+ # {String}.
67
+ #
68
+ # @return [Version]
69
+ #
70
+ def self.new
71
+ super VERSION
72
+ end
73
+
74
+ # We need to mark {.new} as private to dissuade construction of additional
75
+ # instances.
76
+ private_class_method :new
77
+
78
+ # Proxies to the {#instance}'s {#dev?}.
79
+ #
80
+ # @return (see #dev?)
81
+ #
82
+ def self.dev?
83
+ instance.dev?
84
+ end
85
+
86
+ # Tests if the package's version is a development pre-release.
87
+ #
88
+ # @return [Boolean]
89
+ # `true` if this is a development pre-release.
90
+ #
91
+ def dev?
92
+ segments[3] == 'dev'
93
+ end
94
+
95
+ end # module Version
96
+
97
+
98
+ # /Namespace
99
+ # =======================================================================
100
+
101
+ end # module Cucumber
102
+ end # module NRSER
103
+ end # module YARD
@@ -0,0 +1,72 @@
1
+ module YARD::Parser::Cucumber
2
+
3
+ class FeatureParser < YARD::Parser::Base
4
+
5
+ #
6
+ # Each found feature found is creates a new FeatureParser
7
+ #
8
+ # This logic was copied from the logic found in Cucumber to create the builder
9
+ # and then set up the formatter and parser. The difference is really the
10
+ # custom Cucumber::Parser::CityBuilder that is being used to parse the elements
11
+ # of the feature into YARD::CodeObjects.
12
+ #
13
+ # @param [<String>] source containing the string conents of the feauture file
14
+ # @param [<String>] file the filename that contains the source
15
+ #
16
+ def initialize(source, file = '(stdin)')
17
+
18
+ @builder = Cucumber::Parser::CityBuilder.new(file)
19
+ @tag_counts = {}
20
+ @parser = Gherkin::Parser.new(@builder)
21
+
22
+ @source = source
23
+ @file = file
24
+
25
+ @feature = nil
26
+ end
27
+
28
+ #
29
+ # When parse is called, the gherkin parser is executed and all the feature
30
+ # elements that are found are sent to the various methods in the
31
+ # Cucumber::Parser::CityBuilder. The result of which is the feature element
32
+ # that contains all the scenarios, steps, etc. associated with that feature.
33
+ #
34
+ # @see Cucumber::Parser::CityBuilder
35
+ def parse
36
+ begin
37
+ @parser.parse(@source)
38
+ @feature = @builder.ast
39
+ return nil if @feature.nil? # Nothing matched
40
+
41
+ # The parser used the following keywords when parsing the feature
42
+ # @feature.language = @parser.i18n_language.get_code_keywords.map {|word| word }
43
+
44
+ rescue Gherkin::ParserError => e
45
+ e.message.insert(0, "#{@file}: ")
46
+ warn e
47
+ end
48
+
49
+ self
50
+ end
51
+
52
+ #
53
+ # This is not used as all the work is done in the parse method
54
+ #
55
+ def tokenize
56
+
57
+ end
58
+
59
+ #
60
+ # The only enumeration that can be done here is returning the feature itself
61
+ #
62
+ def enumerator
63
+ [@feature]
64
+ end
65
+
66
+ end
67
+
68
+ #
69
+ # Register all feature files (.feature) to be processed with the above FeatureParser
70
+ YARD::Parser::SourceParser.register_parser_type :feature, FeatureParser, 'feature'
71
+
72
+ end
@@ -0,0 +1,43 @@
1
+ module YARD
2
+ module Server
3
+
4
+ class Adapter
5
+
6
+ class << self
7
+
8
+ alias_method :yard_setup, :setup
9
+
10
+ #
11
+ # To provide the templates necessary for `yard-cucumber` to integrate
12
+ # with YARD the adapter has to around-alias the setup method to place
13
+ # the `yard-cucumber` server templates as the last template in the list.
14
+ #
15
+ # When they are normally loaded with the plugin they cause an error with
16
+ # the `yardoc` command. They are also not used because the YARD server
17
+ # templates are placed after all plugin templates.
18
+ #
19
+ def setup
20
+ yard_setup
21
+ YARD::Templates::Engine.template_paths +=
22
+ [File.dirname(__FILE__) + '/../../templates',File.dirname(__FILE__) + '/../../docserver']
23
+ end
24
+
25
+ alias_method :yard_shutdown, :shutdown
26
+
27
+ #
28
+ # Similar to the addition, it is good business to tear down the templates
29
+ # that were added by again around-aliasing the shutdown method.
30
+ #
31
+ def shutdown
32
+ yard_shutdown
33
+ YARD::Templates::Engine.template_paths -=
34
+ [File.dirname(__FILE__) + '/../../templates',File.dirname(__FILE__) + '/../../docserver']
35
+ end
36
+
37
+ end
38
+
39
+
40
+ end
41
+
42
+ end
43
+ end
@@ -0,0 +1,31 @@
1
+ module YARD
2
+ module Server
3
+ module Commands
4
+
5
+ #
6
+ # List Features powers the features menu option in `yard server`
7
+ #
8
+ class ListFeaturesCommand < ListCommand
9
+ def type; :features end
10
+
11
+ def items
12
+ Registry.load_all
13
+ run_verifier(Registry.all(:feature))
14
+ end
15
+ end
16
+
17
+ #
18
+ # List Tags powers the tags menu option in `yard server`
19
+ #
20
+ class ListTagsCommand < ListCommand
21
+ def type; :tags end
22
+
23
+ def items
24
+ Registry.load_all
25
+ run_verifier(Registry.all(:tag).sort_by {|t| t.value.to_s })
26
+ end
27
+ end
28
+
29
+ end
30
+ end
31
+ end