I would be very grateful for some advice on the following.
Below I have a simplified example for our setup.
I have defined some Helper modules on our RSpec test suite:
## spec/rails_helper.rb
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
RSpec.configure do |config|
config.include ViewHelpers
end
### spec/support/view_helpers/base.rb
# frozen_string_literal: true
module ViewHelpers
class Base
# class content
end
end
### spec/support/view_helpers/admins/payments/new.rb
# frozen_string_literal: true
module ViewHelpers
module Admins
module Payments
class New < Base
# class content
end
end
end
end
With this setup the specs run perfectly locally; the sub-class New
inherits from Base
as expected. However, when the tests are running on Travis CI, we get the following error:
NameError:
1433 uninitialized constant ViewHelpers::Admins::Payments::Base
1434# ./spec/support/view_helpers/admins/payments/new.rb:6:in `<module:Payments>'
1435# ./spec/support/view_helpers/admins/payments/new.rb:5:in `<module:Admins>'
1436# ./spec/support/view_helpers/admins/payments/new.rb:4:in `<module:ViewHelpers>'
1437# ./spec/support/view_helpers/admins/payments/new.rb:3:in `<top (required)>'
1438# ./spec/rails_helper.rb:34:in `block in <top (required)>'
1439# ./spec/rails_helper.rb:34:in `each'
1440# ./spec/rails_helper.rb:34:in `<top (required)>'
1441# ./spec/controllers/admins/billpayers_controller_spec.rb:3:in `<top (required)>'
I have also tried inheriting with explicit namespacing:
# frozen_string_literal: true
module ViewHelpers
module Admins
module Payments
class New < ViewHelpers::Base
# class content
end
end
end
end
Again, this runs successfully locally but Travis CI errors:
NameError:
1433 uninitialized constant ViewHelpers::Base
1434# ./spec/support/view_helpers/admins/payments/new.rb:6:in `<module:Payments>'
1435# ./spec/support/view_helpers/admins/payments/new.rb:5:in `<module:Admins>'
1436# ./spec/support/view_helpers/admins/payments/new.rb:4:in `<module:ViewHelpers>'
1437# ./spec/support/view_helpers/admins/payments/new.rb:3:in `<top (required)>'
1438# ./spec/rails_helper.rb:34:in `block in <top (required)>'
1439# ./spec/rails_helper.rb:34:in `each'
1440# ./spec/rails_helper.rb:34:in `<top (required)>'
1441# ./spec/controllers/admins/billpayers_controller_spec.rb:3:in `<top (required)>'
I am rather stumped as to why this works locally but not on CI. Would be very grateful for any support and insight.
Thanks Sam