Skip to content

Commit

Permalink
Merge pull request #69 from Sija/develop
Browse files Browse the repository at this point in the history
v1.7
  • Loading branch information
Sija authored Jun 21, 2020
2 parents 16d04fa + 11d5ff9 commit 3fff872
Show file tree
Hide file tree
Showing 31 changed files with 230 additions and 203 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ crystal:
- latest
- nightly

matrix:
jobs:
allow_failures:
- crystal: nightly

Expand All @@ -16,5 +16,7 @@ script:
- crystal spec --no-debug
- crystal spec --release
- crystal spec --release --no-debug
- shards build crash_handler
- shards build crash_handler --release
- crystal tool format --check
- bin/ameba src
- bin/ameba
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</h1>

<p align="center">
<a href="https://travis-ci.org/Sija/raven.cr"><img src="https://travis-ci.org/Sija/raven.cr.svg?branch=master" alt="Build Status" /></a>
<a href="https://travis-ci.com/Sija/raven.cr"><img src="https://travis-ci.com/Sija/raven.cr.svg?branch=master" alt="Build Status" /></a>
<a href="https://www.codacy.com/app/Sija/raven.cr"><img src="https://api.codacy.com/project/badge/Grade/32cb8814a14d4a6cbe39d6768142c59b" alt="Codacy Badge" /></a>
<a href="https://github.com/Sija/raven.cr/releases"><img src="https://img.shields.io/github/release/Sija/raven.cr.svg" alt="Releases" /></a>
<a href="https://github.com/Sija/raven.cr/blob/master/LICENSE"><img src="https://img.shields.io/github/license/Sija/raven.cr.svg" alt="License" /></a>
Expand Down
6 changes: 3 additions & 3 deletions shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: raven
version: 1.6.0
version: 1.7.0

authors:
- Sijawusz Pur Rahnama <sija@sija.pl>
Expand All @@ -15,12 +15,12 @@ development_dependencies:
version: ~> 0.4.0
ameba:
github: crystal-ameba/ameba
version: ~> 0.11.0
version: ~> 0.13.0

targets:
crash_handler:
main: src/crash_handler.cr

crystal: 0.32.0
crystal: 0.35.0

license: MIT
2 changes: 1 addition & 1 deletion spec/raven/backtrace_line_spec.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "../spec_helper"

def with_line(path = "#{__DIR__}/foo.cr", method = "foo_bar?")
private def with_line(path = "#{__DIR__}/foo.cr", method = "foo_bar?")
line = "#{path}:1:7 in '#{method}'"
yield Raven::Backtrace::Line.parse(line)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/raven/breadcrumb_buffer_spec.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "../spec_helper"

def with_breadcrumb_buffer
private def with_breadcrumb_buffer
breadcrumbs = Raven::BreadcrumbBuffer.new(10)
yield breadcrumbs
end
Expand Down
11 changes: 3 additions & 8 deletions spec/raven/client_spec.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "../spec_helper"

class ClientTest < Raven::Client
private class ClientTest < Raven::Client
def generate_auth_header
super
end
Expand All @@ -10,12 +10,7 @@ class ClientTest < Raven::Client
end
end

def build_configuration
Raven::Configuration.new
.tap(&.dsn = "dummy://12345:67890@sentry.localdomain:3000/sentry/42")
end

def with_client
private def with_client
yield ClientTest.new(build_configuration)
end

Expand Down Expand Up @@ -96,7 +91,7 @@ describe Raven::Client do
last_event[:options].should eq({:content_type => "application/octet-stream"})
last_event[:data].should be_a(String)
io = IO::Memory.new(last_event[:data].as(String))
Gzip::Reader.open(io) do |gzip|
Compress::Gzip::Reader.open(io) do |gzip|
data = JSON.parse(gzip.gets_to_end)
data.as_h?.should_not be_nil
data["event_id"].should eq(event.id)
Expand Down
2 changes: 1 addition & 1 deletion spec/raven/client_state_spec.cr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "../spec_helper"
require "timecop"

def with_client_state
private def with_client_state
yield Raven::Client::State.new
end

