ruby - Tests not run automatically -
i'm trying setup guard in exercism folder, tests automatically run (using guard-minitest).
the folder structure looks this:
. ├── exercism └── ruby ├── bob │ ├── bob.rb │ ├── bob_test.rb ├── etl │ ├── etl.rb │ ├── etl_test.rb ... └── binary_search_tree ├── bst.rb ├── binary_search_tree.rb └── readme.md
due unusual folder structure, made following configuration in guardfile:
# tell guard watch folders under ruby/ all_dirs = dir.glob('ruby/*') directories all_dirs options = { test_folders: all_dirs, test_file_patterns: '*_test.rb', pride: true } guard :minitest, options watch(%r{^ruby/([^/]+)/([^/]+).rb$}) end
with setup expect tests run after edit .rb file.
i run guard in debug mode.
all tests run on startup, expected.
however, when edit .rb file tests not run again, although guard outputs this:
20:43:26 - debug - interactor stopped or killed 20:43:26 - debug - hook :run_on_additions_begin executed guard::minitest 20:43:26 - debug - hook :run_on_additions_end executed guard::minitest 20:43:26 - debug - start interactor
i tried many variations in guard configuration, such as:
watch(%r{^ruby/([^/]+)/([^/]+).rb$}) |m| dir.glob("ruby/#{m[1]}/*_test.rb").first end
(i expect run test folder in file modified.)
nothing seems work. have go guard's interactive console , press enter tests run.
what doing wrong?
edit
after reading cezary's answer below, tried more things, including trying on other environments.
it turns out wasn't guard's fault, environment using.
i ran in codio box. moved project other 2 machines, win8 , ubuntu 14.04, , works fine on both using guardfile:
all_dirs = dir.glob('ruby/*') directories all_dirs clearing :on options = { test_folders: all_dirs, test_file_patterns: '*_test.rb', pride: true } guard :minitest, options watch(%r{^ruby/([^/]+)/([^/]+).rb$}) |m| file = dir.glob("ruby/#{m[1]}/*_test.rb").first puts " should test #{file}" file end end
the output of guard -d
follows:
on codio box (where doesn't work):
<!-- language: lang-none --> 08:55:09 - debug - interactor stopped or killed should test ruby/anagram/anagram_test.rb 08:55:09 - debug - hook :run_on_additions_begin executed guard::minitest 08:55:09 - debug - hook :run_on_additions_end executed guard::minitest 08:55:09 - debug - start interactor [1] guard(main)>
on win/ubuntu (where works fine):
<!-- language: lang-none --> 11:02:10 - debug - interactor stopped or killed should test ruby/anagram/anagram_test.rb 11:02:10 - debug - hook :run_on_modifications_begin executed guard::minitest 11:02:10 - info - running: ruby/anagram/anagram_test.rb run options: --seed 52507 # running tests: .......... finished tests in 0.001249s, 8006.0205 tests/s, 8006.0205 assertions/s. 10 tests, 10 assertions, 0 failures, 0 errors, 0 skips 11:02:10 - debug - hook :run_on_modifications_end executed guard::minitest 11:02:10 - debug - start interactor [1] guard(main)>
i don't know why on codio run_on_additions
, on other 2 run_on_modifications
. anyway, guess that's codio issue. tried , without manual save , it's same.
hi i'm 1 of guys "reponsible" guard, , based on wrote walkthrough: https://github.com/guard/guard/wiki/understanding-guard
i highly recommend going through (feedback appreciated).
here's list of things consider:
structure: if can, put tests in separate top folder, ideally 'ruby/test' in example, , files in 'ruby/lib'. closer convention , things
guard::minitest
work out of box. (some editors - vim , emacs - allow switch between "alternative" files , automatically know tests or implementation files).guard watches directories recursively (and can't turned off right now). small projects, can watch not specifying
directories
option. but, if have lots of disk activity in folder , have large projects, you'll want select directories. e.g. in case, be:directories ruby
. `dir.glob('ruby/*') doesn't make sense here.guard::minitest options - if use structure described, shouldn't necessary. if not, think having
test_folder: %w(ruby)
should enough. also,test_file_patterns
shouldn't necessary, since files seem following defaults/convention (bob_test.rb
,etl_test.rb
) - unless have strange having test suites insidebob.rb
,etl.rb
files.your watch expression has no block, returns files changed. unfortunately, when change implementation file (like
bob.rb
), file passedguard::minitest
, ignore non-test files (probably usingtest_file_patterns
option, sincebob.rb
won't matchbob_test.rb
, guard::minitest quietly ... nothing.ideally, rename
guardfile
, update gems (guard::minitest
basically) , runbundle exec guard init minitest
"current" recommended templateguard::minitest
, try tweak instead. you'll see default has:watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
which shows how translate changed implementations files test files (which files guard::minitest
cares about).
in case may want:
watch(%r{^ruby/(.*/)?([^/]+)\.rb$}) { |m| "ruby/#{m[1]}/#{m[2]}_test.rb" }
i'd regexen horrible - , i'm planning implement glob pattern support - take while (lots of critical bug fixes in pipeline me).
if doesn't - go through wiki document above, since there 20-50 problems can have guard/listen - , outside guard's/listen's control. (i wish change make simpler, suggestions helpful).
since bugs priority me, maintainers - rely on issues reported int github. don't watch stuff in stack overflow (we expect tough issues reported in github).
ok, i've pointed out many things wrong, time stuff did very, well:
running
guard
in debug mode - you're awesome doing thatshowing output regarding changes - you're awesome doing (since shows guard::minitest getting changes, it's ignoring them - since you're passing implementation files , not test files).
submitting such detailed issue - that's so helpful. ideally, shouldn't have gone through trouble (or had issue in first place), reporting you're showing wrong guard on many levels. (often, developers/maintainers "get" internals, "know" what's wrong - though docs or messages or debug output says nothing others - issues others very much).
thanks again - if ever see other people issues can resolve - please so. if see obvious bugs or issues in guard - please open issue in guard. if it's in plugin repository (like guard::minitest
), mention me important issues aren't ignored (mention me @e2
on github).
i hope make guard better - i'm working hard make simpler, more intuitive, more flexible , more reliable. more can count on people reporting broken stuff, faster can move ahead cool stuff.
thanks again , have great day!
Comments
Post a Comment