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

Small fixes, warnings, RSpec upgrades for the future #86

Merged
merged 8 commits into from
Apr 2, 2014
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ Gemfile.lock
pkg
*.gem

# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
vendor
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
#
# * Create a file at ~/.gitignore
# * Include files you want ignored
Expand Down
5 changes: 4 additions & 1 deletion lib/bugsnag/tasks/bugsnag.cap
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ namespace :bugsnag do

within release_path do
with rails_env: rails_env do
execute rake, "bugsnag:deploy #{new_env.map{|k,v| "#{k}=#{v}"}.join(" ")}"
params = "bugsnag:deploy #{new_env.map{|k,v| "#{k}=#{v}"}.join(" ")}"
rake = fetch(:rake, "rake")
execute rake, params
end
end

Expand All @@ -53,3 +55,4 @@ namespace :bugsnag do
end

end
# vi:ft=ruby
60 changes: 30 additions & 30 deletions spec/helper_spec.rb
Original file line number Diff line number Diff line change
@@ -1,90 +1,90 @@
require 'spec_helper'

describe Bugsnag::Helpers do
it "should be able to clean up recursive hashes" do
it "cleans up recursive hashes" do
a = {:a => {}}
a[:a][:b] = a
Bugsnag::Helpers.cleanup_obj(a).should == {:a => {:b => "[RECURSION]"}}
expect(Bugsnag::Helpers.cleanup_obj(a)).to eq({:a => {:b => "[RECURSION]"}})
end

it "should be able to clean up recursive arrays" do
it "cleans up recursive arrays" do
a = []
a << a
a << "hello"
Bugsnag::Helpers.cleanup_obj(a).should == ["[RECURSION]", "hello"]
expect(Bugsnag::Helpers.cleanup_obj(a)).to eq(["[RECURSION]", "hello"])
end

it "should allow multiple copies of the same string" do
it "allows multiple copies of the same string" do
a = {:name => "bugsnag"}
a[:second] = a[:name]
Bugsnag::Helpers.cleanup_obj(a).should == {:name => "bugsnag", :second => "bugsnag"}
expect(Bugsnag::Helpers.cleanup_obj(a)).to eq({:name => "bugsnag", :second => "bugsnag"})
end

it "should allow multiple copies of the same object" do
it "allows multiple copies of the same object" do
a = []
b = ["hello"]
a << b; a << b
Bugsnag::Helpers.cleanup_obj(a).should == [["hello"], ["hello"]]
expect(Bugsnag::Helpers.cleanup_obj(a)).to eq([["hello"], ["hello"]])
end

it "should reduce hash size correctly" do
it "reduces hash size correctly" do
meta_data = {
:key_one => "this should not be truncated",
:key_two => ""
}

1000.times {|i| meta_data[:key_two] += "this should be truncated " }

meta_data[:key_two].length.should > 4096
expect(meta_data[:key_two].length).to be > 4096

meta_data_return = Bugsnag::Helpers.reduce_hash_size meta_data

meta_data_return[:key_one].length.should == 28
meta_data_return[:key_one].should == "this should not be truncated"
expect(meta_data_return[:key_one].length).to eq(28)
expect(meta_data_return[:key_one]).to eq("this should not be truncated")

meta_data_return[:key_two].length.should == 4107
meta_data_return[:key_two].match(/\[TRUNCATED\]$/).nil?.should == false
expect(meta_data_return[:key_two].length).to eq(4107)
expect(meta_data_return[:key_two].match(/\[TRUNCATED\]$/).nil?).to eq(false)

meta_data[:key_two].length.should > 4096
meta_data[:key_two].match(/\[TRUNCATED\]$/).nil?.should == true
expect(meta_data[:key_two].length).to be > 4096
expect(meta_data[:key_two].match(/\[TRUNCATED\]$/).nil?).to eq(true)

meta_data[:key_one].length.should == 28
meta_data[:key_one].should == "this should not be truncated"
expect(meta_data[:key_one].length).to eq(28)
expect(meta_data[:key_one]).to eq("this should not be truncated")
end

