Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Final refactor of table example substitution.

  • Loading branch information...
commit 66069581e1f165b01edd67f22010da3edd7c3e03 1 parent dd1113c
@lukaso lukaso authored
View
11 lib/turnip/builder.rb
@@ -82,7 +82,10 @@ def to_scenarios(examples)
Scenario.new(@raw).tap do |scenario|
scenario.steps = steps.map do |step|
new_description = substitute(step.description, headers, row)
- new_extra_args = substitute_extra_args(step, headers, row)
+ new_extra_args = step.extra_args.map do |ea|
+ next ea unless ea.instance_of?(Turnip::Table)
+ Turnip::Table.new(ea.map {|t_row| t_row.map {|t_col| substitute(t_col, headers, row) } })
+ end
Step.new(new_description, new_extra_args, step.line)
end
end
@@ -95,11 +98,7 @@ def substitute(text, headers, row)
text.gsub(/<([^>]*)>/) { |_| Hash[headers.zip(row)][$1] }
end
- def substitute_extra_args(step, headers, row)
- return step.extra_args unless index = step.extra_args.find_index { |a| a.instance_of?(Turnip::Table) }
- step.extra_args.dup.tap do |ea|
- ea[index] = ea[index].dup.tap {|t| t.raw.map! {|t_row| t_row.map! {|t_col| substitute(t_col, headers, row) } } }
- end
+ def substitute_table(step, headers, row)
end
end
View
5 lib/turnip/table.rb
@@ -9,11 +9,6 @@ def initialize(raw)
@raw = raw
end
- def initialize_copy(other)
- super
- @raw = Marshal.load(Marshal.dump(other.raw))
- end
-
def headers
raw.first
end
View
13 spec/table_spec.rb
@@ -77,17 +77,4 @@
end
end
- describe '#dup and #clone' do
- it "makes a deep copy when calling #dup" do
- new_table = table.dup
- new_table.raw[0][0] = 'blegga'
- table.raw[0][0].should == 'foo'
- end
-
- it "makes a deep copy when calling #clone" do
- new_table = table.dup
- new_table.raw[0][0] = 'blegga'
- table.raw[0][0].should == 'foo'
- end
- end
end
Please sign in to comment.
Something went wrong with that request. Please try again.