这是我的测试:
# Custom validation method tests
describe "#ticker_symbol" do
before(:each) do
o = OpenStruct.new(:body => '')
Curl::Easy.any_instance.stub(:get).and_return(o)
end
it "should add an error" do
subject
end
end
我的模型的相关部分:
# Custom validation methods
def ticker_symbol
apiresponse = Curl.get("https://www.google.com/finance/info?infotype=infoquoteall&q=" + ticker)
debugger
if apiresponse.body == ''
errors.add(:ticker, "must be valid")
end
end
出于某种原因,apiresponse 不应该是这样的:
apiresponse
#<Curl::Easy https://www.google.com/finance/info?infotype=infoq>
知道为什么我的存根不起作用吗?