I've recently migrated from TextMate to RubyMine and have really liked it so far. One thing I noticed was that RubyMine doesn't have a Steak plugin like TextMate does, which allows the ability to run a single scenario.
Is there any way to do the same in RubyMine or am I stuck running the full file of acceptance tests everytime I want to run a single Steak test?
Steak is an extension for rspec. To run single tests in rspec you can specify a --tag
describe 'run this test', :focus => true do
# this one will run
end
describe 'but not this one' do
# wont get run
end
$ rspec --tag focus my_spec_file.rb
(Note: I've never used rubymine)
Related
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.
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
I have some slow RSpec tests that I've tagged with :slow. I've set RSpec up to skip them default by adding the line config.filter_run_excluding slow: true to my RSpec configuration. And I can run the slow tests by running rspec --tag slow.
But how can I run all the tests using one command, including slow and non-slow tests? I can't figure it out from the docs.
You can find a similar question here : Command line to run all examples in RSpec, including ones that are filtered out?
In few words, this feature doesn't exist on rspec but you can use env variable :
RSpec.configure do |c|
c.filter_run_excluding slow: true unless ENV['ALL']
end
Call ALL=1 rspec will run all the specs including the slow tag.
I can typically test a regular Test::Unit method using the following commandline syntax for a method "delete_user_test":
ruby functional/user_controller_test.rb -n delete_user_test
Now when I'm using the shoulda plugin with Test::Unit I try to use the same technique as follows:
...
context "Deleting a User" do
should "remove user from user table" do
...
end
end
Then I try to run the single test as follows:
ruby functional/user_controller_test.rb -n "test: Deleting a User should remove user from user table"
This doesn't work. Does anyone know how I can run a single context tests using shoulda and Test::Unit. I have a couple of different test in one test file and I want to only run the one using TDD without having to wait for all tests to run.
This works for me:
ruby functional/user_controller_test.rb -n "/Deleting a User/"
Just put some reasonably long string from your context name into the regular expression.
Using the full name of the test with a space at the end seems to work too:
ruby -Itest
functional/user_controller_test.rb
-n "test: Deleting a user should remove user from user table. "
Combining the two approaches has worked well for me; using both -I test and the regexp.
ruby -Itest functional/user_controller_teset.rb -n "/remove user from user table/"
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.