I get the following error when trying to run a minitest unit test with ruby test/test_foo.rb:
Warning: you should require 'minitest/autorun' instead.
Warning: or add 'gem "minitest"' before 'require "minitest/autorun"'
From:
/home/emile/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/minitest/autorun.rb:15:```
test_foo.rb looks like this:
require 'minitest/autorun'
class TestFoo < MiniTest::Test
#stuf
end
My Gemfile does contain gem 'minitest' and test_foo.rb does contain require 'minitest/autorun', yet I still get the warning.
Is this a bug? Any ideas?
Run your test using bundle exec ruby test/test_foo.rb to make sure you use your bundled gems (in this case minitest).
Just running ruby test/test_foo.rb will use your globally installed Rubygems.
If you want to dig around a little more, try looking in /home/emile/.rvm/rubies/ruby-2.0.0-p0/lib/ruby/2.0.0/minitest/autorun.rb, around line 15.
▲
I've interepreted the warning literally and added the line gem 'minitest' before the line require 'minitest/autorun', and that seems to work. Odd, or is this expected?
This is expected. It tells ruby to use the gem version and not the standard library version.
Related
I started to learn ruby recently. I trying to use a library pHash on ruby for my own project. I trying during for 2 days, but I don't understand what I'm doing wrong.I included old and new versions library, I installed in local directory and home directory. I got constantly error on compile ruby and in command line ubuntu. At last I tried to use a bundler/inline and got next error.
Code here:
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'pHash', require: 'ffi'
gem 'rspec', require: false
end
Phash::Text.new('first.txt') % Phash::Text.new('second.txt')
The last line I take from documentation.
require: 'ffi' seems unlikely to do what you need... and indeed the examples in the documentation all include a specific require call first. The one you referenced looks like this in full:
require 'phash/text'
Phash::Text.new('first.txt') % Phash::Text.new('second.txt')
I'm trying to develop a ruby gem for practice and I'm wondering how do I require pry during development and test runs? Is there anyway to require the gem only during development? I'm on Ruby and not Rails and I don't think I have any environment variables setup to rely on. Is there a conventional way to do this?
and
Currently if I run code that hits the above line, I get this error:
NoMethodError: undefined method `pry' for #<Binding:0x007f8d3287c4d8>
from /Users/jwan/programming/interview_questions/gemini/jobcoin_client/lib/jobcoin_client/requests/connection.rb:18:in `post'
A few questions:
How do I properly require pry so this line doesn't throw an error when developing a gem?
I read Yahuda's post but I'm still unclear why adding dependencies in the gemspec vs adding dependencies in the Gemfile. What is the difference?
Currently, after I make changes to the ruby gem, I have to run these series of commands. Is there anything more efficient that I can do?
gem build jobcoin_client.gemspec
WARNING: no homepage specified
WARNING: open-ended dependency on pry (>= 0, development) is not recommended
if pry is semantically versioned, use:
add_development_dependency 'pry', '~> 0'
WARNING: See http://guides.rubygems.org/specification-reference/ for help
Successfully built RubyGem
Name: jobcoin_client
Version: 0.1.0
File: jobcoin_client-0.1.0.gem
$ gem install jobcoin_client
Successfully installed jobcoin_client-0.1.0
Parsing documentation for jobcoin_client-0.1.0
Done installing documentation for jobcoin_client after 0 seconds
1 gem installed
05:45 PM
$ irb
irb(main):001:0> require 'jobcoin_client'
=> true
irb(main):002:0> require 'pry'
=> false
You can install it to the system and use a boolean flag to conditionally require it and set breakpoints.
gem install pry
Then in code, something like this:
SET_BREAKPOINTS = ENV["SET_BREAKPOINTS"] == "true"
require 'pry' if SET_BREAKPOINTS
binding.pry if SET_BREAKPINTS
To turn breakpoints on, you can manipulate env through code:
ENV["SET_BREAKPOINTS"] = "true"
or when calling a script from bash:
env SET_BREAKPOINTS=true irb -r 'your_gem'
I'm trying to use this this gem, but even though it shows up with a gem list after I install it, a require 'stopwords-filter' in irb results in LoadError: cannot load such file -- stopwords-filter.
To make sure that I was actually able to install and use gems, I also tried installing this gem and I can require it just fine. Everything works.
What am I missing about stopwords-filter?
Thanks!
Even though the gem is named stopwords-filter, the require statement is just stopwords:
require 'stopwords'
I would like to have unit tests output color in my dev environment. However, I can't make it work on Linux (Debian and Ubuntu). When I include the following libs:
require 'minitest/autorun'
require 'minitest/unit'
require 'minitest/pride'
I get:
/usr/local/rvm/gems/ruby-1.9.2-p136/gems/minitest-2.3.1/lib/minitest/pride.rb:35:in `<top (required)>': undefined method `output' for MiniTest::Unit:Class (NoMethodError)
caused by the code:
MiniTest::Unit.output = PrideIO.new(MiniTest::Unit.output)
I have seen a working Rspec variant. Unfortunately, my Ruby knowledge is not enough to see differences.
Give turn a whirl.
Add this to your Gemfile:
group :test do
gem 'turn', :require => false
end
step 1 : use the latest version of the gem (I think it will be fixed in Ruby 1.9.3)
gem install minitest
step 2 : require "minitest/pride" on the command line, not in your code
ruby -rminitest/pride your_ruby_script.rb
.. and in your code simply require 'minitest/autorun'
require 'minitest/autorun'
If you use Rubymine, just add
-rminitest
in the default configuration of the tests.
=> the configuration would like
-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) -rminitest/pride
simply add these lines to your test_helper.rb file after require 'rails/test_help'
require "minitest/reporters"
Minitest::Reporters.use!
in your gemfile add
gem 'minitest-reporters', '~> 1.0.7'
this will get your rake test to be in red and green, but it also brings up the backtrace. to get rid of all those extra backtrace logs add this to your gemfile then bundle:
gem 'mini_backtrace'
then in config/initializers/backtrace_silencers.rb add this line to cut all the extra rvm stuff
Rails.backtrace_cleaner.add_silencer { |line| line =~ /rvm/ }
hope that works for you, let me know if you need more details.
See https://github.com/tenderlove/purdytest/issues/1. It seems to be a known bug with the minitest version shipped with 1.9.2. For the others, adding
gem "minitest"
at the very top of your file did the trick.
I currently use purdytest with 1.9.2
Try look at this post about using turn gem for nice looking and configurable output for minitest.
http://rawonrails.blogspot.com/2012/01/better-minitest-output-with-turn-gem.html
$ gem install mynyml-redgreen --source http://gemcutter.org
# in your test file
require 'redgreen'
redgreen and turn work nicely in conjunction with each other, by the way
I am on Ubuntu10
sudo apt-get install ruby1.9.1-full
then download sources of rubygem 1.3.7 and install it
sudo ruby setup.rb
then, for example, install sinatra
sudo gem install sinatra
Finally open irb and type
require "rubygems"
require "sinatra"
and get error
LoadError: no such file to load -- sinatra
from (irb):2:in `require'
from (irb):2
from /usr/bin/irb:12:in `<main>'
I had exactly this problem. The problem is that gem and ruby disagree about where the gems live. Compare these:
ruby -e "puts Gem.path"
gem env
gem which sinatra
If you're like my setup, you'll notice that there's an entry in gem env's paths that isn't in Gem.path, and that's exactly where sinatra will claim to be. In my case, I had to add
export GEM_HOME=/usr/lib/ruby/gems/1.9.1
to my .profile. Then everyone was happy.
Execute
sudo gem install sinatra --verbose
and note the path where the gem is getting installed.
Then try this in irb
puts $LOAD_PATH
and make sure that gem is installed in one of the directories in $LOAD_PATH
And ideally just start using http://rvm.beginrescueend.com/
I usually hit this error when I forget:
require 'rubygems'
It'd be helpful if you provided the actual code sample, though, what gem you want to require, and what Ruby version you're using if this doesn't solve the problem.
This was before here on SO quite a few times. Problem is that you probably have two versions of ruby. The one is installing the gem and the other one is trying to use it. Do this in terminal:
$ which -a ruby
Or this:
$ which -a gem
to see if you have more than one version of ruby/gem installed. If so - remove one version (via $ rm or package manager of your system).
I use ruby gems 1.8.7 for a project. I was getting the same error. Use the line require 'rubygems'. It must always be the first require statement, otherwise you can get an error. In my code, I had
require 'watir'
require 'rubygems'
# more code
I got the error - in `require': no such file to load -- watir (LoadError).
When I put rubygems first, the error went away and everything worked. I don't know
why this happens.
Btw, I tried user24359 answer and it did not help me.
C:\code>ruby -e "puts Gem.path"
-e:1: uninitialized constant Gem (NameError)