diff --git a/lib/seed-fu/runner.rb b/lib/seed-fu/runner.rb index d042aa8..6a583b7 100644 --- a/lib/seed-fu/runner.rb +++ b/lib/seed-fu/runner.rb @@ -35,15 +35,17 @@ def run_file(filename) ActiveRecord::Base.transaction do open(filename) do |file| chunked_ruby = '' - file.each_line do |line| + start_line = 1 + file.each_line.with_index do |line, line_index| if line == "# BREAK EVAL\n" - eval(chunked_ruby) + eval(chunked_ruby, binding, filename, start_line) + start_line = line_index + 2 chunked_ruby = '' else chunked_ruby << line end end - eval(chunked_ruby) unless chunked_ruby == '' + eval(chunked_ruby, binding, filename, start_line) unless chunked_ruby == '' end end end diff --git a/spec/runner_spec.rb b/spec/runner_spec.rb index 85f1581..f92a3bb 100644 --- a/spec/runner_spec.rb +++ b/spec/runner_spec.rb @@ -21,4 +21,18 @@ SeedFu.seed SeededModel.count.should == 3 end + + it "should give meaningful stacktraces" do + %w[straight chunked].each do |suffix| + begin + SeedFu.seed(File.dirname(__FILE__) + '/fixtures/with_errors', /_#{suffix}/) + fail "Was supposed to raised error" + rescue Exception => e + e.message.should == "on line 4" + e.backtrace.first.should =~ /seeded_models_#{suffix}.rb:4/ + end + end + end + + end