Skip to content

Commit

Permalink
Breadcrumbs/Breadcrumb: Improve tests, convert to utc sooner
Browse files Browse the repository at this point in the history
  • Loading branch information
Cawllec committed Dec 6, 2018
1 parent ee3e8c5 commit 8e2042e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
6 changes: 3 additions & 3 deletions lib/bugsnag/breadcrumbs/breadcrumb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Breadcrumb
# @return [Hash, nil] metadata hash containing strings, numbers, or booleans, or nil
attr_accessor :meta_data

# @return [Symbol] set to `:auto` if the breadcrumb was automatically generated
# @return [Boolean] set to `true` if the breadcrumb was automatically generated
attr_reader :auto

# @return [Time] a Time object referring to breadcrumb creation time
Expand All @@ -36,7 +36,7 @@ def initialize(name, type, meta_data, auto)
@auto = auto == :auto

# Store it as a timestamp for now
@timestamp = Time.now
@timestamp = Time.now.utc
end

##
Expand Down Expand Up @@ -69,7 +69,7 @@ def to_h
:name => @name,
:type => @type,
:metaData => @meta_data,
:timestamp => @timestamp.utc.iso8601
:timestamp => @timestamp.iso8601
}
end
end
Expand Down
17 changes: 10 additions & 7 deletions spec/breadcrumbs/breadcrumb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
it "is stored as a timestamp" do
breadcrumb = Bugsnag::Breadcrumbs::Breadcrumb.new(nil, nil, nil, nil)

expect(breadcrumb.timestamp).to be_within(0.5).of Time.now
expect(breadcrumb.timestamp).to be_within(0.5).of Time.now.utc
end
end

Expand All @@ -77,14 +77,17 @@
breadcrumb = Bugsnag::Breadcrumbs::Breadcrumb.new("my message", "test type", {:a => 1, :b => 2}, :manual)
output = breadcrumb.to_h

expect(output[:name]).to eq("my message")
expect(output[:type]).to eq("test type")
expect(output[:metaData]).to eq({ :a => 1, :b => 2})

timestamp_regex = /^\d{4}\-\d{2}\-\d{2}T\d{2}:\d{2}:[\d\.]+Z$/

expect(output[:timestamp]).to be_a_kind_of(String)
expect(output[:timestamp]).to match(timestamp_regex)
expect(output).to match(
:name => "my message",
:type => "test type",
:metaData => {
:a => 1,
:b => 2
},
:timestamp => match(timestamp_regex)
)
end
end
end

0 comments on commit 8e2042e

Please sign in to comment.