3
我正在開發Rails 3.1.1,Ruby 1.9.2並使用Rspec2進行測試。
助手中的殘肢不能工作。rspec helper.stub不起作用
users_helper_spec.rb
require 'spec_helper'
describe UsersHelper do
describe 'test' do
before do
helper.stub(:val).and_return('this is test')
end
it 'returns val' do
test.should eql 'this is test'
end
end
end
user_helper.rb
module UsersHelper
def test
return val
end
end
錯誤
1) UsersHelper test test
Failure/Error: test.should eql 'this is test'
NameError:
undefined local variable or method `val' for #<RSpec::Core::ExampleGroup::Nested_15::Nested_1:0x007f9ad5f42a50>
# ./app/helpers/users_helper.rb:3:in `test'
# ./spec/helpers/users_helper_spec.rb:10:in `block (3 levels) in <top (required)>'
在共同成株ntroller和視圖正常工作,但在幫手中它不起作用。
任何想法?
在此先感謝。
你爲什麼要扼殺你試圖測試的價值?這似乎沒有道理。如果你能向我們展示一些實際的代碼而不是一個人爲的例子,或許我們可以幫助更多......另外,它可能更易於使用'=='而不是'eql'。 –
感謝您的回覆。我認爲這是顯示問題的最簡單方法,並且問題不取決於另一個代碼是什麼。 – DIGITALSQUAD
但事實並非如此。由於我們無法看到您的實際代碼,因此我們無法猜測發生了什麼。請提供您的實際代碼。 –