Reputation: 12933
So I wrote a module as such in 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
How ever when I include SpecUtil into my rails test file as such:
include SpecUtil
I get the error
/home/adam/Documents/Aptana Studio 3 Workspace/StartPoint/spec/requests/categories_spec.rb:2:in `<top (required)>': uninitialized constant SpecUtil (NameError)
This happens when I run guard. The file spec_util.rb exists in the same folder as the tests....
why is this spazzing out? - I read on stack that, the way I am including modules is correct...
Upvotes: 1
Views: 73
Reputation: 3462
Usually utility modules like this are put into spec/support
directory. Make sure that your spec/spec_helper.rb
has code which loads support files:
# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
and move your module to spec/support/spec_util.rb
Upvotes: 1