lucid 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.md CHANGED
@@ -2,6 +2,19 @@ Change Log and History
2
2
  ======================
3
3
 
4
4
 
5
+ Version 0.0.7 / 2013-05-17
6
+ --------------------------
7
+
8
+ This version mainly makes a lot of internal changes and many of those are predicated upon keeping pace with the changes that Cucumber is making as they move to their 2.0 release.
9
+
10
+ Two specific changes worth calling out:
11
+
12
+ * Lucid will now let you reliably configure a library path.
13
+ * Lucid will allow you to configure the name of the driver file. (This was due to a [planned enhancement[(https://github.com/jnyman/lucid/issues/2)].)
14
+
15
+ The driver file in Cucumber is env.rb. In Lucid this defaults to driver.rb. Now, however, you can override that default. Regarding the library path, this is equivalent to what Cucumber refers to as the "support" directory. The main reason for these changes is that Lucid is trying to be a little more configurable than Cucumber.
16
+
17
+
5
18
  Version 0.0.6 / 2013-05-09
6
19
  --------------------------
7
20
 
data/lib/lucid/ast.rb CHANGED
@@ -7,6 +7,7 @@ require 'lucid/ast/scenario_outline'
7
7
  require 'lucid/ast/step_invocation'
8
8
  require 'lucid/ast/step_collection'
9
9
  require 'lucid/ast/step'
10
+ require 'lucid/ast/step_result'
10
11
  require 'lucid/ast/table'
11
12
  require 'lucid/ast/tags'
12
13
  require 'lucid/ast/doc_string'
@@ -9,6 +9,7 @@ module Lucid
9
9
  include Names
10
10
  include HasLocation
11
11
  attr_accessor :feature
12
+ attr_accessor :comment
12
13
 
13
14
  def initialize(language, location, comment, keyword, title, description, raw_steps)
14
15
  @language, @location, @comment, @keyword, @title, @description, @raw_steps = language, location, comment, keyword, title, description, raw_steps
@@ -36,14 +37,16 @@ module Lucid
36
37
 
37
38
  def accept(visitor)
38
39
  return if Lucid.wants_to_quit
39
- visitor.visit_comment(@comment) unless @comment.empty?
40
- visitor.visit_background_name(@keyword, name, file_colon_line, source_indent(first_line_length))
41
- with_visitor(hook_context, visitor) do
42
- visitor.runtime.before(hook_context)
43
- skip_invoke! if failed?
44
- visitor.visit_steps(step_invocations)
45
- @failed = step_invocations.any? { |step_invocation| step_invocation.exception || step_invocation.status != :passed }
46
- visitor.runtime.after(hook_context) if @failed || feature_elements.empty?
40
+ visitor.visit_background(self) do
41
+ comment.accept(visitor)
42
+ visitor.visit_background_name(@keyword, name, file_colon_line, source_indent(first_line_length))
43
+ with_visitor(hook_context, visitor) do
44
+ visitor.runtime.before(hook_context)
45
+ skip_invoke! if failed?
46
+ step_invocations.accept(visitor)
47
+ @failed = step_invocations.any? { |step_invocation| step_invocation.exception || step_invocation.status != :passed }
48
+ visitor.runtime.after(hook_context) if @failed || feature_elements.empty?
49
+ end
47
50
  end
48
51
  end
49
52
 
@@ -11,8 +11,12 @@ module Lucid
11
11
 
12
12
  def accept(visitor)
13
13
  return if Lucid.wants_to_quit
14
- @value.strip.split("\n").each do |line|
15
- visitor.visit_comment_line(line.strip)
14
+ return if empty?
15
+
16
+ visitor.visit_comment(self) do
17
+ @value.strip.split("\n").each do |line|
18
+ visitor.visit_comment_line(line.strip)
19
+ end
16
20
  end
17
21
  end
18
22
 
@@ -6,6 +6,7 @@ module Lucid
6
6
  include Names
7
7
  include HasLocation
8
8
  attr_writer :outline_table
9
+ attr_reader :comment, :keyword, :outline_table
9
10
 
10
11
  def initialize(location, comment, keyword, title, description, outline_table)
11
12
  @location, @comment, @keyword, @title, @description, @outline_table = location, comment, keyword, title, description, outline_table
@@ -20,9 +21,12 @@ module Lucid
20
21
 
21
22
  def accept(visitor)
22
23
  return if Lucid.wants_to_quit
23
- visitor.visit_comment(@comment) unless @comment.empty?
24
- visitor.visit_examples_name(@keyword, name)
25
- visitor.visit_outline_table(@outline_table)
24
+
25
+ visitor.visit_examples(self) do
26
+ comment.accept(visitor)
27
+ visitor.visit_examples_name(keyword, name)
28
+ outline_table.accept(visitor)
29
+ end
26
30
  end
27
31
 
28
32
  def skip_invoke!
@@ -39,7 +43,7 @@ module Lucid
39
43
 
40
44
  def to_sexp
41
45
  sexp = [:examples, @keyword, name]
42
- comment = @comment.to_sexp
46
+ comment = comment.to_sexp
43
47
  sexp += [comment] if comment
44
48
  sexp += [@outline_table.to_sexp]
45
49
  sexp
@@ -11,6 +11,7 @@ module Lucid
11
11
 
12
12
  attr_accessor :language
13
13
  attr_reader :feature_elements
14
+ attr_reader :comment, :background, :tags
14
15
 
15
16
  def initialize(location, background, comment, tags, keyword, title, description, feature_elements)
16
17
  @background, @comment, @tags, @keyword, @title, @description, @feature_elements = background, comment, tags, keyword, title, description, feature_elements
@@ -30,12 +31,14 @@ module Lucid
30
31
 
31
32
  def accept(visitor)
32
33
  return if Lucid.wants_to_quit
33
- visitor.visit_comment(@comment) unless @comment.empty?
34
- visitor.visit_tags(@tags)
35
- visitor.visit_feature_name(@keyword, indented_name)
36
- visitor.visit_background(@background) if !@background.is_a?(EmptyBackground)
37
- @feature_elements.each do |feature_element|
38
- visitor.visit_feature_element(feature_element)
34
+ visitor.visit_feature(self) do
35
+ comment.accept(visitor)
36
+ tags.accept(visitor)
37
+ visitor.visit_feature_name(@keyword, indented_name)
38
+ background.accept(visitor)
39
+ @feature_elements.each do |feature_element|
40
+ feature_element.accept(visitor)
41
+ end
39
42
  end
40
43
  end
41
44
 
@@ -5,26 +5,16 @@ module Lucid
5
5
  super(raw)
6
6
  @scenario_outline = scenario_outline
7
7
  @cells_class = ExampleRow
8
- init
9
- end
10
-
11
- def init
12
- create_step_invocations_for_example_rows!(@scenario_outline)
13
- end
14
-
15
- def to_sexp
16
- init
17
- super
8
+ example_rows.each do |cells|
9
+ cells.create_step_invocations!(scenario_outline)
10
+ end
18
11
  end
19
12
 
20
13
  def accept(visitor)
21
14
  return if Lucid.wants_to_quit
22
- init
23
- cells_rows.each_with_index do |row, n|
24
- if(visitor.configuration.expand?)
15
+ visitor.visit_outline_table(self) do
16
+ cells_rows.each do |row|
25
17
  row.accept(visitor)
26
- else
27
- visitor.visit_table_row(row)
28
18
  end
29
19
  end
30
20
  nil
@@ -43,20 +33,11 @@ module Lucid
43
33
  end
44
34
 
45
35
  def skip_invoke!
46
- init
47
36
  example_rows.each do |cells|
48
37
  cells.skip_invoke!
49
38
  end
50
39
  end
51
40
 
52
- def create_step_invocations_for_example_rows!(scenario_outline)
53
- return if @dunit
54
- @dunit = true
55
- example_rows.each do |cells|
56
- cells.create_step_invocations!(scenario_outline)
57
- end
58
- end
59
-
60
41
  def example_rows
61
42
  cells_rows[1..-1]
62
43
  end
@@ -104,14 +85,21 @@ module Lucid
104
85
 
105
86
  def accept(visitor)
106
87
  return if Lucid.wants_to_quit
107
- visitor.configuration.expand? ? accept_expand(visitor) : accept_plain(visitor)
88
+ #visitor.configuration.expand? ? accept_expand(visitor) : accept_plain(visitor)
89
+ if visitor.configuration.expand?
90
+ accept_expand(visitor)
91
+ else
92
+ visitor.visit_table_row(self) do
93
+ accept_plain(visitor)
94
+ end
95
+ end
108
96
  end
109
97
 
110
98
  def accept_plain(visitor)
111
99
  if header?
112
100
  @cells.each do |cell|
113
101
  cell.status = :skipped_param
114
- visitor.visit_table_cell(cell)
102
+ cell.accept(visitor)
115
103
  end
116
104
  else
117
105
  visitor.runtime.with_hooks(self) do
@@ -121,7 +109,7 @@ module Lucid
121
109
  end
122
110
 
123
111
  @cells.each do |cell|
124
- visitor.visit_table_cell(cell)
112
+ cell.accept(visitor)
125
113
  end
126
114
 
127
115
  visitor.visit_exception(@scenario_exception, :failed) if @scenario_exception
@@ -130,14 +118,12 @@ module Lucid
130
118
  end
131
119
 
132
120
  def accept_expand(visitor)
133
- if header?
134
- else
135
- visitor.runtime.with_hooks(self) do
136
- @table.visit_scenario_name(visitor, self)
137
- @step_invocations.each do |step_invocation|
138
- visitor.visit_step(step_invocation)
139
- @exception ||= step_invocation.reported_exception
140
- end
121
+ return if header?
122
+ visitor.runtime.with_hooks(self) do
123
+ @table.visit_scenario_name(visitor, self)
124
+ @step_invocations.each do |step_invocation|
125
+ step_invocation.accept(visitor)
126
+ @exception ||= step_invocation.reported_exception
141
127
  end
142
128
  end
143
129
  end
@@ -13,6 +13,7 @@ module Lucid
13
13
 
14
14
  attr_reader :feature_tags
15
15
  attr_accessor :feature
16
+ attr_reader :comment, :tags, :keyword
16
17
 
17
18
  def initialize(language, location, background, comment, tags, feature_tags, keyword, title, description, raw_steps)
18
19
  @language, @location, @background, @comment, @tags, @feature_tags, @keyword, @title, @description, @raw_steps = language, location, background, comment, tags, feature_tags, keyword, title, description, raw_steps
@@ -23,15 +24,18 @@ module Lucid
23
24
  def accept(visitor)
24
25
  return if Lucid.wants_to_quit
25
26
 
26
- visitor.visit_comment(@comment) unless @comment.empty?
27
- visitor.visit_tags(@tags)
28
- visitor.visit_scenario_name(@keyword, name, file_colon_line, source_indent(first_line_length))
27
+ visitor.visit_feature_element(self) do
28
+ comment.accept(visitor)
29
+ tags.accept(visitor)
30
+ visitor.visit_scenario_name(keyword, name, file_colon_line, source_indent(first_line_length))
29
31
 
30
- skip_invoke! if @background.failed?
31
- with_visitor(visitor) do
32
- visitor.execute(self, skip_hooks?)
32
+ skip_invoke! if @background.failed?
33
+ with_visitor(visitor) do
34
+ visitor.execute(self, skip_hooks?)
35
+ end
36
+
37
+ @executed = true
33
38
  end
34
- @executed = true
35
39
  end
36
40
 
37
41
  def to_units(background)
@@ -11,12 +11,17 @@ module Lucid
11
11
 
12
12
  attr_accessor :feature
13
13
  attr_reader :feature_tags
14
+ attr_reader :comment, :tags, :keyword
14
15
 
15
16
  module ExamplesArray #:nodoc:
16
17
  def accept(visitor)
17
18
  return if Lucid.wants_to_quit
18
- each do |examples|
19
- visitor.visit_examples(examples)
19
+ return if self.empty?
20
+
21
+ visitor.visit_examples_array(self) do
22
+ each do |examples|
23
+ examples.accept(visitor)
24
+ end
20
25
  end
21
26
  end
22
27
  end
@@ -32,13 +37,15 @@ module Lucid
32
37
  return if Lucid.wants_to_quit
33
38
  raise_missing_examples_error unless @example_sections
34
39
 
35
- visitor.visit_comment(@comment) unless @comment.empty?
36
- visitor.visit_tags(@tags)
37
- visitor.visit_scenario_name(@keyword, name, file_colon_line, source_indent(first_line_length))
38
- visitor.visit_steps(steps)
40
+ visitor.visit_feature_element(self) do
41
+ comment.accept(visitor)
42
+ tags.accept(visitor)
43
+ visitor.visit_scenario_name(keyword, name, file_colon_line, source_indent(first_line_length))
44
+ steps.accept(visitor)
39
45
 
40
- skip_invoke! if @background.failed?
41
- visitor.visit_examples_array(examples_array) unless examples_array.empty?
46
+ skip_invoke! if @background.failed?
47
+ examples_array.accept(visitor)
48
+ end
42
49
  end
43
50
 
44
51
  def to_units(background)
@@ -63,11 +70,7 @@ module Lucid
63
70
 
64
71
  def step_invocations(cells)
65
72
  step_invocations = steps.step_invocations_from_cells(cells)
66
- if @background
67
- @background.step_collection(step_invocations)
68
- else
69
- StepCollection.new(step_invocations)
70
- end
73
+ @background.step_collection(step_invocations)
71
74
  end
72
75
 
73
76
  def each_example_row(&proc)
@@ -23,11 +23,16 @@ module Lucid
23
23
 
24
24
  def accept(visitor)
25
25
  return if Lucid.wants_to_quit
26
- start = Time.now
27
- self.each do |feature|
28
- visitor.visit_feature(feature)
26
+
27
+ visitor.visit_features(self) do
28
+ start = Time.now
29
+
30
+ self.each do |feature|
31
+ feature.accept(visitor)
32
+ end
33
+
34
+ @duration = Time.now - start
29
35
  end
30
- @duration = Time.now - start
31
36
  end
32
37
 
33
38
  def step_count
@@ -50,11 +50,16 @@ module Lucid
50
50
  return if Lucid.wants_to_quit
51
51
  # The only time a Step is visited is when it is in a ScenarioOutline.
52
52
  # Otherwise it's always StepInvocation that gets visited instead.
53
- visit_step_result(visitor, first_match(visitor), @multiline_arg, :skipped, nil, nil)
53
+ visitor.visit_step(self) do
54
+ visit_step_result(visitor, first_match(visitor), @multiline_arg, :skipped, nil, nil)
55
+ end
56
+
54
57
  end
55
58
 
56
59
  def visit_step_result(visitor, step_match, multiline_arg, status, exception, background)
57
- visitor.visit_step_result(keyword, step_match, @multiline_arg, status, exception, source_indent, background, file_colon_line)
60
+ visitor.visit_step_result(
61
+ StepResult.new(keyword, step_match, @multiline_arg, status, exception, source_indent, background, file_colon_line)
62
+ )
58
63
  end
59
64
 
60
65
  def first_match(visitor)
@@ -15,8 +15,12 @@ module Lucid
15
15
 
16
16
  def accept(visitor)
17
17
  return if Lucid.wants_to_quit
18
- @steps.each do |step|
19
- visitor.visit_step(step)
18
+
19
+ visitor.visit_steps(self) do
20
+ @steps.each do |step|
21
+ #visitor.visit_step(step)
22
+ step.accept(visitor)
23
+ end
20
24
  end
21
25
  end
22
26
 
@@ -6,8 +6,6 @@ require 'gherkin/rubify'
6
6
  module Lucid
7
7
  module AST
8
8
  class StepInvocation #:nodoc:
9
- include Gherkin::Rubify
10
-
11
9
  attr_writer :step_collection, :background
12
10
  attr_reader :name, :matched_cells, :status, :reported_exception
13
11
  attr_accessor :exception
@@ -35,20 +33,25 @@ module Lucid
35
33
 
36
34
  def accept(visitor)
37
35
  return if Lucid.wants_to_quit
38
- invoke(visitor.runtime, visitor.configuration)
39
- visit_step_result(visitor)
36
+
37
+ visitor.visit_step(self) do
38
+ invoke(visitor.runtime, visitor.configuration)
39
+ visit_step_result(visitor)
40
+ end
40
41
  end
41
42
 
42
43
  def visit_step_result(visitor)
43
44
  visitor.visit_step_result(
44
- keyword,
45
- @step_match,
46
- (@different_table || @multiline_arg),
47
- @status,
48
- @reported_exception,
49
- source_indent,
50
- @background,
51
- file_colon_line
45
+ StepResult.new(
46
+ keyword,
47
+ @step_match,
48
+ (@different_table || @multiline_arg),
49
+ @status,
50
+ @reported_exception,
51
+ source_indent,
52
+ @background,
53
+ file_colon_line
54
+ )
52
55
  )
53
56
  end
54
57
 
@@ -144,11 +147,39 @@ module Lucid
144
147
  end
145
148
 
146
149
  def actual_keyword
147
- repeat_keywords = rubify([language.keywords('but'), language.keywords('and')]).flatten.uniq.reject{|kw| kw == '* '}
148
- if repeat_keywords.index(@step.keyword) && previous
150
+ #repeat_keywords = rubify([language.keywords('but'), language.keywords('and')]).flatten.uniq.reject{|kw| kw == '* '}
151
+ #if repeat_keywords.index(@step.keyword) && previous
152
+ keywords = Keywords.new(language)
153
+ if keywords.repeat_keyword?(keyword) && previous
149
154
  previous.actual_keyword
150
155
  else
151
- keyword == '* ' ? language.code_keywords.first : keyword
156
+ #keyword == '* ' ? language.code_keywords.first : keyword
157
+ keyword == '* ' ? keywords.star_code_keyword : keyword
158
+ end
159
+ end
160
+
161
+ class Keywords
162
+ include Gherkin::Rubify
163
+
164
+ def initialize(language)
165
+ @language = language
166
+ end
167
+
168
+ def repeat_keyword?(keyword)
169
+ repeat_keywords.index(keyword)
170
+ end
171
+
172
+ def star_code_keyword
173
+ language.code_keywords.reject { |k| repeat_keywords.map(&:strip).include?(k) }.first
174
+ end
175
+
176
+ attr_reader :language
177
+ private :language
178
+
179
+ private
180
+
181
+ def repeat_keywords
182
+ rubify([language.keywords('but'), language.keywords('and')]).flatten.uniq.reject{|kw| kw == '* '}
152
183
  end
153
184
  end
154
185