gpt4 book ai didi

ruby-on-rails - Rspec & rails : undefined method `to' for true:TrueClass

转载 作者:行者123 更新时间:2023-12-02 15:23:35 27 4
gpt4 key购买 nike

我正在尝试测试我的 bool 字符串方法之一,但出现以下错误:

undefined method `to' for true:TrueClass
describe 'is_tall?' do

it "should return true for a tall user" do
expect(tall_user_string.is_tall?.to be_truthy)
end

it "should return false for a short user" do
expect(user_string.is_tall?.to be_falsey)
end

end

有什么想法吗?

最佳答案

to 调用应该跟在 expect() 之后,而不是真正的方法。改变

describe 'is_tall?' do

it "should return true for a tall user" do
expect(tall_user_string.is_tall?.to be_truthy)
end

it "should return false for a short user" do
expect(user_string.is_tall?.to be_falsey)
end

end

describe 'is_tall?' do

it "should return true for a tall user" do
expect(tall_user_string.is_tall?).to be_truthy
end

it "should return false for a short user" do
expect(user_string.is_tall?).to be_falsey
end

end

关于ruby-on-rails - Rspec & rails : undefined method `to' for true:TrueClass,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32684063/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com