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

Ignore some instance variables #145

Merged
merged 3 commits into from
Mar 24, 2013
Merged
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
7 changes: 6 additions & 1 deletion lib/better_errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@ class << self

# @private
alias_method :binding_of_caller_available?, :binding_of_caller_available

# The ignored instance variables.
# @return [Array]
attr_accessor :ignored_instance_variables
end

@ignored_instance_variables = []

# Returns a proc, which when called with a filename and line number argument,
# returns a URL to open the filename and line in the selected editor.
#
Expand Down
8 changes: 6 additions & 2 deletions lib/better_errors/stack_frame.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,15 @@ def local_variables

def instance_variables
return {} unless frame_binding
Hash[frame_binding.eval("instance_variables").map { |x|
Hash[visible_instance_variables.map { |x|
[x, frame_binding.eval(x.to_s)]
}]
end


def visible_instance_variables
frame_binding.eval("instance_variables") - BetterErrors.ignored_instance_variables
end

def to_s
"#{pretty_path}:#{line}:in `#{name}'"
end
Expand Down
9 changes: 9 additions & 0 deletions spec/better_errors/error_page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ module BetterErrors
html.should include("inst_d")
html.should include(":value_for_inst_d")
end

it "should show filter instance variables" do
BetterErrors.stub(:ignored_instance_variables).and_return([ :@inst_d ])
html = error_page.do_variables("index" => 0)[:html]
html.should include("inst_c")
html.should include(":value_for_inst_c")
html.should_not include('<td class="name">@inst_d</td>')
html.should_not include("<pre>:value_for_inst_d</pre>")
end
end

it "should not die if the source file is not a real filename" do
Expand Down