ruby - RSPEC delivers a Name error on my vote spec -
i'm getting name error votes don't quite understand. it's supposed make sure votes values of 1 , -1. i've been receiving lot of nonameerrors in code pretty recently, i'm wondering how should go fixing problems these.
require 'rails_helper' describe vote def valid? (@vote == 1) || (@vote == -1) end describe "validations" before good_v = votes.new(value: 1) bad_v = votes.new(value: -1) no_v = votes.new(value: 2) end describe "value validation" "only allows -1 or 1 values" expect(good_v.valid?).to eq(true) expext(bad_v.valid?).to eq(true) expect(no_v.valid?).to eq(false) end end end end
it doesn't seem votes method i'm using create vote. wanted use good_v = @post.votes.create(value: 1)
, don't think that's working either.
clyde-browns-computer-2:bloccit clydiscope$ rspec spec/models/vote_spec.rb f failures: 1) vote validations value validation allows -1 or 1 values failure/error: expect(good_v.valid?).to eq(true) nameerror: undefined local variable or method `good_v' # <rspec::examplegroups::vote::validations::valuevalidation:0x007fdd4ad44700> # ./spec/models/vote_spec.rb:19:in `block (4 levels) in <top (required)>' finished in 0.00397 seconds (files took 1.68 seconds load) 1 example, 1 failure failed examples: rspec ./spec/models/vote_spec.rb:18 # vote validations value validation allows -1 or 1 values
there should place should defining something, not sure what's missing.
the errors codes make wrong.
before do
block set local variable in describe
block can not use it.
change code to:
before @good_v = votes.new(value: 1) @bad_v = votes.new(value: -1) @no_v = votes.new(value: 2) end
then use these instance variable in test case.
Comments
Post a Comment