Expand Down
4 changes: 2 additions & 2 deletions spec/raven/configuration_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ private class RandomSampleFail < Random::PCG32
end
end

def with_configuration
private def with_configuration
with_clean_env do
yield Raven::Configuration.new
end
end

def with_configuration_with_dsn
private def with_configuration_with_dsn
with_configuration do |configuration|
configuration.dsn = "http://12345:67890@sentry.localdomain:3000/sentry/42"
yield configuration
Expand Down
14 changes: 9 additions & 5 deletions spec/raven/event_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Raven::Test
class Exception < ::Exception; end
end

def with_event(clear = true, **opts)
private def with_event(clear = true, **opts)
if clear
Raven::Context.clear!
Raven::BreadcrumbBuffer.clear!
Expand All @@ -13,18 +13,24 @@ def with_event(clear = true, **opts)
yield event
end

def with_event_hash(**opts)
private def with_event_hash(**opts)
with_event(**opts) do |event|
yield event.to_hash
end
end

def exception_value_from_event_hash(hash, index)
private def exception_value_from_event_hash(hash, index)
ex_values = hash.to_any_json[:exception, :values].as(Array)
ex_values[index].as(Hash)
end

describe Raven::Event do
around_each do |example|
Raven::Context.clear!
example.run
Raven::Context.clear!
end

context "with fully implemented event" do
opts = {
message: "test",
Expand Down Expand Up @@ -190,8 +196,6 @@ describe Raven::Event do
{% for key in %i(user extra tags) %}
context "with {{key.id}} context specified" do
it "prioritizes event context" do
Raven::Context.clear!

Raven.{{key.id}}_context({
"context_event_key" => "context_value",
"context_key" => "context_value",
Expand Down
51 changes: 22 additions & 29 deletions spec/raven/instance_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,7 @@ private class InstanceTest < Raven::Instance
end
end

private class LoggerTest < Raven::Logger
getter infos = [] of String

def info(message, *args)
super.tap do
@infos << message
end
end
end

def build_configuration
Raven::Configuration.new.tap do |config|
config.dsn = "dummy://12345:67890@sentry.localdomain:3000/sentry/42"
config.logger = LoggerTest.new(nil)
end
end

def with_instance(context = nil)
private def with_instance(context = nil)
yield InstanceTest.new(context, build_configuration)
end

Expand Down Expand Up @@ -214,17 +197,21 @@ describe Raven::Instance do
with_instance do |instance|
instance.configuration.silence_ready = false

instance.report_status
instance.logger.as(LoggerTest).infos.should contain(ready_message)
Log.capture do |logs|
instance.report_status
logs.check(:info, ready_message)
end
end
end

it "logs nothing if 'silence_ready' option is true" do
with_instance do |instance|
instance.configuration.silence_ready = true

instance.report_status
instance.logger.as(LoggerTest).infos.should_not contain(ready_message)
Log.capture do |logs|
instance.report_status
logs.empty
end
end
end

Expand All @@ -233,8 +220,10 @@ describe Raven::Instance do
instance.configuration.silence_ready = false
instance.configuration.dsn = "dummy://foo"

instance.report_status
instance.logger.as(LoggerTest).infos.first.should contain(not_ready_message)
Log.capture do |logs|
instance.report_status
logs.check(:info, /#{not_ready_message}/)
end
end
end

Expand All @@ -243,10 +232,12 @@ describe Raven::Instance do
instance.configuration.silence_ready = false
instance.configuration.environments = %w(production)

instance.report_status
instance.logger.as(LoggerTest).infos.should contain(
"#{not_ready_message}: Not configured to send/capture in environment 'default'"
)
Log.capture do |logs|
instance.report_status
logs.check(:info,
"#{not_ready_message}: Not configured to send/capture in environment 'default'"
)
end
end
end
end
Expand All @@ -255,7 +246,9 @@ describe Raven::Instance do
it "sends the result of Event.capture" do
with_instance do |instance|
event = instance.capture("Test message")
instance.last_sent_event.try(&.id).should eq(event.as?(Raven::Event).try(&.id))

last_sent_event = instance.last_sent_event.should_not be_nil
last_sent_event.id.should eq(event.as(Raven::Event).id)
end
end
end
Expand Down
12 changes: 0 additions & 12 deletions spec/raven/logger_spec.cr

This file was deleted.

24 changes: 13 additions & 11 deletions spec/raven/processors/sanitize_data_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ end
STRING_MASK = Raven::Processor::SanitizeData::STRING_MASK
INT_MASK = Raven::Processor::SanitizeData::INT_MASK

describe Raven::Processor::SanitizeData do
processor = build_processor(Raven::Processor::SanitizeData)
private def test_processor
build_processor(Raven::Processor::SanitizeData)
end

describe Raven::Processor::SanitizeData do
context "configuration for sanitize fields" do
it "should union default sanitize fields with user-defined sanitize fields" do
with_processor(SanitizeDataTest) do |processor|
Expand Down Expand Up @@ -133,7 +135,7 @@ describe Raven::Processor::SanitizeData do
},
}

result = processor.process(data_with_embedded_json)
result = test_processor.process(data_with_embedded_json)
result = result.to_any_json

JSON.parse(result["data", "json"].as(String)).should eq(%w(foo bar))
Expand All @@ -148,7 +150,7 @@ describe Raven::Processor::SanitizeData do
},
}

