Skip to content
This repository

Expose names of AST elements in Before hook (Legacy API) #431

Merged
merged 7 commits into from about 1 year ago

3 participants

Matt Wynne Myron Marston Oleg Sukhodolsky
Matt Wynne
Owner

This is to allow us to release Cucumber 1.3 and keep backwards compatability with
an undocumented but widely-used API.

It will be replaced by #430 when v2.0 is released.

added some commits April 08, 2013
Matt Wynne Add a failing feature describing suggested solution 453c0b1
Matt Wynne Add a failing test to document current API ddc6115
Matt Wynne Correct feature 1dc6b36
Matt Wynne Correct test 22c8d10
Matt Wynne Set reference to parent feature on scenario.
This is annoying. I want to remove the circular dependency and have the
child nodes unaware of their parent, but right now we have people who
depend on this behaviour, so I'm putting it back in.
1e71d78
Matt Wynne Sigh 0fd7654
Matt Wynne
Owner

@fidothe @myronmarston I'm hoping these changes will prevent vcr/vcr#288 from regressing when we release Cucumber 1.3

Can you just read over the change and let me know if it looks OK to you?

Myron Marston

Looks fine to me. As far as I can tell, that specifies the API VCR has been using perfectly.

Thanks, Matt!

Oleg Sukhodolsky
Collaborator

@mattwynne do you want to add something to this PR or it should be merged?

Matt Wynne
Owner
Oleg Sukhodolsky os97673 merged commit d210e54 into from April 10, 2013
Oleg Sukhodolsky os97673 closed this April 10, 2013
Oleg Sukhodolsky os97673 deleted the branch April 10, 2013
Oleg Sukhodolsky
Collaborator

merged and the branch deleted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 7 unique commits by 2 authors.

Apr 08, 2013
Matt Wynne Add a failing feature describing suggested solution 453c0b1
Matt Wynne Add a failing test to document current API ddc6115
Matt Wynne Correct feature 1dc6b36
Apr 09, 2013
Matt Wynne Correct test 22c8d10
Matt Wynne Set reference to parent feature on scenario.
This is annoying. I want to remove the circular dependency and have the
child nodes unaware of their parent, but right now we have people who
depend on this behaviour, so I'm putting it back in.
1e71d78
Matt Wynne Sigh 0fd7654
Apr 10, 2013
Oleg Sukhodolsky The latest capybara is not compatible with 1.8.7 cec3c64
This page is out of date. Refresh to see the latest.
2  cucumber.gemspec
@@ -33,7 +33,7 @@ Gem::Specification.new do |s|
33 33
   s.add_development_dependency 'yard', '~> 0.8.0'
34 34
 
35 35
   # Needed for examples (rake examples)
36  
-  s.add_development_dependency 'capybara', '>= 1.1.2'
  36
+  s.add_development_dependency 'capybara', '>= 1.1.2', '< 2.1'
37 37
   s.add_development_dependency 'rack-test', '>= 0.6.1'
38 38
   s.add_development_dependency 'ramaze'
39 39
   s.add_development_dependency 'sinatra', '>= 1.3.2'
79  features/.cucumber/stepdefs.json
@@ -29,11 +29,20 @@
29 29
     "file_colon_line": "aruba-0.5.1/lib/aruba/cucumber.rb:19",
30 30
     "steps": [
31 31
       {
32  
-        "name": "a file named \"cucumber.yml\" with:",
  32
+        "name": "a file named \"features/foo.feature\" with:",
33 33
         "args": [
34 34
           {
35 35
             "offset": 14,
36  
-            "val": "cucumber.yml"
  36
+            "val": "features/foo.feature"
  37
+          }
  38
+        ]
  39
+      },
  40
+      {
  41
+        "name": "a file named \"features/support/hook.rb\" with:",
  42
+        "args": [
  43
+          {
  44
+            "offset": 14,
  45
+            "val": "features/support/hook.rb"
37 46
           }
38 47
         ]
39 48
       }
@@ -116,7 +125,15 @@
116 125
     "flags": "",
117 126
     "file_colon_line": "aruba-0.5.1/lib/aruba/cucumber.rb:60",
118 127
     "steps": [
119  
-
  128
+      {
  129
+        "name": "I run `cucumber`",
  130
+        "args": [
  131
+          {
  132
+            "offset": 7,
  133
+            "val": "cucumber"
  134
+          }
  135
+        ]
  136
+      }
120 137
     ]
121 138
   },
122 139
   {
@@ -217,12 +234,7 @@
217 234
     "flags": "",
218 235
     "file_colon_line": "aruba-0.5.1/lib/aruba/cucumber.rb:117",
219 236
     "steps": [
220  
-      {
221  
-        "name": "the output should not contain:",
222  
-        "args": [
223 237
 
224  
-        ]
225  
-      }
226 238
     ]
227 239
   },
