Identify troubling spec with rspec in Ruby - ruby

I've got this monstrous error message while running rspec spec/vector_spec.rb and I couldn't identify what spec is causing an error.
Here's some part of the error message:
..................F...........******************************...........F...***********************....*.....*....................................../home/ubuntu/workspace/daru/lib/daru/index.rb:102: [BUG] Segmentation fault at 0x007fe1e31ce030
ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0048 p:0021 s:0197 e:000196 METHOD /home/ubuntu/workspace/daru/lib/daru/index.rb:102
c:0047 p:0015 s:0193 e:000192 METHOD /home/ubuntu/workspace/daru/lib/daru/vector.rb:207
...
Here's the full error message: https://gist.github.com/lokeshh/83369d71ca94b07cf89b23e215214666
I want to know which spec is causing an error so I can look into it but I couldn't find a way to identify the spec that is causing the error.
Is there way?

You can append a colon and then the line number of the specific test to the RSpec file, e.g.:
rspec spec/vector_spec.rb:83
You could also disable large parts of your code with =begin and =end to narrow down the section.
I just ran rspec -h and got some very helpful information. Check out the --only-failures and next-failure options! Also, looks like you could also use -fd to get the groups and example names printed out!

Related

rspec error in Rails3: Formatter 'nested' unknown

My tests were running fine, then suddenly I started getting this error whenever I tried to run rspec:
/.rvm/gems/ruby-2.0.0-p451/gems/rspec-core-3.0.2/lib/rspec/core/formatters.rb:167:in `find_formatter': Formatter 'nested' unknown - maybe you meant 'documentation' or 'progress'?. (ArgumentError)
I haven't made any changes to my .rspec file, which only contains one thing:
--color
I'm using the 'rspec-rails' gem.
I'm not sure what I did differently to get this error. I must have changed something... but what? I've never seen this error before and googling it was no help.
I'm a jr dev/recent grad and still learning, so any assistance is greatly appreciated!
Change your .rspec file to --color --format documentation
Read more about the formatters by typing rspec --help in the console.

Migrating to rubinius

I'm trying to migrate my project from mri to rubinius to get concurrency advantage.
I've started the server and open first page and then got error:
Puma caught this error: undefined method `=~' for Pathname (NameError)
kernel/common/module.rb:212:in `instance_method'
kernel/common/module.rb:354:in `undef_method'
kernel/bootstrap/array.rb:66:in `each'
kernel/common/module.rb:352:in `undef_method'
...
My Gemfile
source 'https://rubygems.org'
ruby '2.1.0', :engine => "rbx", engine_version: '2.2.1'
gem "rubysl" # Ruby Standard Library meta-gem for rubinius
# Server requirements
gem 'puma'
...
What might be a problem here?
UPDATE: full stack trace
I examined your stack trace and looked at the Rubinius source code. The offending line is:
class Pathname
undef =~ # THIS IS IT
end
#=~ is an instance method on Object so normally undef =~ should work on any class... unless it has been undef'd on Object or on Pathname already.
I'm wondering if this is happening because you have the rubysl gem in your Gemfile. I don't know Rubinius, but from what I can see, it doesn't seem to require you to specifically include this gem. Or maybe it did in past versions, but doesn't now. If the standard library is being loaded twice, that would explain why undef =~ fails the second time.
If that doesn't help, I recommend you try temporarily removing as many gems as possible and see if the problem disappears. If so, add them back one by one until you find which one is causing the problem.

RSpec Broken pipe

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.

Ruby refinements not working in CI server

I'm having errors within the Jenkins server:
$ ruby -v
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-linux]
When running rspec, I have the following error:
undefined method `using' for #<Class:0x000000026f9c88> (NoMethodError)
the exact same code works on my local computer, with ruby2.
Here's my version: ruby 2.0.0dev (2012-12-01 trunk 38126) [x86_64-linux]
Also, it works on irb. It seems that ruby isn't recognizing the using statement when running a script.
Here's the code:
describe "blah" do
include TestHelper
using TestHelper::BrowserRefinement
...
end
clarification: the refinement is defined in a different file. I'm scourging the interwebs to see if there's a difference between revisions r39474 and r38126.
In current release of Ruby 2.0 (2.0.0p0), using is an instance method of the top-level object main, not that of Module. And it's a private method. If you call it in class/module definition or method definition, a RuntimeError is raised.
"The scope of a refinement activated by main.using is from the point just after main.using is invoked to the end of the file where main.using is invoked. However, when main.using is invoked in a string given as the first argument of Kernel#eval, Kernel#instance_eval, or Module#module_eval, the end of the scope is the end of the string."
You can read more about this in Refinements Specification.
For your test cases, you can write them with eval and pass in the top level bindings, like the test cases in ruby source.
Refinements is still an experimental feature, it may change in future :-)

How to make minitest stop execution on failure?

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.

Resources