Bug #12410
closedDocumentation on running a single test is not working
Description
As per this webpage,
http://theforeman.org/contribute.html#Setuptestenvironment
To run a single test, you have to run:
ruby -Itest test/functional/your_test.rb
But that doesn't seem to work:
$ ruby -Itest test/unit/orchestration/dhcp_test.rb
/home/pphilip/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- spork (LoadError)
from /home/pphilip/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /home/pphilip/git/foreman/foreman/test/test_helper.rb:2:in `<top (required)>'
from /home/pphilip/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /home/pphilip/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from test/unit/orchestration/dhcp_test.rb:1:in `<main>'
Is this something wrong with my environment?
Instead, this works for me, but it seems like the tests are being executed twice.
$ rake test TEST=test/unit/orchestration/dhcp_test.rb 2015-11-05T20:42:32 [app] [I] Connecting to database specified by database.yml The Apipie cache is turned off. Enable it and run apipie:cache rake task to speed up API calls. The Apipie cache is turned off. Enable it and run apipie:cache rake task to speed up API calls. Run options: --seed 34785 # Running tests: Finished tests in 0.001123s, 0.0000 tests/s, 0.0000 assertions/s. 0 tests, 0 assertions, 0 failures, 0 errors, 0 skips Loaded suite /home/pphilip/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/rake_test_loader Started ...............[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message. .... Finished in 4.82911997 seconds. 19 tests, 64 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications 0% passed 3.93 tests/s, 13.25 assertions/s Coverage report generated for Unit Tests to /home/pphilip/git/foreman/foreman/coverage. 57881 / 130558 LOC (44.33%) covered. /home/pphilip/.rvm/rubies/ruby-2.2.2/bin/ruby -I"lib:test" -I"/home/pphilip/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0" "/home/pphilip/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/rake_test_loader.rb" "test/unit/orchestration/dhcp_test.rb" /home/pphilip/git/foreman/foreman/test/test_runner.rb The Apipie cache is turned off. Enable it and run apipie:cache rake task to speed up API calls. Run options: --seed 34495 # Running tests: Finished tests in 0.001173s, 0.0000 tests/s, 0.0000 assertions/s. 0 tests, 0 assertions, 0 failures, 0 errors, 0 skips Loaded suite /home/pphilip/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/rake/rake_test_loader Started ...............[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message. .... Finished in 4.805871891 seconds. 19 tests, 64 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications 0% passed 3.95 tests/s, 13.32 assertions/s Coverage report generated for Unit Tests to /home/pphilip/git/foreman/foreman/coverage. 57912 / 130558 LOC (44.36%) covered.
Let me know the right way to run a single test and I'll fix the documentation.
-PP
Updated by Dominic Cleal about 10 years ago
- Description updated (diff)
- Category set to Tests
Updated by Dominic Cleal about 10 years ago
Can you try prefixing the first ruby command with "bundle exec" which might help with loading?
bundle exec be ruby -Itest test/unit/orchestration/dhcp_test.rb
I have no idea why that second command is running tests twice, most bizarre. I always use the first style.
We also have the single_test gem in our bundler.d/test.rb stack, but I don't think it's active (missing the require line?) because these don't work for me: https://github.com/grosser/single_test#usage
Updated by Phirince Philip about 10 years ago
Ok, prepending "bundle exec" worked for me!
Shall I fix the documentation to reflect this?
Probably, it's safer to do "bundle exec rake test" as well?
-PP
Dominic Cleal wrote:
Can you try prefixing the first ruby command with "bundle exec" which might help with loading?
bundle exec be ruby -Itest test/unit/orchestration/dhcp_test.rb
I have no idea why that second command is running tests twice, most bizarre. I always use the first style.
We also have the single_test gem in our bundler.d/test.rb stack, but I don't think it's active (missing the require line?) because these don't work for me: https://github.com/grosser/single_test#usage
Updated by Dominic Cleal about 10 years ago
- Project changed from Foreman to Website
- Category deleted (
Tests)
Phirince Philip wrote:
Ok, prepending "bundle exec" worked for me!
Shall I fix the documentation to reflect this?
Thanks, that'd be good.
Probably, it's safer to do "bundle exec rake test" as well?
Yes, it would. I think sometimes certain rvm-type setups mean you can leave it out and it activates bundler automatically or something, but it's certainly safer to use it as a rule.
Updated by Anonymous over 9 years ago
- Status changed from New to Ready For Testing
- Assignee changed from Phirince Philip to Anonymous
- Pull request https://github.com/theforeman/theforeman.org/pull/603 added
Updated by Anonymous over 9 years ago
- Status changed from Ready For Testing to Closed
- % Done changed from 0 to 100
Applied in changeset theforemanorg|6bc24ab3d50ac0bf306b73146db343060b2a66a2.