I'm having errors in some tests but the error themselves seem to be covered up by this error coming from
/home/durrantm/.rvm/gems/ruby-1.9.3-p194/gems/rspec-core-2.6.4/lib/rspec/core/
formatters/base_text_formatter.rb:162:in `write':
Broken pipe - <STDOUT> (Errno::EPIPE)
fyi, I run the test and then pipe out the results to less as there's a lot of output.
How can I resolve this?
I've updated RSpec and tried different versions of ruby 1.9.3 and 2.0 but to no avail.
How are you executing your tests? It looks like you might be doing something like rspec | less and then exiting out of less. This closes the pipe while RSpec is still printing to it.
Related
I was learning about the gem Rspec through a tutorial when this error came up.The last thing I typed in was
$ rspec spec spec\hello_world_spec.rb
I had only installed the Rspec gem and nothing else.
the output message from the cmd
Try to get rid of spec
rspec spec\hello_world_spec.rb
You're passing spec and spec\hello_world_spec.rb as arguments to rspec. These are interpreted as files to run, or directories to search through for files to run. Since you're already running in the spec\ directory, rspec is looking for spec\spec\ and spec\spec\hello_world_spec.rb, which don't exist. Try running that from one directory up (in a typical ruby project, the "root" of your project) and it should run.
i.e. Instead of:
\rspec_tutorial\spec>rspec spec spec\hello_world_spec.rb
try:
\rspec_tutorial>rspec spec spec\hello_world_spec.rb
Also, as #Ursus points out, running rspec spec spec\hello_world_spec.rb is redundant. Rspec will search through spec\ for files to run and will run hello_world_spec.rb automatically since it's under spec. If you only want to run hello_world_spec.rb–which seems to be your intent–then drop the spec from the command, per #Ursus' answer.
The documentation for the minitest-ci gem (seemingly the only option for producing test results for a CI tool such as Jenkins) has the extremely annoying habit of not preserving the results of rake minitest:models when invoked as rake minitest - the test results from running minitest:models are deleted prior to running the rest of the tests. minitest-ci's barely-extant documentation claims adding this to test_helper.rb will disable the troublesome auto-clean behavior, but it doesn't:
# Why do SO and GitHub have to use completely different ways of indicating inline code?
# test/helper.rb
MiniTest::Ci.auto_clean = false
Has anyone out there managed to get minitest-ci to preserve all the test result files? I'm reaching wits' end here.
I think ci_reporter gem supports miniTest. This could be another option.
I have placed all my specs in specs/*.rb.
However, when I run Minitest with ruby spec/**/*_spec.rb, only one file is run.
What gives?
This is not minitest specific, but Ruby. You are effectively running a ruby program which knows nothing about the program being run.
Ruby does not support running multiple files at once afaik, so if you want to get a similar result you could try something like:
for file in spec/**/*_spec.rb; do ruby $file; done
UPDATE: for what you want you should probably create a Rake task as described here
You can use the testrbl third party gem to run multiple Minitest files on the command line. You could also use the mtest bin from maxitest extensions.
Using a for loop in bash will incur overhead of loading your application/library for every test you pass it. If you have just ten tests, and you're testing a Rails app that takes 5 seconds to boot, that's over a minute of totally unnecessary load time.
I am using Minitest as the runner for my functional tests, using Selenium as the driver to run the browser. Each test is modeled as MiniTest::Unit::TestCase.
Minitest reports summary of execution when it completes executing all tests. The Exceptions that were encountered are also printed towards the end of the execution. I find it difficult to debug when something unexpected fails as the context of execution is lost. The exceptions I am running into are not deterministic.
Is there a way to make Minitest runner to stop execution of tests on exception or assertion failure?
I am using minitest (2.11.2) and ruby 1.9.2p290 (2011-07-09) [i386-mingw32]
I think you mean to have a "fast fail" option available. I found the fail_fast for minitest (Test::Unit): Immediate backtrace & exit article, but that's out of date (still covers what can be done). I think you'll need to monkeypatch your testing library to enable this option. I found a Gist showing how to add a simple fail-fast option to minitest/turn/minitest-rails so that might get you on the right track. I understand your problem is to do with the first article I've referenced:
When I run the Test::Unit suite in my Ruby on Rails 3 project through
rake test and a test is failing, the default behavior is to just
print “F” or “E”, keep running until all the tests are finished (while
I twiddle my thumbs), and only then print out a stack trace.
try rails test -f will do it. It means abort test run of first failure or error.
As I answered here, I found a gem for: minitest-fail-fast. It works with Rails 4.2 and Minitest 5.6.1
It does not directly answer the question, but might be very useful.
You could use pry-rescue gem so that your tests will launch a pry session whenever something goes wrong. All you have to do is to add the gem into your Gemfile:
group :development, :test do
gem 'pry-rescue'
end
Then launch your tests with the following flag:
PRY_RESCUE_RAILS=1 rails test rails test test/integration/agendas_test.rb
Use -f.
In pure ruby, as you ask for, this means ruby <file> -f.
In rails, this means rails test -f.
Minitest will check the terminal's arguments for the -f flag, so how you call it appears to not be relevant to the -f flag.
I get a slightly heisen error from eventmachine (0.12.10, on OSX 10.6.4):
terminate called after throwing an instance of 'std::runtime_error'
what(): no loop breaker
It only occurs in tests, and only when all tests are run together. Run individually they pass.
I spotted the only place in the eventmachine code that mentions the error's message:
http://github.com/eventmachine/eventmachine/blob/master/ext/em.cpp#L333
(What puzzles me as well is that it looks like a win32 code path, or am I wrong?)
To me it looks like some ressource like sockets are used up. That would explain the occurence pattern.
Ok, I found it myself.
The error comes in fact from the win32 conditionally compiled code. I get a plain old "Too many open files" error if I build locally, and that problem is easy to releave by increasing the ulimit value for open files (which is said to be quite modest by default on OSX).
ulimit -n 1024 # or whichever value you find appropriate
(Default is 255, look at the output of ulimit -a)
If I build and install from the cloned git repository using rake gem:install, I get the expected (Unix) error message. So the bug appears to be fixed in master.
Filed bug for the rubygems.org gem is here: http://github.com/eventmachine/eventmachine/issues#issue/88