github.com/jasonkeene/cli@v6.14.1-0.20160816203908-ca5715166dfb+incompatible/testhelpers/matchers/be_in_display_order_test.go (about)

     1  package matchers_test
     2  
     3  import (
     4  	"strings"
     5  
     6  	. "github.com/cloudfoundry/cli/testhelpers/matchers"
     7  
     8  	. "github.com/onsi/ginkgo"
     9  	. "github.com/onsi/gomega"
    10  )
    11  
    12  var _ = Describe("BeInDisplayOrder()", func() {
    13  	var (
    14  		matcher OmegaMatcher
    15  		actual  []string
    16  	)
    17  
    18  	actual = []string{
    19  		"1st line 1",
    20  		"2nd line 2",
    21  		"3rd line 3",
    22  		"4th line 4",
    23  	}
    24  
    25  	It("asserts actual is in same display order with expected", func() {
    26  		matcher = BeInDisplayOrder(
    27  			[]string{"1st"},
    28  			[]string{"2nd"},
    29  			[]string{"3rd"},
    30  			[]string{"4th"},
    31  		)
    32  
    33  		success, err := matcher.Match(actual)
    34  		Expect(success).To(Equal(true))
    35  		Expect(err).To(BeNil())
    36  
    37  		matcher = BeInDisplayOrder(
    38  			[]string{"1st"},
    39  			[]string{"3rd"},
    40  			[]string{"2nd"},
    41  			[]string{"4th"},
    42  		)
    43  
    44  		success, err = matcher.Match(actual)
    45  		Expect(success).To(Equal(false))
    46  		Expect(err).To(BeNil())
    47  		msg := matcher.FailureMessage([]string{})
    48  		Expect(strings.Contains(msg, "2nd")).To(Equal(true))
    49  	})
    50  
    51  	It("asserts actual contains the expected string", func() {
    52  		matcher = BeInDisplayOrder(
    53  			[]string{"Not in the actual"},
    54  		)
    55  
    56  		success, err := matcher.Match(actual)
    57  		Expect(success).To(Equal(false))
    58  		Expect(err).To(BeNil())
    59  
    60  		msg := matcher.FailureMessage([]string{})
    61  		Expect(strings.Contains(msg, "Not in the actual")).To(Equal(true))
    62  	})
    63  
    64  	It("asserts actual contains 2 substrings in the same display line ", func() {
    65  		matcher = BeInDisplayOrder(
    66  			[]string{"1st", "line"},
    67  			[]string{"4th", "line"},
    68  		)
    69  
    70  		success, err := matcher.Match(actual)
    71  		Expect(success).To(Equal(true))
    72  		Expect(err).To(BeNil())
    73  
    74  		matcher = BeInDisplayOrder(
    75  			[]string{"1st", "line 2"},
    76  		)
    77  
    78  		success, err = matcher.Match(actual)
    79  		Expect(success).To(Equal(false))
    80  
    81  		msg := matcher.FailureMessage([]string{})
    82  		Expect(strings.Contains(msg, "line 2")).To(Equal(true))
    83  
    84  		matcher = BeInDisplayOrder(
    85  			[]string{"1st"},
    86  			[]string{"line 1"},
    87  		)
    88  
    89  		success, err = matcher.Match(actual)
    90  		Expect(err).ToNot(HaveOccurred())
    91  		Expect(success).To(Equal(false))
    92  
    93  		msg = matcher.FailureMessage([]string{})
    94  		Expect(strings.Contains(msg, "line 1")).To(Equal(true))
    95  	})
    96  
    97  	It("asserts actual contains 2 substrings displaying in order on a single line ", func() {
    98  		matcher = BeInDisplayOrder(
    99  			[]string{"1st", "line 1"},
   100  		)
   101  
   102  		success, err := matcher.Match(actual)
   103  		Expect(success).To(Equal(true))
   104  		Expect(err).To(BeNil())
   105  
   106  		matcher = BeInDisplayOrder(
   107  			[]string{"line 1", "1st"},
   108  		)
   109  
   110  		success, err = matcher.Match(actual)
   111  		Expect(err).ToNot(HaveOccurred())
   112  		Expect(success).To(Equal(false))
   113  
   114  		msg := matcher.FailureMessage([]string{})
   115  		Expect(strings.Contains(msg, "1st")).To(Equal(true))
   116  	})
   117  
   118  })