所以我在rails中写了一个模块:
module SpecUtil
def login
visit tasks_path
click_link "Sign in"
current_path == log_in_path
fill_in "email", :with => @user.email
fill_in "password", :with => @user.password
click_button "Save changes"
current_path == tasks_path
page.should have_content "You have logged in!"
end
def create_comment
visit tasks_path
click_link @task.name
current_path == task_path(@task)
fill_in 'comment_comment', :with => 'I am a comment'
click_button 'Create Comment'
end
end
当我将 SpecUtil 包含到我的 rails 测试文件中时:
include SpecUtil
我得到错误
/home/adam/Documents/Aptana Studio 3 Workspace/StartPoint/spec/requests/categories_spec.rb:2:in `<top (required)>': uninitialized constant SpecUtil (NameError)
当我跑卫时会发生这种情况。文件 spec_util.rb 与测试存在于同一文件夹中......
为什么这会引起轰动?- 我在堆栈上读到,我包含模块的方式是正确的......