Reputation: 2520
Why is only the (deprecated) #should
statement working for me?
The commented-out #expect
statements fail although they follow the example in the curriculum exactly.
require 'rails_helper'
describe Vote do
describe "validations" do
describe 'value validation' do
it "only allows -1 or 1 as values" do
vgood1 = Vote.create :value => 1
vgood2 = Vote.create :value => -1
vbad1 = Vote.create :value => 0
vbad2 = Vote.create :value => 2
vbad3 = Vote.create
expect (vgood1.valid?).should == true#eq(true)
# expect (vgood2.valid?).to eq(true)
# expect (vbad1.valid?).to eq(false)
# expect (vbad2.valid?).to eq(false)
# expect (vbad3.valid?).to eq(false)
end
end
end
end
Here is the example in the curriculum
Failures:
1) Vote validations value validation only allows -1 or 1 as values
Failure/Error: expect(bad_v.valid?).to eq(false)
expected: false
got: true
Upvotes: 0
Views: 47
Reputation: 6466
This looks like a whitespace error.
Because of implied parentheses, Ruby reads this:
expect (vgood2.valid?).to eq(true)
as this:
expect((vgood2.valid?).to eq(true))
In this latter case, (vgood2.valid?)
is the object that doesn't have a to
method defined on it.
Upvotes: 1