Advertisement
Guest User

Untitled

a guest
Jan 19th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. require 'rails_helper'
  2. describe Product do
  3. context "when the product has comments" do
  4. before do
  5. @product = Product.create!(name: 'race bike')
  6. @user = User.create!(email: 'bob@bob.com', password: 'unitedfdfdf')
  7. @product.comments.create!(rating: 1, user: @user, body: "Awful bike!")
  8. @product.comments.create!(rating: 3, user: @user, body: "Really Awful bike!")
  9. @product.comments.create!(rating: 5, user: @user, body: "Really Really Awful bike!")
  10. end#before
  11. it "returns the average rating of all comments" do
  12. expect(@product.average_rating).to eq 3.0
  13. end
  14.  
  15. context "when the product has no name" do
  16. before do
  17. @product = Product.build(description: "nice bike")
  18. end
  19. it 'is invalid' do
  20. expect(Product.build(description: "nice bike")).not_to be_valid
  21. end
  22.  
  23. end
  24. end#context
  25. end#classProduct
  26.  
  27.  
  28.  
  29.  
  30. Message error on rspc is the following
  31. Failures:
  32.  
  33. 1) Product when the product has comments when the product has no name is invalid
  34. Failure/Error: @product = Product.build(description: "nice bike")
  35.  
  36. NoMethodError:
  37. undefined method `build' for #<Class:0x00000004fc20c0>
  38. # ./spec/models/product_spec.rb:17:in `block (4 levels) in <top (required)>'
  39.  
  40. Finished in 0.41484 seconds (files took 4.2 seconds to load)
  41. 2 examples, 1 failure
  42.  
  43. Failed examples:
  44.  
  45. rspec ./spec/models/product_spec.rb:19 # Product when the product has comments when the product has no name is invalid
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement