Pathname.rb error on running a minitest testcase - ruby

I'm running Ruby 1.8.6.
I installed the minitest 1.3.1 gem, which is the new defacto replacement for the Test::Unit framework in Ruby 1.9 The API is supposed to be the same.
I wrote a small test to get things rolling:
require 'rubygems'
gem 'minitest'
require 'minitest/unit'
MiniTest::Unit.autorun
class CategoryMiniTest < MiniTest::Unit::TestCase
def test_twoCategoriesCannotHaveSameName
assert_equals(2,2)
end
end
Which leads to:
>ruby test\unit\category_mini_test.rb
l:/ruby_home/lib/ruby/1.8/pathname.rb:709:in `relative_path_from': different prefix: "l:/" and "L:/Gishu/Ruby/Rails/ShowMeTheMoney" (ArgumentError)
from l:/ruby_home/lib/ruby/gems/1.8/gems/minitest-1.3.1/lib/minitest/unit.rb:17
What gives?

I can't see anything wrong with your code. It looks almost exactly the same as the Ruby 1.8.6 & MiniTest example in my blog post: Test::Unit and MiniTest with different Ruby versions.
So I wonder if it is:
something to do with your environment,
something to do with how you are running the test, or
a bug in MiniTest.
Looking at the error message, I wonder whether the problem is with case-sensitivity - the upper-case and lower-case L drive letters may not match.

Related

Simplecov fails to exit on rspec suite completion in Ruby 2.6.3

So after upgrading the Ruby version used with my app from 2.5.5 to 2.6.3, simplecov 0.17.0 now hangs silently and permanently at the end of my test suite.
I'm running Ruby 2.6.3 and Rails 5.2.3.
As for what else may be relevant, I have capybara 3.26.0 running and I'm using RSpec.
One thing I tried is adding "use_merging false" to my SimpleCov.start block, as I saw that suggested out and about. No luck for me.
Here's an example of the output I get:
138 examples, 0 failures, 1 pending
Randomized with seed 29475
Then that's where it hangs.
Any help is greatly appreciated!
Edit: SimpleCov config:
SimpleCov.start :rails do
add_filter "/app/channels/"
add_filter "/app/jobs/"
add_filter "/app/mailers"
end
From https://github.com/colszowka/simplecov
If you're making a Rails application, SimpleCov comes with built-in configurations (see below for information on profiles) that will get you started with groups for your Controllers, Views, Models and Helpers. To use it, the first two lines of your test_helper should be like this:
require 'simplecov'
SimpleCov.start 'rails'
The documenation also states:
Load and launch SimpleCov at the very top of your test/test_helper.rb (or spec_helper.rb, rails_helper, cucumber env.rb, or whatever your preferred test framework uses):
require 'simplecov'
SimpleCov.start
If this does not help, please share your simplecov entry in your Gemfile and the test-, spec-, rails_helper.

Ruby RSpec test for success or failure based on gem version being used

Is there a way to write an Rspec test to prove that some code fails if we are using a specific version of a gem and passes if we use another version of the same gem?
What I do currently is have one version in my Gemfile and then run rspec spec and see a test pass. Then I modify my Gemfile with the different gem version and bundle update and then run rspec spec again and see the same test fail.
I would like to have two tests, one that loads one version of the gem and tests for normal execution and succeeds and another test that loads a different version of the gem and tests for an exception and succeeds on the raised exception and both tests are run on the same rspec spec run. Is this even possible. If not, any suggestions on anything that does not involve me having to modify my Gemfile manually?
Also, in case it helps
I currently use bundler to install gems.
ruby 1.9.3p545
rspec 2.14.1
Also, I am not using Rails
I think you can specify the gem and version you want to use in the code:
it "does something" do
gem "gemname", "4.0"
require "gemname"
expect(subject).to do_something
end
But I don't know if what you're trying to do is a good idea because you should be testing with the same gems you would be using in production.
You could define a different environment to include the alternative version of your gem and use this while testing. For example, in your Gemfile
group :custom_test do
gem 'gemname', 'x.y.z'
end
And then run your tests as in
RAILS_ENV=custom_test rspec
I strongly suggest however that you look into solutions that let you test against different environments, gemfiles, rails and ruby versions (e.g. Jenkins or Travis etc.)

Error when trying to run a minitest unit test

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.

Ruby's autoload not working in 1.8.7 or Ruby Enterprise?

I've written a gem and within a file I am doing this to autoload my main gem logic:
$:.push File.expand_path('lib', __FILE__)
require "oa-casport/version"
require 'omniauth/core'
module OmniAuth
module Strategies
autoload :Casport, 'omniauth/strategies/casport'
end
end
For Ruby versions 1.8.7 and ree, it prints out "no such file to load - omniauth/strategies/casport'
But it doesn't print out this message on version 1.9.2. Is there something off with the location of calling autoload?
The repo for the gem is located at https://github.com/stevenhaddox/oa-casport
EDIT: My gem works for Rails 2 and 3 regardless of version, but doesn't work on Sinatra when using Ruby/REE 1.8.7. Any ideas?
You're adding a wrong path to $LOAD_PATH.
File.expand_path('lib', __FILE__) will evaluate to ${GEM_PATH}/lib/oa-casport.rb/lib which obviously doesn't exist.
Instead, specify your paths in your gemspec:
Gem::Specification.new do |spec|
# ...
spec.require_paths = [ 'lib' ]
# ...
end
PS: Just to solve the initial problem: You probably meant to add the following to $LOAD_PATH: File.expand_path(File.dirname __FILE__).
I checked out the code and it looks like it loads fine with Rails 2 or Rails 3 with Ruby 1.8.7 and 1.9.2, but is only having issues with Sinatra under Ruby 1.8.7 (loads fine with 1.9.2).
I'm still not sure why the discrepancy, but I'll keep looking into it when I get a chance. The fact that it works in most of the environments above seems to tell me the $:.push line isn't really causing any problems (but it may not be necessary since you're using git to package your gem files already in the .gemspec).

Unable to generate xml results with ci_reporter using Ruby 1.9.2 with Watir

I have installed Watir 1.7.1, Ruby 1.9.2, ci_reporter 1.6.4, test unit 2.2.0.
Since testunit donot come with Ruby 1.9.2, I installed the testunit seperately.
When I run the script, ci_reporter donot create 'test/reports' folder in the directory iam running the tests. When i execute the script, script runs fine but the folder is not created.
Does the folder 'test/reports' gets created by itself or the 'test/reports' folder should be as part of testunit.
Following is the simple test iam running, please look at the code snippet :
gem 'test-unit'
require 'test/unit/ui/console/testrunner.rb'
require 'ci/reporter/rake/test_unit_loader.rb'
require 'watir'
class My_Test < Test::Unit::TestCase
def test_me
browser = Watir::IE.start('http://www.google.com')
assert(browser.link(:text, 'About Google').exists?)
browser.close
end
end
Does ruby 1.9.2 support ci_reporter 1.6.4?
Can any one help me with an example as to how the reports would be created by ci_reporter and where the reports get stored?
Based on Tiffany's response and the link she gave, I think the answer to your question is 'NO. it is not supported at this time'
I'd also echo the recommendation to use 1.8.7 that's what I've been using for a while now and it is working good with watir.
I think most folks are still using ruby 1.8.7 with Watir. I'm still on 1.8.7, and I use ci_reporter with Watir every day without any problems.
Any chance you can try your code in a 1.8.7 environment? I just found this blog post that indicates that ci_reporter has not been updated to work with ruby 1.9.2: http://www.larkware.com/posts/fix-ci-reporter-for-test-unit-2-dot-0

Resources