Skip to content

Commit

Permalink
Allow Failure#to_json to accept options (#134)
Browse files Browse the repository at this point in the history
Allow #to_json to accept options
  • Loading branch information
ct-clearhaus committed Jul 16, 2020
1 parent 3343a41 commit 30a9ac5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/stoplight/failure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,18 @@ def ==(other)
time == other.time
end

# @param options [Object, nil]
# @return [String]
def to_json
def to_json(options = nil)
JSON.generate(
error: {
class: error_class,
message: error_message
{
error: {
class: error_class,
message: error_message
},
time: time.strftime(TIME_FORMAT)
},
time: time.strftime(TIME_FORMAT)
options
)
end
end
Expand Down
5 changes: 5 additions & 0 deletions spec/stoplight/failure_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@
expect(described_class.new(error_class, error_message, time).to_json)
.to eql(json)
end

it 'generates JSON with options' do
expect(described_class.new(error_class, error_message, time).to_json({}))
.to eql(json)
end
end

describe '::TIME_FORMAT' do
Expand Down

0 comments on commit 30a9ac5

Please sign in to comment.