Run single system test - ruby-on-rails

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

Related

What does `rails spec` do that `rspec` does not?

What is it that rails spec does, if anything, that rspec alone does not?
I was looking for a way to run only specific RSpec tests from the command line, and the only way I found requires running rspec directly (rspec --tag focus ..., not via rails spec. I could do that, but I'm concerned that maybe doing so bypassing some important setup or other functionality.
It seems it calls rails test:prepare before actually calling rspec:
https://github.com/rspec/rspec-rails/blob/master/lib/rspec/rails/tasks/rspec.rake#L11

Run only one test on CircleCI (Rails)

Sometimes I have a broken test on CircleCI, where the error can't be replicated locally. Instead of waiting for the whole suite to run, I'd like to run that one test individually. (I know I can ssh in, but that's time-consuming and running it that way wouldn't exactly replicate the usual automated test sequence.)
My aim is to make a temporary config commit to run just one test (ideally just a test method, but the whole class would be fine too). I can think of two possible solutions: (A) edit app.rake to make the default rake task run a single test; or (B) edit circle.yml to run just the one test from command-line using rake test. Any clue on either of these?

Rubymine: How to run single test via Rail5 test runner?

You can run single test using Rails 5 test runner by specifying the file and the linenumber like the following:
rails test path/to/test:55
In RubyMine, you can run single test from context menu on a test you want to run. However, since it is not via the above test runner, it does not use a spring preloader and takes long to launch a test.
I have tried to create new Run/Debug configuration to run test via spring, but I am still not sure how to do it.
Please let me know how to run single test via Rail5 test runner?

When To Use A Particular Rails Environment for Testing?

I am teaching myself Ruby On Rails with Michael Hartl's Book. When it uncovered the use of seeds.rb file, I tested within Development Environment, it Failed. When set to Test Environment, It Succeeded. Why? When will I need to change the environment again for successful tests?
When you say I tested within Development Environment, it Failed., you are not running automated tests. You ran the rake db:seed script against the development database. The same task can be run against the test environment with rake db:seed RAILS_ENV=test. Again, this is not an automated test.
There are many reasons why rake db:seed run against the development environment failed in your case. The specific reason could be identified based on the error message.
development environment is one where you work on a day to day basis, adding/changing functionality by making code changes. By default, most scripts assume that you are working with development environment.
test environment is the environment against which the automated tests are run. In the case of rails tutorial, the automated tests are written in the files under test folder. When automated tests are run on a rails application - with rake test or some other way - the test environment is used to run these tests against. The test database gets cleaned up before running the tests to ensure the tests are run starting with a blank state.
Hope this clarifies.

Can 'cucumber' run my rspec-on-rails tests?

I have a small test project that I'm using to test the waters for a much larger project. I am using rspec on rails for testing, but recently looked into Cucumber. It looks very nice, but I'm wondering if there's a way for cucumber to run my spec tests, or for rspec (autospec) to run my cucumber features. I've looked around extensively, but have yet to find a solid conclusion.
Thanks,
Mike
I've been experimenting with Cucumber as well. It supports autotest:
AUTOFEATURE=true autospec
That runs both the rspec & cucumber test suite continuously.
An easy way to do this would be to create a Rake task that invokes both tools, such as this minimal example:
desc 'Run rspec + cucumber'
task :build => [:spec, :features]
Then you can build both with:
rake build
Both RSpec and Cucumber come with some default tasks which work with Rails, but you can customize the tasks to suit your needs. There's more info on writing rake tasks here.
Depends on what you are looking for, but the best way to run cucumber tests with rspec is to use turnip, which uses exactly the same feature syntax as cucumber (the syntax is called gherkin), but allows you to use most of the functionality of rspec. https://github.com/jnicklas/turnip.
If you want to take things one step further, you can run your features from inside rspec _spec.rb files using a gem we created called rutabaga. https://github.com/simplybusiness/rutabaga
In both cases, all the tests can be run by executing rspec or bundle exec rspec as needed.

Resources