I am testing a web application with ruby, rspec, capybara and selenium and i ran into an uninitialized constant ActiveAdminLoginPage
Exception that i don't know how to solve.
In spec_helper.rb i am requiring the following:
Dir[File.join(Dir.pwd, 'spec/page_objects/**/*.rb')].each { |f| require f }
I have 2 classes
spec/page_objects/products/active_admin_login_page.rb
module Products
class ActiveAdminLoginPage < ::ActiveAdminLoginPage
...
end
end
inherits from
spec/page_objects/active_admin_login_page.rb
unfortunately the sub class is loaded before the parent class.
How do i create a autoload command dynamically from all filenames in a directory? I would like to replace this command:
Dir[File.join(Dir.pwd, 'spec/page_objects/**/*.rb')].each { |f| require f }
with a autoload command.
How about you use require
to load your dependency in the file that needs it?
require
loads a file only once, so you shouldn't encounter any side effects.
Or, even better, you can use auto_load
, which uses require
under the hood, but it does it in a smarter way
autoload :ActiveAdminLoginPage, 'active_admin_login_page'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With