Reputation: 5073
I'm trying to test one of my boolean string methods but I am getting the bellow error:
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
Any ideas?
Upvotes: 2
Views: 3600
Reputation: 7482
You have a small typo, you need to close parentheses earlier:
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
And if you like William Shakespeare you can also write it like this:
describe 'is_tall?' do
it "should return true for a tall user" do
expect(tall_user_string.is_tall?).to be
end
it "should return false for a short user" do
expect(user_string.is_tall?).not_to be
end
end
Upvotes: 3
Reputation: 176532
The to
call should follow the expect()
, not the real method. Change
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
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
Upvotes: 4