命令be_true似乎不适用于Rspec 2.1

时间:2014-07-28 12:47:05

标签: ruby-on-rails ruby ruby-on-rails-3 rspec rspec2

我在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)>'

你能帮我解决这个问题吗?

0 个答案:

没有答案