如题,这个该怎么对比呢,使用“==”等测试无法通过,详细可以看这个提问: http://stackoverflow.com/questions/13898826/ruby-rspec-possible-to-compare-the-content-of-two-objects
环境是在 rails 中 补充代码如下: 自己定义的类:
class HighChart
attr_accessor :chart, :title, :subtitle, ...
.
.
.
end
需要测试的方法:
module HighchartsHelper do
def get_highchart_object
.
.
.
highchart_object = HighChart.new(...)
end
end
Rspec 代码:
describe HighchartsHelper do
describe "#get_highchart_object" do
it "return highchart object" do
highchart_object = HighChart.new(...)
expect(helper.get_highchart_object).to eq(highchart_object)
end
end
end
HighChart.new() 创建的对象的内容(chart, title, subtitle 等)都是一样的