I have loaded a Ruby project into RubyMine, that has it's spec files located in a spec directory, as usual. Right-clicking and selecting 'run' on any single spec file correctly runs it. Right-clicking and selecting 'run all' on the specs directory causes every test to fail with the following message:
Fail to load: /Users/nathaniel/repos/close-web/spec/compositions/analysis/analysis_data_spec.rb:1
Exception message: cannot load such file -- spec_helper
Inside the launch configuration, the 'Tests folder' seems to be set correctly:
/Users/nathaniel/repos/close-web/spec
And the working directory as well:
/Users/nathaniel/repos/close-web
The Ruby arguments are set like this:
-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) -Itest
(There is some indication on the RubyMine website that -Itest is required.) Under the Bundler tab 'Run the script in the context of the bundle' is checked as well. I'm unclear what else RubyMine might need to be able to recursively find and execute the tests. Running them from the command line works fine:
~repos/closeweb $ bundle exec rspec spec
... (all the tests running)
Finished in 6 minutes 27 seconds (files took 13.39 seconds to load)
1054 examples, 0 failures, 108 pending
What configuration is wrong here that all the tests won't run?
Given that your folder is called spec, not test, you need to -Ispec, not -Itest.
In other words, your RubyMine arguments should be:
-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) -Ispec
From the ruby man page:
-I directory Used to tell Ruby where to load the library scripts.
Directory path will be added to the load-path variable ($:)
Related
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".
So check this out: it appears as though, upon running bundle exec rspec, there's a race between jekyll serve and puma/rspec's boot up. Sometimes I run the command, and my tests run fine. Other times, I get the error for each of my spec files: cannot load such file -- /path/to/project/sitename_jekyll/_layouts/spec/form_spec.rb which is interesting cause that's not where my spec files are located. They're in /path/to/project/sitename_jekyll/spec/form_spec.rb.
What's crazy is that I can literally just re-run the command over and over and over again and sometimes it'll go through and run the spec tests in the correct location, and sometimes it'll look for them in _layouts and error out. It probably runs correctly maybe once out of ever three or five attempts. All the other times I get the following errors:
Here's what my spec_helper.rb looks like: https://gist.github.com/johnhutch/2cddfafcde0485ff021501d5696c0c2d
And here's an example test file:
https://gist.github.com/johnhutch/a35d15c170f5fd9ca07998bf035d111d
My .rspec only contains two lines:
--color
--require spec_helper
And here's the output, both successful and unsuccesful, back to back:
https://gist.github.com/johnhutch/7927d609170ef5c70a595735502b128d
HEEELLLLLP!
This sounds like jekyll is changing the current directory while building the site, which since it is being run in a thread also affects the tests RSpec is trying to run (See https://bugs.ruby-lang.org/issues/9785 for why Dir.chdir is not threadsafe) - leading to attempts to load things from incorrect locations.
A potential solution to this would be to wait for the Jekyll site to be built before actually running your tests. A comment in your spec_helper seems to state that someone thought passing force_build: true would do this but from a quick perusal of the jekyll-rack code I don't think that's true and you actually need to wait for compiling? to return false (v 0.5) (complete? to return true in the current master branch) to ensure building has finished (as well as passing force_build). This could either be done in a loop sleeping and checking (simpler)
sleep 0.1 while <jekyll app>.compiling?
or (if using the master branch) via the mutex/conditional Rack::Jekyll exposes like in its test suite - https://github.com/adaoraul/rack-jekyll/blob/master/test/helper.rb#L49
Note: Also check my comment about your tests that aren't actually testing anything.
As per Thomas Walpole's super helpful responses this ended up working:
sleep 0.1 while Capybara.app.compiling?
inserted right after:
51 Capybara.app = Rack::Jekyll.new(force_build: true)
in my spec_helper.rb
Thanks again, Thomas!
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!
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
The Cucumber feature file runs on the command line, but not in Intellij. I believe this means there are additional configuration steps that I'm missing.
I am using Windows 7, Intellij IDEA 13.1.3, Ruby 1.9.3, Cucumber 1.3.4
Here is my project folder structure:
\cucumber
\projectName
\features
-mainFeature.feature
\step_definitions
-helperFeature.feature
On the command line I navigate to the cucumber folder:
E:\path\to\cucumber\folder\
Then I execute the following command:
bundle exec cucumber projectName/features/mainFeature.feature
And this command runs the cucumber test case successfully.
When I try to run the cucumber test case in Intellij, Intellij is unable to find/load the step definitions. It says that I "can implement step definitions for undefined steps with these snippets" for every single step I use in my features.
The specific error message is:
You can implement step definitions for undefined steps with these snippets:
Then(/^verify the same\-date destination airport grouping strategy$/) do
pending # express the regexp above with the code you wish you had
end
1 scenario (1 undefined)
5 steps (5 undefined)
0m0.014s
Under "Run > Edit Configurations" I've defined the following on the configuration tab:
Feature file: E:\path\to\cucumber\folder\projectName\features\scratchpad_grouping_strategy.feature
Runner options: --color -r features
'cucumber' gem: 1.3.4
Working directory: E:\path\to\cucumber\folder\
Environment variables: [environment variables]
Ruby arguments: -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift);
Ruby SDK: Use other SDK -> 'cucumber' gem: ruby 1.9.3
And under the Bundler tab:
Run the script in context of the bundle (bundle exec) is checked
Suggestions?
I had to specify my working directory correctly. Below is my directory
My working directory: /user/jchiang/test/cucumber
My cucubmer feature files: /user/jchiang/test/cucumber/features
My cucubmer step definitions:/user/jchiang/test/cucumber/lib