0

I want to require file all_class from file log_in_test.rb.

enter image description here

I tried all kinds of require and require_relative, for example

#require "../../ib4b-template/features/page-object/all_class" require_relative "page-object/all_class" 

and they are not working. Can anyone kindly give me a hand?

1
  • Are you running cucumber? Commented Oct 20, 2013 at 9:50

4 Answers 4

2

Try this:

require_relative 'all_class' # without 'page-object/' 

The most common way to solve this problem is using File.dirname(__FILE__):

require File.join(File.dirname(__FILE__), '..', 'all_class') 
Sign up to request clarification or add additional context in comments.

2 Comments

@nzsquall whats your ruby version?
@UnknownI am using ruby 2.0.0p247
1

Use

require_relative '../page_object/all_class' 

relative to support/log_in_test.rb, all_class.rb lies in above path.

require doesn't find if the directory structure is not in the Ruby's library path.

1 Comment

Hi @kiddorails, have error as: "H:\My H Drive\Workspace\ib4b-template\features>ruby log_in_test.rb log_in_test.rb:5:in require_relative': cannot load such file -- H:/My H Drive/Workspace/ib4b-template/page_object/all_class (LoadError) from log_in_test.rb:5:in <main>'"
1
require_relative './page_object/all_class.rb' 

or

require_relative './page_object/all_class' 

the '.rb' part is optional

You should use require_relative instead of require when you are working on a project and want to require one file from one of the directories into another.

You should use require to add gem libraries to your project.

Also, a good practice to use when working on a larger practice is to make a environment.rb file in the config folder and have that require all the the models and then having the executables requiring that environment file.

Comments

0
require File.join(File.dirname(__FILE__), '..', '..','page-object', 'all_class') 

1 Comment

Hi @Bala, have error as: "H:\My H Drive\Workspace\ib4b-template\features>ruby log_in_test.rb C:/Ruby200-x64/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in require': cannot load such file -- ./../../page-object/all_class (LoadError) from C:/Ruby200-x64/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in require' from log_in_test.rb:5:in `<main>'"

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.