我正在尝试测试一个线程。假设客户,地点,消息都在上面的代码中,但是发布起来会很长。我正在尝试测试“消息”变量,但由于它不是实例变量并且它位于线程内,因此我无法很容易地对其进行测试。我假设存根线程将是使用 rspec 测试它的正确途径,但是如果您对如何准确测试“消息”变量有任何其他建议,那将非常有帮助。这是我正在做的基本版本:
Class Messages def order_now conf = venue.confirmation_message message = "Hi #{customer.first_name}, " if conf && conf.present? message << conf else message << "your order has been received and will be ready shortly." end Thread.new do ActiveRecord::Base.connection_pool.with_connection do Conversation.start(customer, venue, message, {:from_system => true}) end ActiveRecord::Base.connection_pool.clear_stale_cached_connections! end end end
先感谢您!