Issue with running unit tests when requiring rubygems
I wanted to try using mocha to write unit tests with mocks. After requiring "rubygems" a NoMethodError exception was thrown when attempting to run the tests. The method which wasn't found was 'run'. If I remove the call to require "rubygems" my test fails because I can't use mocha but the NoMethodError exception which was thrown is not thrown anymore. Am I missing something? Thanks, Gabriel Ayuso
This *might* be because the minitest version in our stdlib is outdated. You can try to install the minitest gem and require that instead and see if that fixes it. On Fri, Feb 11, 2011 at 3:24 PM, Gabriel Ayuso <gabriel@gabrielayuso.com> wrote:
I wanted to try using mocha to write unit tests with mocks. After requiring "rubygems" a NoMethodError exception was thrown when attempting to run the tests. The method which wasn't found was 'run'. If I remove the call to require "rubygems" my test fails because I can't use mocha but the NoMethodError exception which was thrown is not thrown anymore. Am I missing something? Thanks, Gabriel Ayuso _______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Considering that the updated minitest library also contains the new benchmarking facilities (though I don't think that part was officially adopted by MRI), it might be worth considering pulling from upstream. On Fri, Feb 11, 2011 at 9:37 AM, Eloy Duran <eloy.de.enige@gmail.com> wrote:
This *might* be because the minitest version in our stdlib is outdated. You can try to install the minitest gem and require that instead and see if that fixes it.
On Fri, Feb 11, 2011 at 3:24 PM, Gabriel Ayuso <gabriel@gabrielayuso.com> wrote:
I wanted to try using mocha to write unit tests with mocks. After requiring "rubygems" a NoMethodError exception was thrown when attempting to run the tests. The method which wasn't found was 'run'. If I remove the call to require "rubygems" my test fails because I can't use mocha but the NoMethodError exception which was thrown is not thrown anymore. Am I missing something? Thanks, Gabriel Ayuso _______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
I did a little more testing and I found out that the problem is apparently by how Mocha changes Test::Unit::TestUnit. The only way I was able to make it work was the following: require 'rubygems' gem 'mocha' require 'mocha' require 'test/unit' class QuickTest < Test::Unit::TestCase include Mocha::API def test_quick obj = mock("test") obj.expects(:do).returns(false) assert( obj.do ) end end If I required 'mocha' after 'test/unit' then the NoMethodError exception would be thrown: uncaught Objective-C/C++ exception... 2011-02-11 23:43:50.675 macruby[83143:903] *** Terminating app due to uncaught exception 'NoMethodError', reason: '/Library/Frameworks/MacRuby.framework/Versions/0.8/usr/lib/ruby/1.9.2/minitest/unit.rb:641:in `block': undefined method `run' for #<QuickTest:0x20039eea0 ...> (NoMethodError) Gabriel Ayuso On Feb 11, 2011, at 3:59 PM, Joshua Ballanco wrote:
Considering that the updated minitest library also contains the new benchmarking facilities (though I don't think that part was officially adopted by MRI), it might be worth considering pulling from upstream.
On Fri, Feb 11, 2011 at 9:37 AM, Eloy Duran <eloy.de.enige@gmail.com> wrote: This *might* be because the minitest version in our stdlib is outdated. You can try to install the minitest gem and require that instead and see if that fixes it.
On Fri, Feb 11, 2011 at 3:24 PM, Gabriel Ayuso <gabriel@gabrielayuso.com> wrote:
I wanted to try using mocha to write unit tests with mocks. After requiring "rubygems" a NoMethodError exception was thrown when attempting to run the tests. The method which wasn't found was 'run'. If I remove the call to require "rubygems" my test fails because I can't use mocha but the NoMethodError exception which was thrown is not thrown anymore. Am I missing something? Thanks, Gabriel Ayuso _______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
Did you also try installing the latest minitest + mocha as suggested? I would expect that to fix such issues. Which would also mean that, like Joshua suggested, we should update our version in stdlib. On 11 feb 2011, at 23:53, Gabriel Ayuso wrote:
I did a little more testing and I found out that the problem is apparently by how Mocha changes Test::Unit::TestUnit.
The only way I was able to make it work was the following:
require 'rubygems' gem 'mocha' require 'mocha' require 'test/unit' class QuickTest < Test::Unit::TestCase include Mocha::API def test_quick obj = mock("test") obj.expects(:do).returns(false) assert( obj.do ) end end
If I required 'mocha' after 'test/unit' then the NoMethodError exception would be thrown:
uncaught Objective-C/C++ exception... 2011-02-11 23:43:50.675 macruby[83143:903] *** Terminating app due to uncaught exception 'NoMethodError', reason: '/Library/Frameworks/MacRuby.framework/Versions/0.8/usr/lib/ruby/1.9.2/minitest/unit.rb:641:in `block': undefined method `run' for #<QuickTest:0x20039eea0 ...> (NoMethodError)
Gabriel Ayuso
On Feb 11, 2011, at 3:59 PM, Joshua Ballanco wrote:
Considering that the updated minitest library also contains the new benchmarking facilities (though I don't think that part was officially adopted by MRI), it might be worth considering pulling from upstream.
On Fri, Feb 11, 2011 at 9:37 AM, Eloy Duran <eloy.de.enige@gmail.com> wrote: This *might* be because the minitest version in our stdlib is outdated. You can try to install the minitest gem and require that instead and see if that fixes it.
On Fri, Feb 11, 2011 at 3:24 PM, Gabriel Ayuso <gabriel@gabrielayuso.com> wrote:
I wanted to try using mocha to write unit tests with mocks. After requiring "rubygems" a NoMethodError exception was thrown when attempting to run the tests. The method which wasn't found was 'run'. If I remove the call to require "rubygems" my test fails because I can't use mocha but the NoMethodError exception which was thrown is not thrown anymore. Am I missing something? Thanks, Gabriel Ayuso _______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
I reinstalled the minitest and mocha gems to the following versions: minitest-2.0.2, mocha-0.9.12 The same issue I described before occurred once again. Here's the code I ran on macirb and the result: require 'rubygems' #=> true gem 'minitest' #=> true require 'test/unit' #=> true require 'mocha' #=> true class QuickTest < Test::Unit::TestCase def test_quick obj = mock('obj') obj.expects(:a).returns(true) assert( obj.a ) end end # => nil exit Run options: --seed 43199 # Running tests: uncaught Objective-C/C++ exception... 2011-02-13 14:47:45.996 macruby[25824:903] *** Terminating app due to uncaught exception 'NoMethodError', reason: '/Library/Frameworks/MacRuby.framework/Versions/0.8/usr/lib/ruby/Gems/1.9.2/gems/minitest-2.0.2/lib/minitest/unit.rb:664:in `block': undefined method `run' for #<QuickTest:0x200336080 ...> (NoMethodError) from /Library/Frameworks/MacRuby.framework/Versions/0.8/usr/lib/ruby/Gems/1.9.2/gems/minitest-2.0.2/lib/minitest/unit.rb:657:in `_run_suite:' from /Library/Frameworks/MacRuby.framework/Versions/0.8/usr/lib/ruby/Gems/1.9.2/gems/minitest-2.0.2/lib/minitest/unit.rb:647:in `block' from /Library/Frameworks/MacRuby.framework/Versions/0.8/usr/lib/ruby/Gems/1.9.2/gems/minitest-2.0.2/lib/minitest/unit.rb:647:in `_run_suites:' from /Library/Frameworks/MacRuby.framework/Versions/0.8/usr/lib/ruby/Gems/1.9.2/gems/minitest-2.0.2/lib/minitest/unit.rb:623:in `_run_anything:' from /Library/Frameworks/MacRuby.framework/Versions/0.8/usr/lib/ruby/Gems/1.9.2/gems/minitest-2.0.2/lib/minitest/unit.rb:778:in `run_tests' from /Library/Frameworks/MacRuby.framework/Versions/0.8/usr/lib/ruby/Gems/1.9.2/gems/minitest-2.0.2/lib/minitest/unit.rb:765:in `block' from /Library/Frameworks/MacRuby.framework/Versions/0.8/usr/lib/ruby/Gems/1.9.2/gems/minitest-2.0.2/lib/minitest/unit.rb:764:in `run:' from /Library/Frameworks/MacRuby.framework/Versions/0.8/usr/lib/ruby/Gems/1.9.2/gems/minitest-2.0.2/lib/minitest/unit.rb:558:in `block' ' Gabriel Ayuso On Feb 13, 2011, at 1:08 PM, Eloy Duran wrote:
Did you also try installing the latest minitest + mocha as suggested? I would expect that to fix such issues. Which would also mean that, like Joshua suggested, we should update our version in stdlib.
On 11 feb 2011, at 23:53, Gabriel Ayuso wrote:
I did a little more testing and I found out that the problem is apparently by how Mocha changes Test::Unit::TestUnit.
The only way I was able to make it work was the following:
require 'rubygems' gem 'mocha' require 'mocha' require 'test/unit' class QuickTest < Test::Unit::TestCase include Mocha::API def test_quick obj = mock("test") obj.expects(:do).returns(false) assert( obj.do ) end end
If I required 'mocha' after 'test/unit' then the NoMethodError exception would be thrown:
uncaught Objective-C/C++ exception... 2011-02-11 23:43:50.675 macruby[83143:903] *** Terminating app due to uncaught exception 'NoMethodError', reason: '/Library/Frameworks/MacRuby.framework/Versions/0.8/usr/lib/ruby/1.9.2/minitest/unit.rb:641:in `block': undefined method `run' for #<QuickTest:0x20039eea0 ...> (NoMethodError)
Gabriel Ayuso
On Feb 11, 2011, at 3:59 PM, Joshua Ballanco wrote:
Considering that the updated minitest library also contains the new benchmarking facilities (though I don't think that part was officially adopted by MRI), it might be worth considering pulling from upstream.
On Fri, Feb 11, 2011 at 9:37 AM, Eloy Duran <eloy.de.enige@gmail.com> wrote: This *might* be because the minitest version in our stdlib is outdated. You can try to install the minitest gem and require that instead and see if that fixes it.
On Fri, Feb 11, 2011 at 3:24 PM, Gabriel Ayuso <gabriel@gabrielayuso.com> wrote:
I wanted to try using mocha to write unit tests with mocks. After requiring "rubygems" a NoMethodError exception was thrown when attempting to run the tests. The method which wasn't found was 'run'. If I remove the call to require "rubygems" my test fails because I can't use mocha but the NoMethodError exception which was thrown is not thrown anymore. Am I missing something? Thanks, Gabriel Ayuso _______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
_______________________________________________ MacRuby-devel mailing list MacRuby-devel@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
On Feb 13, 2011, at 05:56 , Gabriel Ayuso wrote:
I reinstalled the minitest and mocha gems to the following versions: minitest-2.0.2, mocha-0.9.12 The same issue I described before occurred once again.
Here's the code I ran on macirb and the result:
require 'rubygems' #=> true gem 'minitest' #=> true require 'test/unit' #=> true require 'mocha' #=> true class QuickTest < Test::Unit::TestCase def test_quick obj = mock('obj') obj.expects(:a).returns(true) assert( obj.a ) end end # => nil exit
I can confirm this with the following minimal repro: require "rubygems" require "isolate" Isolate.now! :system => false do gem "minitest" gem "mocha" end gem "minitest" require "minitest/autorun" require "mocha" class QuickTest < MiniTest::Unit::TestCase def test_quick obj = mock("obj") end end The test only fails on macruby and with mocha. I'll file a ticket.
On Feb 14, 2011, at 15:23 , Ryan Davis wrote:
The test only fails on macruby and with mocha. I'll file a ticket.
here is the workaround: require "rubygems" require "isolate" Isolate.now! :system => false do gem "minitest" gem "mocha" end class Module def remove_method x # do nothing end end if defined?(RUBY_ENGINE) and RUBY_ENGINE == "macruby" gem "minitest" require "minitest/autorun" require "mocha" class QuickTest < MiniTest::Unit::TestCase def test_quick obj = mock("obj") end end
participants (4)
-
Eloy Duran
-
Gabriel Ayuso
-
Joshua Ballanco
-
Ryan Davis