it "should work with no filters configured" do
it "works with no filters configured" do
url = Bugsnag::Helpers.cleanup_url "/dir/page?param1=value1&param2=value2"

url.should == "/dir/page?param1=value1&param2=value2"
expect(url).to eq("/dir/page?param1=value1&param2=value2")
end

it "should not filter with no get params" do
it "does not filter with no get params" do
url = Bugsnag::Helpers.cleanup_url "/dir/page"

url.should == "/dir/page"
expect(url).to eq("/dir/page")
end

it "should leave a url alone if no filters match" do
it "leaves a url alone if no filters match" do
url = Bugsnag::Helpers.cleanup_url "/dir/page?param1=value1&param2=value2", ["param3"]

url.should == "/dir/page?param1=value1&param2=value2"
expect(url).to eq("/dir/page?param1=value1&param2=value2")
end

it "should filter a single get param" do
it "filters a single get param" do
url = Bugsnag::Helpers.cleanup_url "/dir/page?param1=value1&param2=value2", ["param1"]

url.should == "/dir/page?param1=[FILTERED]&param2=value2"
expect(url).to eq("/dir/page?param1=[FILTERED]&param2=value2")
end

it "should filter a get param that contains a filtered term" do
it "filters a get param that contains a filtered term" do
url = Bugsnag::Helpers.cleanup_url '/dir/page?param1=value1&param2=value2&bla=yes', ["param"]

url.should == "/dir/page?param1=[FILTERED]&param2=[FILTERED]&bla=yes"
expect(url).to eq("/dir/page?param1=[FILTERED]&param2=[FILTERED]&bla=yes")
end

it "should filter multiple matches" do
it "filters multiple matches" do
url = Bugsnag::Helpers.cleanup_url "/dir/page?param1=value1&param2=value2&param3=value3", ["param1", "param2"]

url.should == "/dir/page?param1=[FILTERED]&param2=[FILTERED]&param3=value3"
expect(url).to eq("/dir/page?param1=[FILTERED]&param2=[FILTERED]&param3=value3")
end
end
76 changes: 37 additions & 39 deletions spec/middleware_spec.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
require 'spec_helper'

describe Bugsnag::MiddlewareStack do
it "should run before_bugsnag_notify callbacks, adding a tab" do
Bugsnag::Notification.should_receive(:deliver_exception_payload) do |endpoint, payload|
it "runs before_bugsnag_notify callbacks, adding a tab" do
expect(Bugsnag::Notification).to receive(:deliver_exception_payload) do |endpoint, payload|
event = get_event_from_payload(payload)
event[:metaData][:some_tab].should_not be_nil
event[:metaData][:some_tab][:info].should be == "here"
event[:metaData][:some_tab][:data].should be == "also here"
expect(event[:metaData][:some_tab]).not_to be_nil
expect(event[:metaData][:some_tab][:info]).to eq("here")
expect(event[:metaData][:some_tab][:data]).to eq("also here")
end

callback_run_count = 0
Expand All @@ -19,15 +19,15 @@
}

Bugsnag.notify(BugsnagTestException.new("It crashed"))
callback_run_count.should be == 1
expect(callback_run_count).to eq(1)
end

it "should run before_bugsnag_notify callbacks, adding custom data" do
Bugsnag::Notification.should_receive(:deliver_exception_payload) do |endpoint, payload|
it "runs before_bugsnag_notify callbacks, adding custom data" do
expect(Bugsnag::Notification).to receive(:deliver_exception_payload) do |endpoint, payload|
event = get_event_from_payload(payload)
event[:metaData][:custom].should_not be_nil
event[:metaData][:custom][:info].should be == "here"
event[:metaData][:custom][:data].should be == "also here"
expect(event[:metaData][:custom]).not_to be_nil
expect(event[:metaData][:custom][:info]).to eq("here")
expect(event[:metaData][:custom][:data]).to eq("also here")
end

