source

https://www.udemy.com/course/testing-ruby-with-rspec/

installation

gem install rspec

order

basics

  1. card
  2. context
  3. before after
  4. nested hook
  5. overwriting let

preventing code dup & reducing code

  1. implicit subject
  2. explicit subject
  3. described class
  4. one liner syntax
  5. shared examples
  6. shared context

built-in matchers

  1. not_to
  2. equality: eq, eql, equal, be
  3. comparison matchers
  4. predicate matches
  5. all matchers
  6. be matcher(truthy, falsy, nil)
  7. change matcher
  8. contain exactly (ignore order)
  9. start_with, end_with
  10. have_attribute
  11. include (substr, arr elt, keys, key-val)
  12. raise error
  13. respond to (check if class has method & #args)
  14. satisfy: custom predicate function
  15. not_to_spec
  16. compound expectations

mocking

  1. double()
  2. movie
  3. allow(double_or_real_obj).to receive(:method_name).with(matching_arg).and_return(a, b, c)
  4. matching arguments
  5. instance double (only can mock real methods)
  6. class double
  7. spies I (vs double)