Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
420 views
in Technique[技术] by (71.8m points)

ruby on rails - command be_true seems not to work in Rspec 2.1

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...