0

I am trying to create a gem, but when trying to load a module in test I get the following error. I used "Configurable Ruby gems: Custom error messages and testing" to set environment variables from users and that's where most of the code is from.

  1) Msg91sms::Configuration with configuration block returns the correct authkey
     Failure/Error: raise Errors::Configuration, "Msg94 auth key missing!" unless @authkey

     NameError:
       uninitialized constant Msg91sms::Configuration::Errors
     # ./lib/msg91sms/configuration.rb:10:in `authkey'
     # ./spec/msg91sms/configuration_spec.rb:7:in `block (3 levels) in <top (required)>'

but as per the folder structure and everything this should be Msg91sms::Errors::Configuration. I put only one here even though all tests are failing due to improper module loading.

The gem with this error can be found here: https://github.com/flyingboy007/msg91sms/tree/development

bundle exec rspec will throw all errors.

It should be something with naming or improper loading. But I can't figure out.

After following the answer by @sergio, I am now getting this error:

  1) Msg91sms::Configuration with configuration block returns the correct authkey
     Failure/Error: raise ::Msg91sms::Errors::Configuration, "Msg91 auth key missing!" unless @authkey

     NameError:
       uninitialized constant Msg91sms::Errors
     # ./lib/msg91sms/configuration.rb:10:in `authkey'
     # ./spec/msg91sms/configuration_spec.rb:7:in `block (3 levels) in <top (required)>'

Could someone tell me what am doing wrong here?

3
  • Is it Errors::Configuration or Configuration::Errors? Commented Jun 5, 2017 at 18:21
  • The folder structure is like Errors::Configuration but the error is showing like Configuration::Errors..Dont know why.. Commented Jun 5, 2017 at 18:23
  • module Msg94sms module Errors class Configuration < StandardError; end end end Commented Jun 5, 2017 at 18:24

1 Answer 1

2
raise Errors::Configuration, "Msg94 auth key missing!" unless @authkey

Use fully qualified name to help ruby lookup the class.

raise ::Msg91sms::Errors::Configuration, "Msg94 auth key missing!" unless @authkey

The folder structure is like Errors::Configuration but the error is showing like Configuration::Errors..Dont know why..

It's trying to find Errors::Configuration within Msg91sms::Configuration (the current scope at that point). But since there's no Msg91sms::Configuration::Errors, it fails with that message.

Sign up to request clarification or add additional context in comments.

5 Comments

looks like it was the issue there but now am getting a different error. Please see the update in the question. Thank you.
@Abhilash: that is indeed another error, but I'll give you a hint. The file with that class is not loaded. How can you make it loaded? How do you load files in ruby?
indeed matee.. Thanks a lot for the info and the hint
First was an error i didnt think of... I looked at every possible thing I know about like loading and naming. With your help when i solved I saw another error. But this time I stopped thinking as I thought it was something I didnt know about. But I was wrong again. I forget that simple thing..loading!!!! Thank you for the help.
@Abhilash: my pleasure :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.