Pass test arguments via my Rake::TestTask . What am I doing wrong?

343 views Asked by At

I have a Rakefile defined with code like so:

namespace :app do |args|    
  desc "Run App tests from lib/app_tests/test_*.rb"
  Rake::TestTask.new do |t,args|
    t.name = "testApp"
    t.libs << 'lib/pageobjects/app_page_objects'
    t.test_files = FileList['lib/app_tests/test_*.rb']
    #t.options - passing on command line see below
    t.verbose = true
  end   
... 

But, when I run the task, it treats the TESTOPTS args as if they are additional tests that the test runner wants to run. What I want is for each test in t.test_files, pass the 3 arguments to each test. The main error I see is:

cannot load such file -- c:/Users/me/IdeaProjects/impl/util/PROJECT/testclient

Why is Rake treating my TESTOPTS like they are additional items in the t.test_files FileList object? With my experience with JUnit, this seems unusual to me.

And here is the console output:

$ rake app:testapp TESTOPTS="testclient impdev app"
c:/Ruby22-x64/bin/ruby.exe -I"lib;lib/pageobjects/app_page_objects"  "c:/Ruby22-x64/lib/ruby/2.2.0/rake/rake_test_loader.rb" "lib/app_tests/test_1.rb" "lib/app_tests/test_2.rb" testclient impdev app
Current dir is : c:/Users/me/IdeaProjects/impl/util/PROJECT
c:/Ruby22-x64/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- c:/Users/me/IdeaProjects/impl/util/PROJECT/testclient (LoadError)
        from c:/Ruby22-x64/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        from c:/Ruby22-x64/lib/ruby/2.2.0/rake/rake_test_loader.rb:15:in `block in <main>'
        from c:/Ruby22-x64/lib/ruby/2.2.0/rake/rake_test_loader.rb:4:in `select'
        from c:/Ruby22-x64/lib/ruby/2.2.0/rake/rake_test_loader.rb:4:in `<main>'
rake aborted!
Command failed with status (1): [ruby -I"lib;lib/pageobjects/app_page_objects"  "c:/Ruby22-x64/lib/ruby/2.2.0/rake/rake_test_loader.rb"
"lib/app_tests/test_browse_conditions.rb" "lib/app_tests/test_example.rb" testclient impdev app]
end

EDIT:

I created a test project on GitHub that reproduces the problem. Just download the project and run the tests with 'rake test' : https://github.com/djangofan/RakeUnitTests/tree/5df4825d105251c81d425d3aef986e3f7d2f9f44

Also, I discovered that parallel_test (without rake) is capable of passing the test args the way that I want to, with a '-o' argument. I just wish I knew how to do it with Rake.

0

There are 0 answers