Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Don't set a line and colum if Background is empty

  • Loading branch information...
commit 83e9313cf5058412dd8d70f6d8da49f3aa18714f 1 parent 42fb833
@txus txus authored
Showing with 27 additions and 9 deletions.
  1. +4 −2 lib/gherkin/ast.rb
  2. +23 −7 test/gherkin/ast_test.rb
View
6 lib/gherkin/ast.rb
@@ -33,8 +33,10 @@ class Background < Node
include Enumerable
def initialize(steps=[])
- @line = steps.first.line - 1
- @column = 3
+ if steps.any?
+ @line = steps.first.line - 1
+ @column = 3
+ end
@steps = steps
end
View
30 test/gherkin/ast_test.rb
@@ -82,21 +82,37 @@ def name.to_s; 'Name'; end
end
describe Background do
- it 'is a Node' do
- Background.ancestors.must_include Node
- end
-
- it 'is Enumerable' do
+ let(:steps) do
steps = [
OpenStruct.new(line: 4),
OpenStruct.new(line: 5),
]
+ end
+ it 'is a Node' do
+ Background.ancestors.must_include Node
+ end
+
+ it 'is Enumerable' do
instance = Background.new(steps)
- instance.line.must_equal 3
- instance.column.must_equal 3
instance.each.to_a.must_equal steps
end
+
+ describe 'when there are background steps' do
+ it 'records line and column' do
+ instance = Background.new(steps)
+ instance.line.must_equal 3
+ instance.column.must_equal 3
+ end
+ end
+
+ describe 'otherwise' do
+ it 'does not' do
+ instance = Background.new([])
+ instance.line.must_equal nil
+ instance.column.must_equal nil
+ end
+ end
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.