Semi-AutoTest allows you to rapidly repeat a test or set of tests without waiting for test preparation time before each test run.
Given an rspec file like:
# thing_spec.rb require 'semi-autotest' require 'thing' describe 'The thing under test' do it 'should do something' do SemiAutoTest.repeat_from_here Thing.do_something.should == "success" end end
Run one particular spec:
# rspec -e 'thing under test' spec/thing_spec.rb semi>
Press Enter to run the spec once:
semi> . Finished in 0.45392 seconds 1 example, 0 failures semi>
Start watching the code under test with the “w” command (tab completion supported):
semi> w lib/thing.rb semi>
You could also accomplish the same thing with a line like this in your test code (before calling #repeat_from_here):
SemiAutoTest.files_reloadable << 'lib/thing.rb'
Edit the code under test, and introduce a bug. Rerun the spec by pressing Enter:
semi> F Failures: 1) The thing under test should do something Failure/Error: Thing.do_something.should == "success" expected: "success" got: "failure" (using ==) # ./sample/spec/thing_spec.rb:8:in `block (2 levels) in <top (required)>' Finished in 80.54 seconds 1 example, 1 failure Failed examples: rspec ./sample/spec/thing_spec.rb:6 # The thing under test should do something semi>
List watched files with the “l” command:
semi> l ["lib/thing.rb"] semi>
Stop watching files with the “u” command:
semi> u lib/thing.rb semi>
Quit with the “q” command, or by pressing ^D on a blank input line. To continue running until finished (and then quit afterwards), use the “c” command.
Special care needs to be taken if you have tests that have cleanup or teardown which have lasting effects, such as closure of handles (file, database, socket, etc.) or persistence of data. If you encounter problems related to this, experiment with different places from which to call #repeat_from_here – it often helps to call #repeat_from_here in a sooner/higher location in your spec, and from within a “before :all” block.
When using a browser driver in your tests, it may be helpful to have a little no-op broswer spec earlier than your actual spec. The purpose of this is to open the browser before the spec of interest runs, and to keep the browser open for further runs. Example no-op spec:
it 'should open the browser' do visit '/' end
Semi-AutoTest is licensed under the MIT Licence. See the LICENCE file.
The source code repository is at github.com/Pistos/semi-autotest .
Send comments, feedback and tech support requests to the #mathetes channel on the FreeNode IRC network ( webchat.freenode.net/?channels=mathetes ). Reproducible issues may be reported at github.com/Pistos/semi-autotest/issues .