Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call eval with file and line nb so seeds fail with proper stracktraces #111

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/seed-fu/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions spec/fixtures/with_errors/seeded_models_chunked.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# this is line 1
# this is line 2
# BREAK EVAL
raise 'on line 4'
4 changes: 4 additions & 0 deletions spec/fixtures/with_errors/seeded_models_straight.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# this is line 1
# this is line 2
# this is line 3
raise 'on line 4'
14 changes: 14 additions & 0 deletions spec/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 "An exception was supposed to be raised"
rescue Exception => e
e.message.should == "on line 4"
e.backtrace.first.should =~ /seeded_models_#{suffix}.rb:4/
end
end
end


end