result = processor.process(data_with_invalid_json)
result = test_processor.process(data_with_invalid_json)
result = result.to_any_json

expect_raises(JSON::ParseException) do
Expand All @@ -162,7 +164,7 @@ describe Raven::Processor::SanitizeData do
"ccnumba_int" => 4242424242424242,
}

result = processor.process(data)
result = test_processor.process(data)

result["ccnumba"].should eq(STRING_MASK)
result["ccnumba_int"].should eq(INT_MASK)
Expand Down Expand Up @@ -192,7 +194,7 @@ describe Raven::Processor::SanitizeData do
"symbol_hash_array" => [{:password => "secret"}],
}

result = processor.process(data)
result = test_processor.process(data)

result["string_hash_array"].should eq([{"password" => STRING_MASK}])
result["symbol_hash_array"].should eq([{:password => STRING_MASK}])
Expand All @@ -208,7 +210,7 @@ describe Raven::Processor::SanitizeData do
},
}

result = processor.process(data)
result = test_processor.process(data)
result = result.to_any_json

result["sentry.interfaces.Http", "data", "query_string"].as(String).should_not contain("secret")
Expand All @@ -223,7 +225,7 @@ describe Raven::Processor::SanitizeData do
},
}

result = processor.process(data)
result = test_processor.process(data)
result = result.to_any_json

result["sentry.interfaces.Http", "data", :query_string].as(String).should_not contain("secret")
Expand All @@ -238,7 +240,7 @@ describe Raven::Processor::SanitizeData do
},
}

result = processor.process(data)
result = test_processor.process(data)
result.should eq(data)
end

Expand All @@ -252,7 +254,7 @@ describe Raven::Processor::SanitizeData do
},
}

result = processor.process(data)
result = test_processor.process(data)
result.should eq(data)
end
end
Expand All @@ -264,7 +266,7 @@ describe Raven::Processor::SanitizeData do
:millis_since_epoch => "1507671610403",
}

result = processor.process(data)
result = test_processor.process(data)
result.should eq(data)
end
end
2 changes: 1 addition & 1 deletion spec/raven/processors/utf8_conversion_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe Raven::Processor::UTF8Conversion do

it "should retain #cause and #callstack in cleaned up Exception" do
ex = Exception.new(nil, Exception.new)
ex.callstack = CallStack.new
ex.callstack = Exception::CallStack.new

results = processor.process(ex)
results.cause.should eq(ex.cause)
Expand Down
2 changes: 1 addition & 1 deletion spec/raven/version_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe Raven::VERSION do
end

it "should match shard.yml" do
version = YAML.parse(File.read(File.join(__DIR__, "../..", "shard.yml")))["version"].as_s
version = YAML.parse(File.read(Path[__DIR__, "..", "..", "shard.yml"]))["version"].as_s
version.should eq Raven::VERSION
end
end
Loading

0 comments on commit 3fff872

Please sign in to comment.