callback_run_count = 0
Expand All @@ -39,17 +39,17 @@
}

Bugsnag.notify(BugsnagTestException.new("It crashed"))
callback_run_count.should be == 1
expect(callback_run_count).to eq(1)
end

it "should run before_bugsnag_notify callbacks, setting the user" do
Bugsnag::Notification.should_receive(:deliver_exception_payload) do |endpoint, payload|
it "runs before_bugsnag_notify callbacks, setting the user" do
expect(Bugsnag::Notification).to receive(:deliver_exception_payload) do |endpoint, payload|
event = get_event_from_payload(payload)
event[:user].should_not be_nil
event[:user][:id].should be == "here"
event[:user][:email].should be == "also here"
event[:user][:name].should be == "also here too"
event[:user][:random_key].should be == "also here too too"
expect(event[:user]).not_to be_nil
expect(event[:user][:id]).to eq("here")
expect(event[:user][:email]).to eq("also here")
expect(event[:user][:name]).to eq("also here too")
expect(event[:user][:random_key]).to eq("also here too too")
end

callback_run_count = 0
Expand All @@ -59,15 +59,15 @@
}

Bugsnag.notify(BugsnagTestException.new("It crashed"))
callback_run_count.should be == 1
expect(callback_run_count).to eq(1)
end

it "overrides should override data set in before_notify" do
Bugsnag::Notification.should_receive(:deliver_exception_payload) do |endpoint, payload|
it "overrides data set in before_notify" do
expect(Bugsnag::Notification).to receive(:deliver_exception_payload) do |endpoint, payload|
event = get_event_from_payload(payload)
event[:metaData][:custom].should_not be_nil
event[:metaData][:custom][:info].should be == "here2"
event[:metaData][:custom][:data].should be == "also here"
expect(event[:metaData][:custom]).not_to be_nil
expect(event[:metaData][:custom][:info]).to eq("here2")
expect(event[:metaData][:custom][:data]).to eq("also here")
end

callback_run_count = 0
Expand All @@ -79,24 +79,22 @@
}

Bugsnag.notify(BugsnagTestException.new("It crashed"), {:info => "here2"})
callback_run_count.should be == 1
expect(callback_run_count).to eq(1)
end

it "should have no before or after callbacks by default" do
Bugsnag::Notification.should_receive(:deliver_exception_payload) do |endpoint, payload|
it "does not have have before or after callbacks by default" do
expect(Bugsnag::Notification).to receive(:deliver_exception_payload) do |endpoint, payload|
event = get_event_from_payload(payload)
event[:metaData].should have(0).items
expect(event[:metaData].size).to eq(0)
end

Bugsnag.before_notify_callbacks.should have(0).items
Bugsnag.after_notify_callbacks.should have(0).items
expect(Bugsnag.before_notify_callbacks.size).to eq(0)
expect(Bugsnag.after_notify_callbacks.size).to eq(0)
Bugsnag.notify(BugsnagTestException.new("It crashed"))
end

it "should run after_bugsnag_notify callbacks" do
Bugsnag::Notification.should_receive(:deliver_exception_payload) do |endpoint, payload|
event = get_event_from_payload(payload)
end
it "runs after_bugsnag_notify callbacks" do
expect(Bugsnag::Notification).to receive(:deliver_exception_payload)

callback_run_count = 0
Bugsnag.after_notify_callbacks << lambda {|notif|
Expand All @@ -105,10 +103,10 @@

Bugsnag.notify(BugsnagTestException.new("It crashed"))

callback_run_count.should be == 1
expect(callback_run_count).to eq(1)
end

it "should not execute disabled bugsnag middleware" do
it "does not execute disabled bugsnag middleware" do
callback_run_count = 0
Bugsnag.configure do |config|
config.middleware.disable(Bugsnag::Middleware::Callbacks)
Expand All @@ -119,6 +117,6 @@
}

Bugsnag.notify(BugsnagTestException.new("It crashed"))
callback_run_count.should be == 0
expect(callback_run_count).to eq(0)
end
end
end