2015-09-09 13:18:29 +00:00
|
|
|
package unit
|
|
|
|
|
|
|
|
type ErrorSubject struct {
|
|
|
|
*Subject
|
|
|
|
value error
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewErrorSubject(base *Subject, value error) *ErrorSubject {
|
2015-09-20 11:08:05 +00:00
|
|
|
return &ErrorSubject{
|
|
|
|
Subject: base,
|
|
|
|
value: value,
|
|
|
|
}
|
2015-09-09 13:18:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (subject *ErrorSubject) Named(name string) *ErrorSubject {
|
|
|
|
subject.Subject.Named(name)
|
|
|
|
return subject
|
|
|
|
}
|
|
|
|
|
|
|
|
func (subject *ErrorSubject) Fail(verb string, other error) {
|
|
|
|
subject.FailWithMessage("Not true that " + subject.DisplayString() + " " + verb + " <" + other.Error() + ">.")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (subject *ErrorSubject) DisplayString() string {
|
|
|
|
return subject.Subject.DisplayString(subject.value.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (subject *ErrorSubject) Equals(expectation error) {
|
|
|
|
if subject.value != expectation {
|
|
|
|
subject.Fail("is equal to", expectation)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (subject *ErrorSubject) IsNil() {
|
2015-09-09 13:26:11 +00:00
|
|
|
if subject.value != nil {
|
|
|
|
subject.FailWithMessage("Not true that " + subject.DisplayString() + " is nil.")
|
|
|
|
}
|
|
|
|
}
|
2015-10-13 19:29:27 +00:00
|
|
|
|
|
|
|
func (subject *ErrorSubject) IsNotNil() {
|
|
|
|
if subject.value == nil {
|
|
|
|
subject.FailWithMessage("Not true that the error is not nil.")
|
|
|
|
}
|
|
|
|
}
|