command be_true seems not to work in Rspec 2.1

只谈情不闲聊 提交于 2019-12-11 17:47:12

问题


I have this problem in RSPEC: be_true and be_false seems not to be working in Rspec 2.1.

This is my specs file for the class Zombie:

spec/lib/zombie_spec.rb

require "spec_helper"
require "zombie"

describe "A Zombie" do
# your examples (tests) go here
 it "is named Ash" do
  zombie=Zombie.new
  zombie.name.should=="Ash"
 end

 it "has no brains" do
   zombie= Zombie.new
   #zombie.brains.should < 1
   zombie.brains.should be <1

 end


  it "is alive" do
   zombie=Zombie.new
   zombie.alive.should==false
  end

  it "is hungry" do
   zombie=Zombie.new
   #zombie.hungry?.should==true  Working correct
    zombie.hungry?.should be_true  # Not working 

  end
end

This is the file where I have the class Zombie: lib/zombie.rb

class Zombie 
 attr_accessor :name,:brains,:alive
 def initialize
    @name="Ash"     
    @brains=0
    @alive=false
 end

 def hungry?
   true
 end
end

Console:

fernando:~/estudio/Zombies$ rspec spec/lib/zombie_spec.rb ...F

Failures:

  1) A Zombie is hungry
     Failure/Error: zombie.hungry?.should be_true
       expected true to respond to 'true'?
     # ./spec/lib/zombie_spec.rb:25:in `block (2 levels) in <top (required)>'

Can you help me with this problem?

来源:https://stackoverflow.com/questions/24995582/command-be-true-seems-not-to-work-in-rspec-2-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!