cluv
cluv

Reputation: 620

basic rspec test not passing

Would appreciate if someone could tell me why this won't pass, it's getting nil instead of value

class Hello
  def hi
    puts "hello"
  end
end


describe Hello do

  before do
    @obj = Hello.new
  end

  describe "#hi" do
    it "should say hello" do
      @obj.hi.should == "hello"
    end
  end

end

Upvotes: 0

Views: 55

Answers (3)

B Seven
B Seven

Reputation: 45941

Because puts always returns nil, #hi always returns nil.

Change it to:

class Hello
  def hi
    "hello"
  end
end

Upvotes: 3

namxam
namxam

Reputation: 96

I haven't tested it, but you should also be able to test against $stdout. It should receive the

Upvotes: 0

x1a4
x1a4

Reputation: 19496

puts just outputs the string, but returns nil as the value, so hi is just returning that nil value.

Upvotes: 2

Related Questions