Ruby
rsepc mock 메소드 내부 확인
by yunexus
2023. 10. 23.
describe '#test_target_method' do
subject do
described_class.new.test_target_method
end
before do
travel_to('2020-01-01 00:00:00')
...
end
shared_examples '공통 테스트' do |sql|
it '확인 내용' do
allow(모듈::클래스).to receive(:new).and_return(test_class)
test_class.class.alias_method :original_method_name, :method_name
allow(test_class).to receive(:method_name) do |relation|
result = test_class.original_method_name(relation)
expect(result.to_sql).to eq(sql)
result
end
subject
end
end
let(:test_class) { 모듈::클래스.new }
context '테스트 조건' do
include_examples '공통 테스트', 'SELECT * FROM ...'
end
end