Questions tagged [testunit]

Test-unit is a unit testing library in Ruby. It was part of the standard library in Ruby 1.8, and there's a compatibility layer in the standard library of Ruby 1.9.

Test-unit is a unit testing library in Ruby. It was part of the standard library in Ruby 1.8, and there's a compatibility layer in the standard library of Ruby 1.9.

Test::Unit (test-unit) is unit testing framework for Ruby, based on xUnit principles. These were originally designed by Kent Beck, creator of extreme programming software development methodology, for Smalltalk's SUnit. It allows writing tests, checking results and automated testing in Ruby.

366 questions
168
votes
5 answers

How can I tell Rails to use RSpec instead of test-unit when creating a new Rails app?

I have test-unit installed and rspec installed (along with -core, -expectations, -mocks and -rails version 2.6.x). When I run the command rails new foo, it uses test-unit to generate the test stub files instead of rspec. Is there an option where I…
aarona
  • 35,986
  • 41
  • 138
  • 186
82
votes
9 answers

Ruby on Rails: Switch from test_unit to rspec

I'm going through a tutorial that has suggested using rspec, but I have already gone through a lot of default rails installation. I really don't want to have to redo the installation at all. Anyway, when I run $ rails g integration_test named I…
Explosion Pills
  • 188,624
  • 52
  • 326
  • 405
50
votes
3 answers

Test::Unit Rails - How to assert one number is greater than another one?

I am writing my first unit tests with Test::Unit and I have reached a point where I need to compare two numbers. Much to my surprise, I have discovered that none of the following were…
Amokrane Chentir
  • 29,907
  • 37
  • 114
  • 158
42
votes
6 answers

Rspec vs. TestUnit

I'm beginning the planning phase of creating a testing suite for my rails 3.0.8 application. I'm trying to decide on which testing framework/gems to use. Normally I prefer to stick to Rails convention as much as possible. However, this means using…
dhulihan
  • 11,053
  • 9
  • 40
  • 45
36
votes
2 answers

How do I execute a single test using Ruby test/unit?

Instead of running all the test cases automatically, is there any way to execute a single test under ruby test/unit framework. I know I can achieve that by using Rake but I am not ready to switch to rake at this moment. ruby unit_test.rb #this…
pierrotlefou
  • 39,805
  • 37
  • 135
  • 175
34
votes
6 answers

How to use assert_select to test for presence of a given link?

My page should contain a link that looks like Click to go. How would you test for that using assert_select? I want to check for the presence of an a tag with href="/desired_path/1". How do you test the attributes of a…
B Seven
  • 44,484
  • 66
  • 240
  • 385
31
votes
2 answers

minitest, test::unit, and rails

I read somewhere that 'minitest' is the "new test::unit for ruby 1.9.2+". But ruby 1.9.3 seems to include both test::unit and minitest, is that true? In the default rails testing, as outlined in the Rails testing guide.... things like…
jrochkind
  • 22,799
  • 12
  • 59
  • 74
29
votes
10 answers

In Ruby's Test::Unit::TestCase, how do I override the initialize method?

I'm struggling with Test::Unit. When I think of unit tests, I think of one simple test per file. But in Ruby's framework, I must instead write: class MyTest < Test::Unit::TestCase def setup end def test_1 end def test_1 …
someguy
  • 1,923
  • 5
  • 21
  • 19
21
votes
4 answers

How do you "nest" or "group" Test::Unit tests?

RSpec has: describe "the user" do before(:each) do @user = Factory :user end it "should have access" do @user.should ... end end How would you group tests like that with Test::Unit? For example, in my controller test, I want to…
danneu
  • 9,244
  • 3
  • 35
  • 63
21
votes
2 answers

Global setup and teardown blocks in Test::Unit

What's the best way to have a setup run before every method in an entire test suite (not just one test class)? Rspec allows you to define global before and after blocks. Is there a clean comparable way to do this in Test::Unit that doesn't involve…
samg
  • 3,496
  • 1
  • 25
  • 26
20
votes
2 answers

What is the best practice for organizing Ruby test folder structure?

In Java typically you would create two source folders src and test with an identical package hierarchy. In Ruby do you just put all the tests in the same folder as the class under test? Or do you create a similar hierarchy in a separate folder? If…
Garrett Hall
  • 29,524
  • 10
  • 61
  • 76
17
votes
5 answers

Is Test::Unit still relevant in rails?

I am learning Rails the age old way. By reading Agile Web Development with Rails (3rd Edition) as a starting point. I am currently in the chapter that teaches Testing. I am also aware of other BDD Testing framework such as RSPec. So I was wondering…
tundal45
  • 193
  • 3
  • 14
  • 33
17
votes
4 answers

How to run multiple Rails unit tests at once

I often run the various test groups like: rake test:units rake test:functionals I also like to run individual test files or individual tests: ruby -Itest test/unit/file_test.rb ruby -Itest test/unit/file_test.rb -n '/some context Im working…
gtd
  • 16,956
  • 6
  • 49
  • 65
16
votes
3 answers

How to programmatically sign in a user through Devise in Rails

I need to have a custom mechanism for signing in using Devise with Rails 4. So I found the sign_in method in Devise's test helpers section of their documentation: sign_in @user # sign_in(resource) But is that the proper way to sign someone…
at.
  • 50,922
  • 104
  • 292
  • 461
16
votes
13 answers

Setup Factory Girl with Test::Unit and Shoulda

I'm trying to set up Factory Girl with Test::Unit and Shoulda in Ruby on Rails. I have installed the gem, created my factory file under the test/factories directory, and created my spec file under the test/models directory. The current error I'm…
NolanDC
  • 1,041
  • 2
  • 12
  • 35
1
2 3
24 25