Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
working stack form and parsing
  • Loading branch information
patshaughnessy committed Dec 9, 2010
1 parent e428d76 commit e4e92b8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
11 changes: 8 additions & 3 deletions lib/code_buddy/app.rb
Expand Up @@ -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

Expand All @@ -38,8 +42,9 @@ def display_stack(selected_param)
@stack.selected = selected_param
erb :index
else
redirect '/'
redirect '/new'
end
end

end
end
15 changes: 9 additions & 6 deletions lib/code_buddy/stack_frame.rb
Expand Up @@ -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

Expand Down Expand Up @@ -38,8 +41,8 @@ def code
formatted_lines_below
].join
rescue => exception
"Unable to read the file #{path}"
"<span class=\"coderay\">Unable to read file:\n&nbsp;\"#{@path}\"</span>"
end
end
end
end
end
2 changes: 1 addition & 1 deletion spec/stack_frame_spec.rb
Expand Up @@ -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 == "<span class=\"coderay\">Unable to read file:\n&nbsp;\"/no/such/file.rb\"</span>"
end
end
end
10 changes: 8 additions & 2 deletions spec/stack_spec.rb
@@ -1,19 +1,25 @@
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'",
"/Users/me/my_app/config.ru:1"
]
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

Expand Down

0 comments on commit e4e92b8

Please sign in to comment.