Instance defined under child class returning nil and RSpec: no implicit
conversion from nil to integer
I have below code where action class is being returned after require
Robot Class
attr_accessor :action
def initialize
@action = Actions.new
end
def left
@action.left
end
Now Action class uses Direction::Move.new instance which is defined under
initialize method.
Actions Class
def place(x_coordinate, y_coordinate, direction = :north)
@x_coordinate = x_coordinate
@y_coordinate = y_coordinate
@direction = direction
@report.log_position(x_coordinate, y_coordinate, direction) if
x_coordinate.between?(@board.left_limit, @board.right_limit) &&
y_coordinate.between?(@board.bottom_limit, @board.top_limit) &&
@move.directions.grep(direction).present?
end
def left
@move.left(direction)
end
I have now defined Actions class with place method so direction gets
allocated to attr_accessor then robot.left is called
describe '#left' do
it 'should turn left' do
action.place(0, 0, Direction::North)
expect(robot.left).to eq(Direction::West)
end
end
But when I do Rspec test, it returns below error:
RSpec: no implicit conversion from nil to integer
Why robot.left which is calling action.left doesn't allow direction to be
passed over to this action.left method?
No comments:
Post a Comment