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?
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.
Related
I'm using TestRails to log failures in our automated test suite. Example failures have output like this:
Failures:
1) can click on the Photos button after logging in
Failure/Error: login.signin_btn.click
NoMethodError:
undefined method `click' for nil:NilClass
# /Users/kkrzeminski/TestApp/Appium/Common/pages_helper.rb:36:in `click'
# ./test_1_spec.rb:9:in `block (2 levels) in <top (required)>'
I can grab the exception using example.exception in the after(:each) block in my spec_helper, as well as the backtrace, but what I'm really interested is that line beginning with Failure/Error:. I can't seem to find a way to get that string. It would be handy for logging the reason for test failure in TestRails, as just the exception and the backtrace aren't very descriptive.
It sounds like what you really want is a custom formatter for your CI environment. The protocol for RSpec formatters provides an example_failed hook which will give you the example object.
You can then use Example and Notifications objects to gather the information you are desire.
I am using the Devise Gem in version 3.2.2 for authentication in my Rails 3.2.17 app. Now I am building an API and securing it with devise using the method suggested in this Gist.
Now when I am doing a get request on a secured controller using curl (in this case with a UI) I get a 200 and the response I was looking for. For some reasons my tests fail and produce an error like this:
1) Api::V1::UsersController#information should get the dancing partner
Failure/Error: get :information, {}
NoMethodError:
undefined method `user' for nil:NilClass
# ./app/controllers/api/v1/api_controller.rb:26:in `authenticate_user_from_token!'
# ./spec/controllers/api/users_controller_spec.rb:24:in `block (3 levels) in <top (required)>'
I don't know if this is an issue caused by devise or by something else, so I attached all changed code at the bottom of this post.
Here is an example how it should work:
This is my Api controller, which should secure the normal controllers used for the api.
This is my secured controller
Here are my tests
This is my authentication helper
This is my test helper
The complete output of log/test.log
I just figured out, that this error came from accessing the user variable at a point, where I was testing the response for an invalid authentication.
Not quite sure what's going on here. I'm moving over some code from another project of mine and suddenly the same specs from before are generating errors in the new project. All the errors appear to revolve around calling the stub method. Here's an example test:
it "retrieves active workers from Redis" do
#monitor.should_receive(:monitor_running?).and_return(false)
REDIS.should_receive( :smembers ).with( 'leaderboard-workers' ).and_return( [] )
#monitor.perform
end
This works. However if I switch the first test line to this:
#monitor.stub(:monitor_running?).and_return(false)
I end up with the following error:
1) LeaderboardMonitor#perform retrieves active workers from Redis
Failure/Error: #monitor.stub(:monitor_running?).and_return(false)
Mocha::ExpectationError:
unexpected invocation: #<Mock:0x7fcc18c8bab8>.and_return(false)
satisfied expectations:
- allowed any number of times, not yet invoked: #<Mock:0x7fcc18c8bab8>.monitor_running?(any_parameters)
# ./spec/workers/leaderboards/leaderboard_monitor_spec.rb:58:in `block (3 levels) in <top (required)>'
I'm not quite sure what's going on here. Is this an issue with Mocha overriding the stub method? How do I work around this?!?!?
I don't know what version of mocha you are using. Have you tried something like
#monitor.expects(:monitor_running?).returns(false).at_least_once
Hello i am receiving this error:
spec/models/stores/persistent_spec.rb:6:in block (2 levels) in <top
(required)>': undefined methodexpect' for #
(NoMethodError)
Here is my setup. i have a class called Store located inside app/models
i have a class called Stores::Temporary < Store placed inside app/models/stores
I am trying to write tests for Temporary and they are failing with the error above
i have created temporary_spec.rb inside spec/models/stores and the code for it is the following:
require "spec_helper"
describe Stores::Temporary do
end
i am trying to write an expect to raise_error statement.
I have also tried 5.should == 5 which results with no available test being detected inside this file. I am using guard to autorun the tests, so changes in the files are being detected (works correctly) and tests are rerun but appear as blank.
So after struggling with this for 2 hours i restarted the PC and it was working without changing anything... One of those stupid errors you just need to sorta sleep-over and retry.
When I run rspec on my rails project I get a very annoying error message, although exact the same code worked before. The only thing I did was adding a new rspec file. Now the new rspec file doesn't contain anything except for "require 'spec_helper'" but I still get this message (and a few others...):
1) Home Page should have 'Lists' and 'Students' links
Failure/Error: visit home_path
NameError:
undefined local variable or method home_path' for > #<RSpec::Core::ExampleGroup::Nested_2:0x00000004c455a0>
# ./spec/requests/homes_spec.rb:5:inblock (2 levels) in '
I have no idea what to do now. Has anyone a clue what's the matter with it?
Thanks
According to your routes proper helper would be home_index_path.
Try to use it.