Reputation: 13
Not sure if my syntax is right, it doesn't seem to recognise the stub I've passed to my double.
class Robot
def boogie friend
friend.dances
end
end
Test:
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
And the error:
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)>'
Can anyone see what I'm doing wrong?
Upvotes: 1
Views: 225
Reputation: 5479
This will work, you need to pass the object and not a symbol.
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
Upvotes: 1