Rspec双返回NoMethodError

时间:2015-07-26 11:51:12

标签: ruby testing rspec

不确定我的语法是否正确,它似乎没有识别我传递给我的双重存根。

class Robot
  def boogie friend
    friend.dances
  end
end

测试:

describe Robot do

let(:robo_friend){double(:friend, {dances: true})}

  it "should have a friend dance too" do
    expect(subject.boogie :robo_friend).to be true
  end

end

错误:

Robot should have a friend dance too
 Failure/Error: expect(subject.boogie :robo_friend).to be true
 NoMethodError:
   undefined method `dances' for :robo_friend:Symbol
 # ./lib/robot.rb:3:in `boogie'
 # ./spec/robot_spec.rb:8:in `block (2 levels) in <top (required)>'

谁能看到我做错了什么?

1 个答案:

答案 0 :(得分:1)

这将有效,您需要传递对象而不是符号。

describe Robot do
  let(:robo_friend) { double("Friend", dances: true) }

  it "should have a friend dance too" do
    expect(subject.boogie(robo_friend).to eq(true)
  end
end