0

I switched from Test Unit to MiniTest in jruby-1.7.13. I also use mocha/integration. My problem is that running 'rake test' brings up Mocha::ExpectationError: unexpected invocation: MyClass.new. With MyClass.new beeing a class defined in the lib folder and used in the test class. I figured out that running the tests separately workds just fine. It looks like a timing or sequence issue. I tried to circumvent it by using setup/teardown to initiate the MyClass.new before each single test, but this does not help. Do I have to mock/stub the MyClass.new?

2 Answers2

0

Assuming you're using Rails 4, you need to add the following to your config/application.rb:

config.autoload_paths += %W(#{config.root}/lib)

Kill Spring/Zeus/Spork, re-run your tests, and it should work.

Chris Kottom
  • 1,249
  • 10
  • 11
0

the helper.rb sample code...

require 'rubygems'
require 'bundler'

begin
  Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
  $stderr.puts e.message
  $stderr.puts "Run `bundle install` to install missing gems"
  exit e.status_code
end

require 'minitest/spec'
require 'minitest/autorun'
require 'mocha/integration'

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'dibta-modbus-adapter'
require 'dibta-interface'

class MiniTest::Test
  def test_order
    :alpha
  end
  def self.runnable_methods
    methods = methods_matching(/^test_/)

    case self.test_order
    when :random, :parallel then
      max = methods.size
      methods.sort.sort_by { rand max }
    when :alpha, :sorted then
      methods.sort   ## note: Runnable is shuffeled in minitest.rb
    else
      raise "Unknown test_order: #{self.test_order.inspect}"
    end
  end
end

As you can see I started to modify test_order and runnable_methods ....

It depends on the seed "number" where the tests fail. In some cases (with special seed number) the test may even run through.