Merge pull request #83 from hobeone/patch-1
Return prettyprinted JSON strings for errors.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ea269ca..5f2c1ed 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,10 @@
- `ghttp` can now handle concurrent requests.
- Added `Succeed` which allows one to write `Ω(MyFunction()).Should(Succeed())`.
+Bug Fixes:
+- gexec: `session.Wait` now uses `EventuallyWithOffset` to get the right line number in the failure.
+- `ContainElement` no longer bails if a passed-in matcher errors.
+
## 1.0 (8/2/2014)
No changes. Dropping "beta" from the version number.
diff --git a/gexec/session.go b/gexec/session.go
index 460cfe5..46e7122 100644
--- a/gexec/session.go
+++ b/gexec/session.go
@@ -137,7 +137,7 @@
Wait uses eventually under the hood and accepts the same timeout/polling intervals that eventually does.
*/
func (s *Session) Wait(timeout ...interface{}) *Session {
- Eventually(s, timeout...).Should(Exit())
+ EventuallyWithOffset(1, s, timeout...).Should(Exit())
return s
}
diff --git a/gexec/session_test.go b/gexec/session_test.go
index cd48e6f..13cc3cd 100644
--- a/gexec/session_test.go
+++ b/gexec/session_test.go
@@ -4,6 +4,7 @@
"os/exec"
"syscall"
"time"
+
. "github.com/onsi/gomega/gbytes"
. "github.com/onsi/gomega/gexec"
diff --git a/matchers/contain_element_matcher.go b/matchers/contain_element_matcher.go
index 014a20f..4159335 100644
--- a/matchers/contain_element_matcher.go
+++ b/matchers/contain_element_matcher.go
@@ -2,8 +2,9 @@
import (
"fmt"
- "github.com/onsi/gomega/format"
"reflect"
+
+ "github.com/onsi/gomega/format"
)
type ContainElementMatcher struct {
@@ -25,6 +26,7 @@
if isMap(actual) {
keys = value.MapKeys()
}
+ var lastError error
for i := 0; i < value.Len(); i++ {
var success bool
var err error
@@ -34,14 +36,15 @@
success, err = elemMatcher.Match(value.Index(i).Interface())
}
if err != nil {
- return false, fmt.Errorf("ContainElement's element matcher failed with:\n\t%s", err.Error())
+ lastError = err
+ continue
}
if success {
return true, nil
}
}
- return false, nil
+ return false, lastError
}
func (matcher *ContainElementMatcher) FailureMessage(actual interface{}) (message string) {
diff --git a/matchers/contain_element_matcher_test.go b/matchers/contain_element_matcher_test.go
index 4d29eeb..38ee518 100644
--- a/matchers/contain_element_matcher_test.go
+++ b/matchers/contain_element_matcher_test.go
@@ -35,8 +35,12 @@
Ω(map[string]int{"foo": 1, "bar": 2}).ShouldNot(ContainElement(BeNumerically(">", 2)))
})
- It("should fail if the matcher ever fails", func() {
- actual := []interface{}{1, 2, "3", 4}
+ It("should power through even if the matcher ever fails", func() {
+ Ω([]interface{}{1, 2, "3", 4}).Should(ContainElement(BeNumerically(">=", 3)))
+ })
+
+ It("should fail if the matcher fails", func() {
+ actual := []interface{}{1, 2, "3", "4"}
success, err := (&ContainElementMatcher{Element: BeNumerically(">=", 3)}).Match(actual)
Ω(success).Should(BeFalse())
Ω(err).Should(HaveOccurred())