Skip to content

Instantly share code, notes, and snippets.

@giedriusr
Last active August 29, 2015 14:15
Show Gist options
  • Save giedriusr/185389594cdff292bd6c to your computer and use it in GitHub Desktop.
Save giedriusr/185389594cdff292bd6c to your computer and use it in GitHub Desktop.
rspec 3.0
# Documentation
# https://relishapp.com/rspec/rspec-expectations/v/3-0/docs/built-in-matchers
# expect(actual).to exist # passes if actual.exist? and/or actual.exists? are truthy
### Class
Member < ActiveRecord:Base
end
### Specs
# wrong
member = Member.find_by(group_id: group_id)
expect(member).to exist
Failure/Error: expect(member).to exist
expected #<Member ..> to exist but it does not respond to either `exist?` or `exists?`
# correct
member = Member.where(group_id: group_id)
expect(member).to exist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment