Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a single shoulda context test in ruby Test::Unit framework

Tags:

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.

like image 430
Joe Dean Avatar asked Oct 29 '09 06:10

Joe Dean


People also ask

How do I run a test case in Ruby?

We can run all of our tests at once by using the bin/rails test command. Or we can run a single test file by passing the bin/rails test command the filename containing the test cases.

What is the testing framework for Ruby?

RSpec is a popular BDD framework for testing Ruby/Rails applications. Depending on your project type (Ruby or Rails), use the rspec or rspec-rails gem.


2 Answers

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.

like image 162
Milan Novota Avatar answered Oct 06 '22 09:10

Milan Novota


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. " 
like image 45
Shadwell Avatar answered Oct 06 '22 10:10

Shadwell