228 240
   {
@@ -534,51 +546,7 @@
534 546
     "flags": "",
535 547
     "file_colon_line": "features/step_definitions/cucumber_steps.rb:1",
536 548
     "steps": [
537  
-      {
538  
-        "name": "I run cucumber \"--profile default --format html\"",
539  
-        "args": [
540  
-          {
541  
-            "offset": 16,
542  
-            "val": "--profile default --format html"
543  
-          }
544  
-        ]
545  
-      },
546  
-      {
547  
-        "name": "I run cucumber \"--profile default --format pretty\"",
548  
-        "args": [
549  
-          {
550  
-            "offset": 16,
551  
-            "val": "--profile default --format pretty"
552  
-          }
553  
-        ]
554  
-      },
555  
-      {
556  
-        "name": "I run cucumber \"--profile default --format progress\"",
557  
-        "args": [
558  
-          {
559  
-            "offset": 16,
560  
-            "val": "--profile default --format progress"
561  
-          }
562  
-        ]
563  
-      },
564  
-      {
565  
-        "name": "I run cucumber \"features/scenario_outline_with_undefined_steps.feature --format pretty --expand \"",
566  
-        "args": [
567  
-          {
568  
-            "offset": 16,
569  
-            "val": "features/scenario_outline_with_undefined_steps.feature --format pretty --expand "
570  
-          }
571  
-        ]
572  
-      },
573  
-      {
574  
-        "name": "I run cucumber \"features/scenario_outline_with_undefined_steps.feature --format progress --expand \"",
575  
-        "args": [
576  
-          {
577  
-            "offset": 16,
578  
-            "val": "features/scenario_outline_with_undefined_steps.feature --format progress --expand "
579  
-          }
580  
-        ]
581  
-      }
  549
+
582 550
     ]
583 551
   },
584 552
   {
@@ -586,12 +554,7 @@
586 554
     "flags": "",
587 555
     "file_colon_line": "features/step_definitions/cucumber_steps.rb:5",
588 556
     "steps": [
589  
-      {
590  
-        "name": "it should pass",
591  
-        "args": [
592 557
 
593  
-        ]
594  
-      }
595 558
     ]
596 559
   },
597 560
   {
40  features/before_hook.feature
... ...
@@ -0,0 +1,40 @@
  1
+Feature: Before Hook
  2
+
  3
+  Scenario: Examine names of elements
  4
+    Given a file named "features/foo.feature" with:
  5
+      """
  6
+      Feature: Feature name
  7
+
  8
+        Scenario: Scenario name
  9
+          Given a step
  10
+
  11
+        Scenario Outline: Scenario Outline name
  12
+          Given a <placeholder>
  13
+
  14
+          Examples: Examples Table name
  15
+            | <placeholder> |
  16
+            | step          |
  17
+      """
  18
+    And a file named "features/support/hook.rb" with:
  19
+      """
  20
+      names = []
  21
+      Before do |scenario|
  22
+        unless scenario.respond_to?(:scenario_outline)
  23
+          names << scenario.feature.name.split("\n").first
  24
+          names << scenario.name.split("\n").first
  25
+        else
  26
+          names << scenario.scenario_outline.feature.name.split("\n").first
  27
+          names << scenario.scenario_outline.name.split("\n").first
  28
+        end
  29
+      end
  30
+      at_exit { puts names.join("\n") }
  31
+      """
  32
+    When I run `cucumber`
  33
+    Then the output should contain:
  34
+      """
  35
+      Feature name
  36
+      Scenario name
  37
+      Feature name
  38
+      Scenario Outline name
  39
+      """
  40
+
1  lib/cucumber/ast/feature.rb
@@ -16,6 +16,7 @@ def initialize(location, background, comment, tags, keyword, title, description,
16 16
         @background, @comment, @tags, @keyword, @title, @description, @feature_elements = background, comment, tags, keyword, title, description, feature_elements
17 17
         @background.feature = self
18 18
         @location = location
  19
+        @feature_elements.each { |e| e.feature = self }
19 20
       end
20 21
 
21 22
       attr_reader :gherkin_statement
3  lib/cucumber/ast/scenario.rb
@@ -11,7 +11,8 @@ class Scenario #:nodoc:
11 11
       include Names
12 12
       include HasLocation
13 13
 
14  
-      attr_reader :feature_tags
  14
+      attr_reader   :feature_tags
  15
+      attr_accessor :feature
15 16
 
16 17
       def initialize(language, location, background, comment, tags, feature_tags, keyword, title, description, raw_steps)
17 18
         @language, @location, @background, @comment, @tags, @feature_tags, @keyword, @title, @description, @raw_steps = language, location, background, comment, tags, feature_tags, keyword, title, description, raw_steps
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.