diff --git a/lib/code_buddy/app.rb b/lib/code_buddy/app.rb
index e3bcc29..8a3bb22 100644
--- a/lib/code_buddy/app.rb
+++ b/lib/code_buddy/app.rb
@@ -16,19 +16,23 @@ def stack_string=(stack_string)
end
get '/' do
+ display_stack(0)
+ end
+
+ get '/new' do
erb :form
end
post '/' do
self.class.stack_string = params[:stack]
- redirect '/stack'
+ redirect '/'
end
get '/stack' do
display_stack(0)
end
- get '/stack/:selected' do
+ get '/:selected' do
display_stack(params[:selected].to_i)
end
@@ -38,8 +42,9 @@ def display_stack(selected_param)
@stack.selected = selected_param
erb :index
else
- redirect '/'
+ redirect '/new'
end
end
+
end
end
diff --git a/lib/code_buddy/stack_frame.rb b/lib/code_buddy/stack_frame.rb
index 5548863..06b47a7 100644
--- a/lib/code_buddy/stack_frame.rb
+++ b/lib/code_buddy/stack_frame.rb
@@ -5,12 +5,15 @@ class StackFrame
attr_reader :path
attr_reader :line
- attr_reader :code
def initialize(exception_string)
- @path, @line = exception_string.split(':')
- @line = @line.to_i
-
+ if exception_string =~ /\s*([^:\s]+):([0-9]+)\s*/
+ @path = $1
+ @line = $2.to_i
+ else
+ @path = exception_string
+ @line = 0
+ end
code
end
@@ -38,8 +41,8 @@ def code
formatted_lines_below
].join
rescue => exception
- "Unable to read the file #{path}"
+ "Unable to read file:\n \"#{@path}\""
end
end
end
-end
\ No newline at end of file
+end
diff --git a/spec/stack_frame_spec.rb b/spec/stack_frame_spec.rb
index bb6c63b..d0f90b9 100644
--- a/spec/stack_frame_spec.rb
+++ b/spec/stack_frame_spec.rb
@@ -123,7 +123,7 @@
raises(Errno::ENOENT.new('/no/such/file.rb'))
stack_frame = CodeBuddy::StackFrame.new('/no/such/file.rb')
- stack_frame.code.should == 'Unable to read the file /no/such/file.rb'
+ stack_frame.code.should == "Unable to read file:\n \"/no/such/file.rb\""
end
end
end
diff --git a/spec/stack_spec.rb b/spec/stack_spec.rb
index 68827bf..f5eada6 100644
--- a/spec/stack_spec.rb
+++ b/spec/stack_spec.rb
@@ -1,6 +1,7 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe CodeBuddy::Stack do
+
it 'should create a series of stack frames from an exception' do
backtrace = [
"/Users/me/my_app/config.ru:1:in `new'",
@@ -8,12 +9,17 @@
]
CodeBuddy::StackFrame.expects(:new).with("/Users/me/my_app/config.ru:1:in `new'").returns(frame1=mock)
CodeBuddy::StackFrame.expects(:new).with("/Users/me/my_app/config.ru:1" ).returns(frame2=mock)
- stack = CodeBuddy::Stack.new mock(:backtrace=>backtrace)
+ mock_exception = mock(:backtrace=>backtrace)
+ mock_exception.expects(:is_a?).with(Exception).returns(true)
+ stack = CodeBuddy::Stack.new mock_exception
stack.stack_frames.should == [frame1, frame2]
end
it 'should save the currently selected stack frame' do
- stack = CodeBuddy::Stack.new mock(:backtrace=>''), 3
+ mock_exception = mock(:backtrace=>'')
+ mock_exception.expects(:is_a?).with(Exception).returns(true)
+ stack = CodeBuddy::Stack.new mock_exception
+ stack.selected = 3
stack.selected.should == 3
end