Featured post
ruby - Mapping multiple test classes to the same file for autotest -
i'm using standalone autotest in projects along minitest. in 1 of projects, have single file (validation.rb
) validates document different internal format levels. (a level 2 document has more features level 1 document.)
testing validation particular level requires repeatedly loading in known-valid document, subtly mutating in broken way, , ensuring broken. in short:
class testvalidation < minitest::unit::testcase def setup @l1 = document.load( l1doc ) end def test_valid assert @l1.valid_level_1? end def test_unbalanced_data @l1.instance_eval{ @tracks[0].data.pop } refute @l1.valid_level_1?, "validation must ensure tracks have same amount of data" end # many more tests level 1 here end
the problem autotest (as far can tell) knows tests run based on name of test classes. testvalidation
have tests automatically run when validation.rb
changed.
without autotest, have named above class testl1validation
, , created new class testl2validation
loaded different document. doing breaks autotest, however, unless break out validation l1validation.rb
, l2validation.rb
.
how can name files or tests, or set tests, autotest run multiple test classes when single source file changes?
you can add custom mappings autotest. here's 1 way of doing it: create autotest directory @ same level lib , test directories.
add autotest/discover.rb:
$load_path.unshift file.expand_path('../', file.dirname(__file__)) autotest.add_discovery { "my_rules" }
add autotest/my_rules.rb:
require 'autotest' class autotest::my_rules < autotest def initialize super add_mapping(%r%^lib/valid.rb$%, true) { |filename, _| files_matching %r%^test/test_.*\.rb$% } end end
this add custom mapping: whenever lib/valid.rb files has changed, re-run test_*.rb files in test directory.
- Get link
- X
- Other Apps
Comments
Post a Comment