user2025166
user2025166

Reputation: 21

MiniTest falis with jruby rake test task

I have a project with self written gems in jruby (using rvm to switch between jrubies). With jruby-1.7.0 I could do my tests with Test::Unit::TestCase. Now I have switched to MiniTest in jruby-1.7.13. But I cannot run my tests any more with 'rake test'.

The errors are like ... Mocha::ExpectationError: unexpected invocation: blabla.new() ... with blabla beeing my jruby class

It only works if I run them solely via the TEST= and TESTOPTS= parameter to use a single test file and select one or a view tests via --name= (with regular expressions).

I use a helper file with

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

class MiniTest::Test
end

instead of the lines used for the old test suite Test::Unit::TestCase

require 'test/unit'
require 'shoulda'
require 'mocha'

class Test::Unit::TestCase
end

A major difference in MiniTest is the test order. So I tried to circumvent the randomization by definig the test_order like

class MiniTest::Test
  def test_order
    :alpha
  end
end

this had no effect on the test order, but Is this realy a problem? The errors seem to come with too may tests in the test suite. Is this a bug? Please help!

You may also check require self made gem in jruby fails after update to jruby-1.7.13 for my preious post where I already could solve a load problem.

Upvotes: 0

Views: 142

Answers (1)

user2025166
user2025166

Reputation: 21

Here is some code

require File.dirname(__FILE__) + "/../helper.rb"
require 'command/flow_control_command'
## --seed=36725
module Command
 class TestFlowControlCommand < MiniTest::Test
 def setup
  fcp = Configuration::FlowControlParameter.last
  fcp.number_ports = 16
  fcp.save!
 end
 def test_should_exist
  assert FlowControlCommand
 end
 def test_should_initialize
  FlowControlCommand.expects(:new).with("modbus").returns(true)
  assert FlowControlCommand.new("modbus")
 end
 def test_should_have_constants
  assert_equal [0,0,0,0, 0,0,0,0,  0,0,0,0, 0,0,0,0,  0,0,0,0, 0,0,0,0,  0,0,0,0, 0,0,0,0], FlowControlCommand::CIRCLE
 end
 def test_should_find_line_1
  result = FlowControlCommand.new("modbus").find_line [1,0,0,0, 0,0,0,0,  0,0,0,0, 0,0,0,0,  1,1,0,0, 0,0]
  assert_equal "LINE1", result
 end
 def test_should_not_find_line
  result = FlowControlCommand.new("modbus").find_line [0,0,0,0, 0,0,0,0,  0,0,0,0, 0,0,0,0,  1,1,0,0, 0,0]
  assert_equal "LINE?", result
  result = FlowControlCommand.new("modbus").find_line [1,1,0,0, 0,0,0,0,  0,0,0,0, 0,0,0,0,  1,1,0,0, 0,0]
  assert_equal "LINE?", result
 end
 def test_should_find_line_16
  result = FlowControlCommand.new("modbus").find_line [0,0,0,0, 0,0,0,0,  0,0,0,0, 0,0,0,1,  1,1,0,0, 0,0]
  assert_equal "LINE16", result
 end
 def test_should_find_line_13
  result = FlowControlCommand.new("modbus").find_line [0,0,0,0, 0,0,0,0,  0,0,0,0, 1,0,0,0,  1,1,0,0, 0,0]
  assert_equal "LINE13", result
 end

  + some more tests

Running this will cause

Running:

.....EEEEE.EEE.

Finished in 1.036000s, 14.4788 runs/s, 2.8958 assertions/s.

1) Error: Command::TestFlowControlCommand#test_should_find_line_circle: Mocha::ExpectationError: unexpected invocation: Command::FlowControlCommand.new('modbus') unsatisfied expectations: - expected exactly once, invoked twice: Command::FlowControlCommand.new('modbus')

/home/frank/Rubymineprojects/ndir_med1/dibta-model/test/command/test_flow_control_command.rb:61:in `test_should_find_line_circle'

2) Error: Command::TestFlowControlCommand#test_should_find_line_14: Mocha::ExpectationError: unexpected invocation: Command::FlowControlCommand.new('modbus') unsatisfied expectations: - expected exactly once, invoked 3 times: Command::FlowControlCommand.new('modbus')

/home/frank/Rubymineprojects/ndir_med1/dibta-model/test/command/test_flow_control_command.rb:46:in `test_should_find_line_14'

If I run the tests one by one no error occurs, If I run with a specail seed parameter the tests also run through.

Upvotes: 0

Related Questions