TravisCI Ruby project not working with rspec - ruby

I have a Logstash plugin written in Ruby that has started failing on TravisCI, but it works locally. Any ideas what this means?
$ bundle exec rspec spec
The signal EXIT is in use by the JVM and will not work correctly on this platform
Coverage may be inaccurate; set the "--debug" command line option, or do JRUBY_OPTS="--debug" or set the "debug.fullTrace=true" option in your .jrubyrc
W, [2016-12-02T14:12:20.127000 #5894] WARN -- : This usage of the Code Climate Test Reporter is now deprecated. Since version
1.0, we now require you to run `SimpleCov` in your test/spec helper, and then
run the provided `codeclimate-test-reporter` binary separately to report your
results to Code Climate.
More information here: https://github.com/codeclimate/ruby-test-reporter/blob/master/README.md
The command "bundle exec rspec spec" exited with 1.
From here:
https://travis-ci.org/mikebski/logstash-filter-datepart

As you can see on the code-climate/ruby-test-reporter CHANGELOG, you need to replace these lines on your test helper file (in my case spec/spec_helper.rb):
require 'codeclimate-test-reporter'
CodeClimate::TestReporter.start
for these ones:
require 'simplecov'
SimpleCov.start
Henceforth, you also have to call codeclimate-test-reporter explicitly.
Hope it helps!

Related

Ruby test-unit not showing summary after tests

Normally Ruby test-unit will display a summary of tests run after they are finished, something like this:
Finished in 0.117158443 seconds.
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
10 tests, 10 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
298.74 tests/s, 0.00 assertions/s
This was working, but now something has changed and when the unit tests are run it shows the dots but then stops. I tried re-organizing some test file into different directories and made absolutely sure to change the filepaths in the testrunner. Also, the dots do not match the number of tests/assertions.
Loaded suite test
Started
.................$prompt> // <<-- does not put newline here.
I notice that if I run the testrunner from another directory, the summary will show, but it will cause errors with the test dependencies. I should be able to run the testrunner from the same directory. This is an example of the testrunner I am using: https://test-unit.github.io/test-unit/en/file.how-to.html. What are the reasons that this would not display at the end?
Seems like it could be an issue with not having the test-unit.yml file in the same directory as which you run the script.
See here in the code or in the same section in that document you posted.
See how it's configured here, for example:
runner: console
console_options:
color_scheme: inverted
color_schemes:
inverted:
success:
name: red
bold: true
failure:
name: green
bold: true
This part of the code documentation really stuck out:
# ## Test Runners
#
# So, now you have this great test class, but you still
# need a way to run it and view any failures that occur
# during the run. There are some test runner; console test
# runner, GTK+ test runner and so on. The console test
# runner is automatically invoked for you if you require
# 'test/unit' and simply run the file. To use another
# runner simply set default test runner ID to
# Test::Unit::AutoRunner:
Maybe you need to have that runner specified in your YML file?
Without seeing how you are calling your script and your directory organization, it will be hard to tell what is causing that issue but I think it begins with it not reading that yaml file for instance.
If all else fails, let me recommend two great unit testing libraries for Ruby if you feel compelled to switch to a more widely-used library:
minitest
RSpec
Edit: You could also revert your directories to be in the same order as before and hardcode in your Gemfile for that test-unit gem the last version that worked for you, like `"test-unit": "3.4.0".

How do I get the whole error backtrace for rspec?

Currently I am using
parallel tests
rspec
allure 0.8.0
After I run the tests I get the following error:
RSpec::Core::MultipleExceptionError
I need the whole backtrace of the error. Is it some parameter that I need to pass to the command that I use to run and is there a permanent way so that it always prints the whole error
You have two options, to define a helper with that attribute or in command line
## spec/spec_helper.rb
config.full_backtrace = true # false to dismiss
or in the command line
$ rspec spec/folder/your_spec.rb --backtrace
If you get this error you need to find the specific test in the rspec log (scroll up). There you will see details about the issue.
In my case error was shown only on CI and I needed some time in order to figure out that everything I need is "hidden" somewhere in the super long output.

how can I run test files on Windows using rake?

UPDATE: when I run rake test from root, I get:
C:\workspace\faker>rake test
DL is deprecated, please use Fiddle
C:/RailsInstaller/Ruby2.1.0/bin/ruby.exe -w -I"lib;test;." -I"C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib" "C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/rake_test_loader.r
b" "test/test_array_sample_method_compat.rb" "test/test_avatar.rb" "test/test_en_au_ocker_locale.rb" "test/test_en_ca_locale.rb" "test/test_en_locale.rb" "test/test_en_ug_locale.rb" "test/test_en_us_locale.rb" "test/test_es_l
ocale.rb" "test/test_faker.rb" "test/test_faker_app.rb" "test/test_faker_bitcoin.rb" "test/test_faker_book.rb" "test/test_faker_business.rb" "test/test_faker_city.rb" "test/test_faker_code.rb" "test/test_faker_color.rb" "test
/test_faker_commerce.rb" "test/test_faker_company.rb" "test/test_faker_date.rb" "test/test_faker_hacker_talk.rb" "test/test_faker_internet.rb" "test/test_faker_lorem.rb" "test/test_faker_name.rb" "test/test_faker_number.rb" "
test/test_faker_shakespear.rb" "test/test_faker_shakespeare.rb" "test/test_faker_slack_emoji.rb" "test/test_faker_street.rb" "test/test_faker_team.rb" "test/test_faker_time.rb" "test/test_faker_university.rb" "test/test_flexi
ble.rb" "test/test_helper.rb" "test/test_locale.rb" "test/test_pl_locale.rb" "test/test_uk_locale.rb"`
I don't fully understand what rake is doing at this point, but the system hangs infinitely. What am I missing?
So I have built some added functionality for the faker gem, and want to run the tests I wrote before submitting a pull request. However, all my attempts to run the existing tests, and my new tests, have failed. I am worried that it is a Windows machine related issue.
I have tried running rake test:units but it gives me an error and then hangs, while also ringing the Bell on my system 5 times. Strange right?
I have also tried running bundle exec rspec spec, but no tests are found becasue they are not RSpec unit tests, or at least not in the right location.
To see how the gem is formatted, check it out at the repo
All the test files, including my new one, live in the test directory. But for the life of me, I can't run them.
I tried this and works fine:
bundle install
bundle exec ruby test

Cannot test my model tests

I have tests in the folder:
test/models/person/helper/age_calculator_test.rb
These test should fail because of:
assert_equal false, true
they do fail when I run:
bundle exec m test/models/person/helper/age_calculator_test.rb
But when Im running:
bundle exec m test/models
These Tests are not run! What do I wrong?
How can I test all of my Model-Test with Bundler in one command? Thanks!!
It appears that you use the Metal test runner. I cannot see anywhere on its documentation supporting path testing such as test/models. Its main feature is to run tests by line number.
If you would like to execute all of your model tests you could use Rails'
rake test:models
to do it. See the RoR Guide on Rake Tasks for Running your Tests for more options.

Using minitest-reporters with TeamCity (minitest-reporters tries to override reporter selection)

Does anyone have experience with using minitest-reporters for correct test output on TeamCity?
I want to use the JUnit reporter and when I am running the rake test task on my computer, the output is correctly in xml format under test/reports. But when I run the tests from TeamCity, then it tries to use the RubyMine reporter instead (although test_helper specifies JUnit reporter). I found that reports.rb file from mintiest-reporters has these lines:
def self.choose_reporters(console_reporters, env)
if env["TM_PID"]
[RubyMateReporter.new]
elsif env["RM_INFO"] || env["TEAMCITY_VERSION"]
[RubyMineReporter.new]
else
Array(console_reporters)
end
end
And it seems that here the RubiMine reporter is chosen by default when these environment variables are given, although I specified another reprter in my test_helper (and it seems that I could not use the RubiMine reporter as it tries to require some TeamCity files and they somehow cannot be accessed).
I tried to override TEAMCITY_VERSION while calling rake test but it does not seem to work.
Has anyone solved this problem? Or is there some other reporter gem that would work better (I also tried ci_reporter, as it works with my other projects with lower ruby versions but somehow not with 2.0.0)?
I had this exact problem today and was able to solve it by unsetting the 3 environment variables before executing the rake task.
For example, I have a TeamCity command line build step that basically looks like this:
#! /bin/bash
unset TM_PID
unset RM_INFO
unset TEAMCITY_VERSION
rake my_task

Resources