Skip to content

Instantly share code, notes, and snippets.

@MaherSaif
Forked from garybernhardt/gist:1390018
Created November 23, 2011 23:56
Show Gist options
  • Select an option

  • Save MaherSaif/1390282 to your computer and use it in GitHub Desktop.

Select an option

Save MaherSaif/1390282 to your computer and use it in GitHub Desktop.
# Make a user that we'll add a book to.
user = User.create!
controller.stub(:current_user) { user }
# This prints []. The book list is empty.
p user.books
# Expect a book to be added to the user. This fails (see below)
expect {
post :create, :id => asin
}.to change { user.books }.from([]).to([book])
# Failure/Error: expect {
# books should have initially been [], but was [#<Book id: 1, asin: "the-asin", title: "Hamlet", authors: "Bill Shakes", pages: 0, is_ebook: false, image_url: nil, icon_url: nil, details_url: "http://example.com/hamlet", created_at: "2011-11-23 21:47:45", updated_at: "2011-11-23 21:47:45", editorial_review: nil>]
# This seems wrong. `user.books` *is* initially []. Help? I'm running RSpec 2.7.1 on Ruby 1.8.7 and Rails 3.0.9. It also happens with RSpec 2.5.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment