1
我正在編寫一個RSpec規範來測試一個Rails助手。問題是我測試的幫助器方法取決於在另一個幫助器中定義的方法。這對我來說可能是一種代碼味道,但是我正在爲遺留代碼添加測試,而不是我可以重構的點。我如何測試這個Rails幫助器?如何測試依賴於另一個Rails助手的Rails助手?
module FancyHelper
def fancy_method
html = "hello"
html << another_fancy_method
html
end
end
module OtherHelper
def another_fancy_method
"world"
end
end
require "spec_helper"
describe FancyHelper do
describe "#fancy_method" do
it "does what it's supposed to" do
helper.fancy_method.should match("hello")
# NoMethodError: undefined method `another_fancy_method'
end
end
end
該doc鏈接適用於舊版本的RSpec。 [這是當前版本。](https://www.relishapp.com/rspec/rspec-mocks/docs/method-stubs) – Grantovich