Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Commit

Permalink
Fix naming in error spec.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kowshik Prakasam committed Feb 19, 2013
1 parent 9649692 commit 9740047
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 27 deletions.
12 changes: 6 additions & 6 deletions lib/schemata/common/error.rb
@@ -1,5 +1,5 @@
module Schemata
class Error < StandardError
class SchemataError < StandardError

attr_reader :source_exception, :source_backtrace

Expand All @@ -18,11 +18,11 @@ def backtrace
end
end

class DecodeError < Error; end
class EncodeError < Error; end
class SchemaDefinitionError < Error; end
class DecodeError < SchemataError; end
class EncodeError < SchemataError; end
class SchemaDefinitionError < SchemataError; end

class UpdateAttributeError < Error
class UpdateAttributeError < SchemataError
attr_reader :key

def initialize(key, exception = $!)
Expand All @@ -31,7 +31,7 @@ def initialize(key, exception = $!)
end
end

class IncompatibleVersionError < Error
class IncompatibleVersionError < SchemataError
attr_reader :msg_version, :component_version

def initialize(msg_version, component_version)
Expand Down
1 change: 1 addition & 0 deletions lib/schemata/common/msgbase.rb
Expand Up @@ -43,6 +43,7 @@ def self.define(schema)
field_value
end
end

vc_klass
end

Expand Down
42 changes: 21 additions & 21 deletions spec/common/error_spec.rb
Expand Up @@ -3,73 +3,73 @@

describe Schemata do
let(:backtrace) { %w(foo bar) }
let(:message) { "message" }
let(:exception) do
error = StandardError.new(message)
error.set_backtrace backtrace
let(:error_message) { "error message" }
let(:custom_error) do
error = StandardError.new(error_message)
error.set_backtrace(backtrace)
error
end

describe Schemata::Error do
context 'when an exception is explicitly passed in' do
describe Schemata::SchemataError do
context 'when an error is explicitly passed in' do
context 'and a message is not passed in' do
subject { Schemata::Error.new(exception) }
subject { Schemata::SchemataError.new(custom_error) }

its(:message) { should eq message }
its(:message) { should eq error_message }
its(:backtrace) { should be_nil }
end

context 'and a message is passed in' do
subject { Schemata::Error.new(exception, "other message") }
subject { Schemata::SchemataError.new(custom_error, "other message") }

its(:message) { should eq "other message" }
its(:backtrace) { should be_nil }
end
end

context 'when no exception is passed in' do
context 'when no error is passed in' do
context 'and it is a reraise' do
subject do
error = nil
begin
begin
raise exception
raise custom_error
rescue
raise Schemata::Error.new
raise Schemata::SchemataError.new
end
rescue => e
error = e
end
error
end

its(:message) { should eq message }
its(:message) { should eq error_message }
its(:source_backtrace) { should eq backtrace }

it 'includes the re raised exception' do
it 'includes the re raised error' do
expect(subject.backtrace.first).to match /error_spec\.rb/
end

it 'includes the chained exception' do
it 'includes the chained error' do
expect(subject.backtrace.last).to eq "bar"
end
end

context 'and it is a standlone exception' do
subject { Schemata::Error.new(nil, message) }
context 'and it is a standlone error' do
subject { Schemata::SchemataError.new(nil, error_message) }

its(:message) { should eq message }
its(:message) { should eq error_message }
its(:backtrace) { should be_nil }
end
end
end

describe Schemata::UpdateAttributeError do
let(:key) { "key" }
subject { Schemata::UpdateAttributeError.new(key, exception) }
subject { Schemata::UpdateAttributeError.new(key, custom_error) }

its(:message) { should eq "#{key}: #{message}" }
its(:to_s) { should eq "#{key}: #{message}" }
its(:message) { should eq "#{key}: #{error_message}" }
its(:to_s) { should eq "#{key}: #{error_message}" }
its(:key) { should eq key }
its(:backtrace) { should be_nil }
end
Expand Down

0 comments on commit 9740047

Please sign in to comment.