0

这是我的测试:

# 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>

知道为什么我的存根不起作用吗?

4

1 回答 1

1
# Custom validation method tests
describe "#ticker_symbol" do
  let(:stubbed_response) { OpenStruct.new(:body => '') }
  before(:each) do
    Curl.stub(:get).and_return stubbed_response
  end
  it "should add an error" do
    subject
  end
end
于 2013-11-03T19:56:57.300 回答