This may seem obvious but I don't find a way to run Rcov or coverMe outside a Rails project.
I would like to use it with Rspec 2.5
I am using Ruby 1.9.2 so I guess this may be the problem.
I also would like not to use rake tasks but a command on the command line. I have tried several things and the best result I got is Rcov report for :
/var/lib/gems/1.9.1/gems/rcov-0.9.9/lib/rcov/code_coverage_analyzer.rb
and
/var/lib/gems/1.9.1/gems/rcov-0.9.9/lib/rcov/code_coverage_analyzer.rb
No idea why
Check out http://ruby-toolbox.com/categories/code_metrics.html for some alternatives to RCov if using Ruby 1.9 is the problem.
SimpleCov, it runs awesome outside the Rails box.
http://rubydoc.info/gems/simplecov/0.5.4/frames
The latest available version of rcov (0.9.8) still doesn't have good support for 1.9.2. You can try to run it on your project by doing:
rcov spec/*.rb
But you'll most likely get something like:
** WARNING: Ruby 1.9 Support is experimental at best. Don't expect correct results! **
And then some errors after that.
Related
Ruby 2.2.2 on Ubuntu
I have been following the saasbook tutorial on Rails and am getting to grips with the workflow.
I am confused about debugger which some sources says us now 'included' post Ruby version 2. It fails to compile on the example projects and many people have the same issue.
I have found that any bundle install that I try to do with the examples. (see here) (possibly after a bundle update) will fail on trying to 'gem install debugger -v '1.6.x''.
I have found that by commenting out the debugger line in the Gemfile will get me around this hurdle and upon firing up the Rails server, everything seems to work. I also have to change the Ruby version to my current one (2.2.2).
I am assuming that I am working with pre version 2 Ruby examples and this is good to do post version 2.
Am I correct? What has happened to the debugger post version 2?
The debugger gem is not supported on Ruby 1.9. See the debugger readme on GitHub here. If you need a command line debugger for newer versions of Ruby you can use byebug.
You can use the basic built in debugger if you prefer. Simply put require 'debug' anywhere in your source code and the Ruby interpretor will stop at that point and allow you to inspect variables etc. You do not need to install or add any additional gems to your Gemfile to use this as it is built in. See the built in debugger documentation here
Silly, cosmetic question for everyone.
I take pride in my testing. That is, I like to use minitest/pride. Unfortunately, not everyone on my team is a fan, so I have activated it in the past using the command line instead of modifying the code by setting an alias to this:
RUBYOPT=-rminitest/pride bex rake`
(bex is an alias to bundle exec, and the default rake task runs our tests.)
Recently, we updated the ruby version of our project from 1.9.3 to 2.2.0. This has broken my alias, and now when I try to run it, I get this error instead:
/Users/cf5455/.rubies/ruby-2.2.0/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- minitest/pride (LoadError)
from /Users/cf5455/.rubies/ruby-2.2.0/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
My best guess as to why this is happening is that MiniTest was changed since our last Ruby version and pride has been renamed or moved, but I have not been successfully able to Google its new name or location.
Does someone know a way that I can fix my arguments to get pride working again?
Duplicated your error by switching to ruby 2.3.0. I just ran the tests before installing any gems.
I managed to get the tests running with your alias by simply doing a gem minitest install. Not sure if your problem is caused by the same reason since I'm using rbenv for managing my rubies and gems but it does feel like you are having a package management issue. Hope this helps.
I'd like to develop some reusable step definitions and scenario outlines for Cucumber in Ruby.
I've scoured the Cucumber wiki but there seems to be no info on use of Cucumber with Ruby gems.
Is there support for execution of a feature from an installed Gem?
Or would a user have to manually change to the gem installation directory and explicitly referenced the feature(s) to run from there?
If I understood your question correctly, all you need is to create some lib for reusable definitions and steps, and then require this lib(or gem) in features/support/env.rb
Here is a gem does exactly the same as you need, you can use it as a reference: https://github.com/jayzes/cucumber-api-steps
Look at the features this gem provide: https://github.com/jayzes/cucumber-api-steps/blob/master/features/request.feature The gem created some reusable parts.
Turns out cucumber --help shows the way:
cucumber -r gem-name feature-name.feature
UPDATE: This doesn't work. Any other suggestions?
There is a cucumber gem which installs the binary cucumber.
Running this command, will assume default settings. This means it will look under ./features relative to the current path for files with the .feature extension. It will expect ./features/step_definitions to hold files with *_step.rb, where it will search for steps.
Edit: never mind, I misread your question and thought you wanted to know about the cucumber gem and its default paths.
I've had lots of headaches on this issue. I'm currently working on an assignment that requires me to use rspec on ruby. Whenever I run the rspec command I keep getting errors like
home/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.11.1/lib/core/configuration.rb:780:in 'load': cannot load such file
fro, home/.rvm/gems/ruby-1.9.3-p286/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in 'map'....
They're just endless and confusing. I figure I wasn't doing something right in my .rb files no matter how I tweak according to the test rules same issue. I figured I'd start from scratch with a basic rspec tutorial example, still getting the same errors. I felt it might be my ruby installation so I uninstalled and this time I installed using RVM - still the same errors I get. No matter what I try - simple test codes (assuming maybe my assignment one is buggy), I've tried rspec, rspec spec, rake spec, still the same results.
I'm really confused. I'm new to ruby and my assignment is due in a few days. I have an idea how to write the code I need to get the required results but I have been restricted to use rspec which is really annoying. Then I remembered once when I tried to install LAMPP with my 64 bit Ubunutu and I was told I need to get 32 bit libraries or something, which I did and LAMPP now works (I can't use myphp admin though). So I'm thinking, could it be that I need to get a 32 bit version of Ubuntu 12 instead? Does it have anything to do with my rspec problem or I'm just doing something else wrong?
Oh and yes, I have ruby gems installed. Your answers would be really appreciated guys.
1.) delete your Gemfile.lock file
2.) run bundle install if you want to exclude anything use the --without flag ex: bundle install --without production
3.) run bundle exec rspec spec/
This should make it work now. Let me know.
What can I use to profile code in 1.9.2? All of the versions of ruby-prof I've found segfault against 1.9.2.
For instance, when I add
gem "ruby-prof"
to my Rails project's Gemfile and run
bundle
bundle exec ruby-prof config/environment.rb
I get a segfault.
Is there a new profiling gem in town? Is there a way to make ruby-prof play nice?
Not sure it helps but I stumbled on this which may add a bit more clarity or lead you down a different path: http://www.devheads.net/development/ruby/core/segmentation-fault-when-using-ruby-prof-and-ruby-192.htm. You may want to check out wycats' fork based on that thread: https://github.com/wycats/ruby-prof
Also, I have not tried it out myself and it may not be exactly what you are looking for but Aman of Github fame has a port of google-perftools for Ruby:
https://github.com/tmm1/perftools.rb
As #chris.baglieri suggested, you can use the perftools.rb gem for profiling Ruby 1.9 code.
gem install perftools.rb
Then
require 'perftools'
PerfTools::CpuProfiler.start('profile_data') do
# something cpu-intensive
end
`pprof.rb --text profile_data profile.txt`
`pprof.rb --pdf profile_data profile.pdf`
You can use another popular profiler tool - MethodProfiler
It's very handy to find slow method in the target class.