ALL HOW TOs




Installing Notes


Arrays
expect([1,2,3]).to eq [1,2,3]           # ORDERED
expect([1,2,3]).to match_array [3,2,1]  # UNORDERED


Pattern Matching with REGEX
expect("foobar").to match /oba/

# Adding a variable's value to the pattern string
x=bar
expect("foobar").to match /foo#{Regexp.quote(x)}/

# Testing for " inside a string
x="{\"id\": 3}"
expect(x).to match /{\"id\": 3}/   
# NOTE: This pattern will fail at http://rubular.com/.  It requires /{\\\"id\\\":3}/

# Testing for / inside a string
x="http://www.example.com/message"
expect(x).to match /http:\/\/www.example.com\/message/

Test patterns at...  http://rubular.com/


Testing for true/false
expect(actual).to be_truthy  # passes if actual is truthy (not nil or false) 
expect(actual).to be true    # passes if actual == true 
expect(actual).to be_falsy   # passes if actual is falsy (nil or false) 
expect(actual).to be false   # passes if actual == false 
expect(actual).to be_nil     # passes if actual is nil 
expect(actual).to_not be_nil # passes if actual is not nil



  • No labels