Skip to content

Commit

Permalink
StandardRB fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kyrylo committed Jun 8, 2024
1 parent c3a0a3f commit 525e1c8
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
4 changes: 2 additions & 2 deletions lib/telebugs/code_hunk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def self.get(file, line)
start_line = [line - AROUND_LINES, 1].max

lines = get_lines(file, start_line, line + AROUND_LINES)
return { start_line: 0, lines: [] } if lines.empty?
return {start_line: 0, lines: []} if lines.empty?

{
start_line: start_line,
Expand All @@ -37,7 +37,7 @@ def self.get(file, line)

private_class_method def self.get_from_cache(file)
Telebugs::FileCache[file] ||= File.foreach(file)
rescue StandardError
rescue
nil
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/telebugs/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Config
ERROR_API_URL = "https://api.telebugs.com/2024-03-28/errors"

attr_accessor :api_key,
:root_directory
:root_directory

attr_reader :api_url

Expand All @@ -32,7 +32,7 @@ def reset
self.api_url = ERROR_API_URL
self.root_directory = File.realpath(
(defined?(Bundler) && Bundler.root) ||
Dir.pwd,
Dir.pwd
)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/telebugs/notice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def attach_code(b)
next unless File.exist?(frame[:file])
next unless frame[:line]
next unless frame_belogns_to_root_directory?(frame)
next if frame[:file] =~ %r{vendor/bundle}
next if %r{vendor/bundle}.match?(frame[:file])

frame[:code] = CodeHunk.get(frame[:file], frame[:line])
end
Expand Down
6 changes: 3 additions & 3 deletions test/test_file_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ def test_set_when_cache_limit_is_not_reached
end

assert_equal "value0", Telebugs::FileCache["key0"]
assert_equal "value#{max_size-1}", Telebugs::FileCache["key#{max_size-1}"]
assert_equal "value#{max_size - 1}", Telebugs::FileCache["key#{max_size - 1}"]
end

def test_set_when_cache_over_limit
max_size = 2*Telebugs::FileCache::MAX_SIZE
max_size = 2 * Telebugs::FileCache::MAX_SIZE
max_size.times do |i|
Telebugs::FileCache["key#{i}"] = "value#{i}"
end

assert_nil Telebugs::FileCache["key49"]
assert_equal "value50", Telebugs::FileCache["key50"]
assert_equal "value#{max_size-1}", Telebugs::FileCache["key#{max_size-1}"]
assert_equal "value#{max_size - 1}", Telebugs::FileCache["key#{max_size - 1}"]
end
end
11 changes: 5 additions & 6 deletions test/test_notice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

class TestNotice < Minitest::Test
def fixture_path(filename)
File.expand_path(File.join('test', 'fixtures', filename))
File.expand_path(File.join("test", "fixtures", filename))
end

def project_root_path(filename)
fixture_path(File.join('project_root', filename))
fixture_path(File.join("project_root", filename))
end

def setup
Telebugs.configure do |c|
c.root_directory = project_root_path('')
c.root_directory = project_root_path("")
end
end

Expand Down Expand Up @@ -52,12 +52,11 @@ def test_to_json_with_nested_errors
def test_to_json_code
error = RuntimeError.new
error.set_backtrace([
"#{project_root_path('code.rb')}:18:in `start'",
"#{project_root_path("code.rb")}:18:in `start'",
fixture_path("notroot.txt:3:in `pineapple'"),
"#{project_root_path('vendor/bundle/ignored_file.rb')}:2:in `ignore_me'",
"#{project_root_path("vendor/bundle/ignored_file.rb")}:2:in `ignore_me'"
])


n = Telebugs::Notice.new(error)
json = JSON.parse(n.to_json)
backtrace = json["errors"][0]["backtrace"]
Expand Down

0 comments on commit 525e1c8

Please sign in to comment.