だから私は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は、テストと同じフォルダーにあります。
なぜこれが飛び散るのですか?-スタックで読んだのですが、モジュールを含める方法は正しいです...