RubyMine tries to run tests from ActionController::TestCase and similar classes - ruby-on-rails

I'm using Minitest::Spec to write my tests. I've added gem 'minitest-reporters' to my Gemfile so that RubyMine can work property. An it is, except some (IMHO) strange behavior.
Let's say I want to run 'uuid_validator_test.rb' file that contains UUIDValidator test. I do that right-clicking on the file and then click 'Run ...'. RubyMine starts running the test, but for some strange reason also tries to run tests from ActionController::TestCase and similar classes. You can see it on the picture below:
Why is this happening and how can I force it to run just UUIDValidator test?

Related

Can rspec be configured to only run tests what have been modified within a single spec file?

I'm working with Rails 5 and rspec (gem version 4). I was wondering if RSpec can be configured to only run tests that have been modified within a single file when only running that file, i.e.
bundle exec rspec spec/my_spec.rb
. If my file is like this
RSpec.describe MyClass do
context "context 1" do
it "tests condition 1" do
end
it "tests condition 2" do
end
...
end
context "context 2" do
...
end
...
end
and I only update tests in "context 1," is it possible to test the single file and have only modified tests from within that file run? With respect to this answer -- Can I get RSpec to only run changed specs?, it appears that only relates to actual files that have changed when running the complete suite of rspec tests.
I think you are looking for guard.
Checkout nicely written article https://collectiveidea.com/blog/archives/2017/02/09/guard-is-your-friend
There is a Ruby Gem called retest designed to do exactly that. Just run retest, and it will watch for changes in the code or the specs themselves, and rerun just the respective spec file.

Run single system test

To run a single test in Rails, we normally do:
rails test TEST=test/system/invitation_test.rb
But that doesn't work with system tests. Neither do this work:
rails test:system TEST=test/system/invitation_test.rb
With both those commandos above, all system tests (files) are run.
So my question is, how can I run a single system test?
As a side note, to run (all) system tests in Rails, you need to append :system to test.
rails test:system
While rails test doesn't seem to work if you want to run your system tests (you need to append test with :system), if you only want to run a single test it does seem to work:
rails test test/system/my_little_test.rb

Tests that don't include spec_helper being ignored in rspec runs

When testing lib code there is rarely any need to require spec_helper and load all of rails. This is why I have been removing require "spec_helper" in favour of require_relative "../../lib/my_lib.rb".
These tests pass when called directly (rspec spec/lib/my_lib.rb) and are blazingly fast. Winner.
My issue comes when I try and run these tests as a group.
When I call rspec spec/lib it runs any lib specs that have a require "spec_helper" line but not any tests that don't.
I have played with spec_helper.rb to load in these tests, and that kind of works only it means that when I run rspec spec/models/blah.rb it will also run these lib tests, which obviously isn't what I want.
Is there a different way I should be calling my tests? Or is there a way I can get them added to the test run?
Notes
My spec_helper is configured to run the tests in a random order, I wonder if this has anything to do with it?
You should add _spec to your files:
spec/lib/my_lib_spec.rb
Rspec rake task will look only for files which end in _spec.

Getting Capybara::DriverNotFoundError when trying to run Cucumber tests

I'm getting this error when I run the cucumber tests. Everything seemed to be working fine the previous day but I can't figure out why it stopped working. I was trying to get capybara webkit working and I had changed a couple of files but I don't see why it should affect my tests. Any idea on how to fix this error I'm getting while running the cucumber tests?
Capybara::DriverNotFoundError: no driver called :rack was found, available drivers: :rack_test, :selenium, :webkit, :webkit_debug
You mentioned that you edited many files. Could it be that you didn't revert all the changes you made? I think Capybara would pick the 'rack_test' driver by default, and your system could not find the 'rack' driver.
Since you're doing Cucumber testing, you must have a file called 'env.rb' under the features/support folder. Make sure you don't force 'rack' as your Capybara driver, and your tests should run fine.

What's `rspec/autorun` for?

I was having some problem with zeus + rspec and the solution I found says that I must to delete require 'rspec/autorun' from spec_helper.rb.
That worked great, but I was wondering what's the utility of rspec/autorun? It comes in spec_helper.rb by default, but the specs works anyway with or without it.
As far as i understand, you would need rspec/autorun if you want to run specs using "ruby" command.
From RSpec docs:
Generally, life is simpler if you just use the rspec command. If you must use the ruby command, however, you’ll want to do the following:
require 'rspec/autorun'
rspec/autorun installs an at_exit hook that runs your tests. That way you can simply execute your testfiles directly rather than passing them to the rspec command (and a few other tricks, like having tests run automatically when you execute a library file).
Most setups don't need it.

Resources