0
を使用しているとき、私は現在、次のコードでエラーが発生しようとしています:防止例外ArgumentError RSpecのダブルス
class NasaController
attr_reader :plateau, :current_rover
def initialize(plateau:)
@plateau = plateau
@current_rover = []
end
def link_to_rover(robotic_rover)
raise ArgumentError, "#{robotic_rover.class}" unless robotic_rover.is_a? RoboticRover
@current_rover = robotic_rover
end
end
、それは働きます!すばらしいです!しかし........
私のテストは、次のとおりです。controller.link_to_rover(plateau)
RoboticRoverをリンクしていないため
describe NasaController do
subject(:controller) { described_class.new(plateau: plateau) }
let(:robotic_rover) do
double(:robotic_rover, #some_methods...)
end
let(:plateau) { double(:plateau, rover_landed: landed_rover) }
describe 'interacting with a rover' do
context 'when a RoboticRover is used' do
before { controller.link_to_rover(robotic_rover) }
it 'can create a link' do
expect(controller.current_rover).to eq robotic_rover
end
context 'when something other than a RoboticRover is used' do
it 'raises an error at #link_to_rover' do
expect { controller.link_to_rover(plateau) }.to raise_error 'Error!'
end
end
end
end
私の第二のテスト合格につながります。
しかし、controller.link_to_rover(robotic_rover)
もRoboticRoverではないため、最初は失敗します。これはRoboticRoverの倍数です。誰もこの問題を回避するためのガイダンスを持っていますか?