Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'rails_helper'
- describe Product do
- context "when the product has comments" do
- before do
- @product = Product.create!(name: 'race bike')
- @user = User.create!(email: 'bob@bob.com', password: 'unitedfdfdf')
- @product.comments.create!(rating: 1, user: @user, body: "Awful bike!")
- @product.comments.create!(rating: 3, user: @user, body: "Really Awful bike!")
- @product.comments.create!(rating: 5, user: @user, body: "Really Really Awful bike!")
- end#before
- it "returns the average rating of all comments" do
- expect(@product.average_rating).to eq 3.0
- end
- context "when the product has no name" do
- before do
- @product = Product.build(description: "nice bike")
- end
- it 'is invalid' do
- expect(Product.build(description: "nice bike")).not_to be_valid
- end
- end
- end#context
- end#classProduct
- Message error on rspc is the following
- Failures:
- 1) Product when the product has comments when the product has no name is invalid
- Failure/Error: @product = Product.build(description: "nice bike")
- NoMethodError:
- undefined method `build' for #<Class:0x00000004fc20c0>
- # ./spec/models/product_spec.rb:17:in `block (4 levels) in <top (required)>'
- Finished in 0.41484 seconds (files took 4.2 seconds to load)
- 2 examples, 1 failure
- Failed examples:
- 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