我在RSPEC中遇到此问题:be_true
并且be_false
似乎无法在Rspec 2.1
中使用。
这是我的课程Zombie
的规格文件:
规格/ 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
这是我拥有课程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
控制台:
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)>'
你能帮我解决这个问题吗?