我正在开发Rails 3.1.1, Ruby 1.9.2并使用Rspec2进行测试。
在helper中存根不起作用。
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)>'
存根在控制器和视图中工作正常,但在helper中不起作用。
什么好主意吗?
我已经解决了
require 'spec_helper'
describe UsersHelper do
describe 'test' do
before do
helper.stub(:val).and_return('this is test')
end
it 'returns val' do
helper.test.should eql 'this is test'
# helper. is required.
end
end
end
帮手。测试工作得很好。
#199:不能存根方法调用的帮助-问题- rspec/spec-rails - GitHub