我正在使用 jruby(9.1.12.0) 和 rspec-rails(3.7.0)。
我有以下方法
class AddressCreator
include Singleton
attr_reader :client
def initialize
@client = SomeJavaClass.new(some keys go here)
end
end
# SomeJavaClass has an create_address instance method.
def create_address(user_id, address)
req = Java::RandomRequest.new(user_id, address)
resp = Java::RandomResponse.new(default_response_params)
AddressCreator.instance.client.create_address(some_key, req, resp)
end
并添加了相同的测试
describe '#create_address' do
let(:some_key) { SecureRandom.uuid }
let(:user_id) { 1 }
let(:default_response_params) { false }
let(:address) { 'some address goes here' }
let(:request) { Java::RandomRequest.new(address)}
let(:response) { Java::RandomResponse.new(default_response_params)}
before {allow(AddressCreator.instance.client).to receive(:create_address).with(some_key, request, response).and_return(response)}
it 'should create the address' do
result = AddressCreator.instance.client.create_address some_key
expect(AddressCreator.singleton).to have_received(:create_address).with(some_key, request, response) do |request|
expect(request.is_success).to eq(response.is_success)
end
expect(result).to eq(response)
end
end
我的规格未能说明
expected <Java::RandomRequest:0x1d09fb8e>
got <Java::RandomRequest:0x38482732>
我们如何模拟以便我们收到相同的实例?