Skip to content

Commit

Permalink
TI5: Improve when href is shown or not to users
Browse files Browse the repository at this point in the history
  • Loading branch information
mattheworiordan committed Nov 9, 2018
1 parent 8c42c6f commit 51039ca
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/ably/models/error_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def attributes
end

def to_s
see_msg = " -> see https://help.ably.io/error/#{code} for help" if code
error_href = href || (code ? "https://help.ably.io/error/#{code}" : '')
see_msg = " -> see #{error_href} for help" unless message.to_s.include?(error_href.to_s)
"<Error: #{message} (code: #{code}, http status: #{status})>#{see_msg}"
end
end
Expand Down
44 changes: 41 additions & 3 deletions spec/unit/models/error_info_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,48 @@
end

context 'log entries container help link #TI5' do
subject { Ably::Models::ErrorInfo.new('code' => 44444) }
context 'without an error code' do
subject { Ably::Models::ErrorInfo.new('statusCode' => 401) }

it 'includes https://help.ably.io/error/[CODE] in the stringified object' do
expect(subject.to_s).to include('https://help.ably.io/error/44444')
it 'does not include the help URL' do
expect(subject.to_s.scan(/help\.ably\.io/)).to be_empty
end
end

context 'with a specified error code' do
subject { Ably::Models::ErrorInfo.new('code' => 44444) }

it 'includes https://help.ably.io/error/[CODE] in the stringified object' do
expect(subject.to_s).to include('https://help.ably.io/error/44444')
end
end

context 'with an error code and an href attribute' do
subject { Ably::Models::ErrorInfo.new('code' => 44444, 'href' => 'http://foo.bar.com/') }

it 'includes the specified href in the stringified object' do
expect(subject.to_s).to include('http://foo.bar.com/')
expect(subject.to_s).to_not include('https://help.ably.io/error/44444')
end
end

context 'with an error code and a message with the same error URL' do
subject { Ably::Models::ErrorInfo.new('message' => 'error https://help.ably.io/error/44444', 'code' => 44444) }

it 'includes the specified error URL only once in the stringified object' do
expect(subject.to_s.scan(/help.ably.io/).length).to eql(1)
end
end

context 'with an error code and a message with a different error URL' do
subject { Ably::Models::ErrorInfo.new('message' => 'error https://help.ably.io/error/123123', 'code' => 44444) }

it 'includes the specified error URL from the message and the error code URL in the stringified object' do
puts subject.to_s
expect(subject.to_s.scan(/help.ably.io/).length).to eql(2)
expect(subject.to_s.scan(%r{error/123123}).length).to eql(1)
expect(subject.to_s.scan(%r{error/44444}).length).to eql(1)
end
end
end
end

0 comments on commit 51039ca

Please sign in to comment.