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
4
votes
3 answers

With Test::Unit, how can I run a bit of code before all tests (but not each test)?

In my test app, which uses test::unit, I need to start by pulling a bunch of data from various sources. I'd like to only do this once - the data is only read, not written, and doesn't change between tests, and the loading (and error checking for the…
GlyphGryph
  • 4,714
  • 4
  • 32
  • 43
4
votes
2 answers

Rails 3 - How do I test a controller module?

I have 3 controllers which include the same module. How can I test with Test:Unit the module in one place ? Should I write 3 identical functional tests for each controller (not DRY) ? TestController / TestController1 / TestController2 : class…
invaino
  • 267
  • 1
  • 4
  • 13
4
votes
3 answers

How do I stub an http request globally with Test::Unit?

How do I stub an http request, like this one to the twitter api below, on a global scope so it's valid for all tests in a Test::Unit suite? stub_request(:get, "https://api.twitter.com/1/users/show.json?screen_name=digiberber"). with(:headers =>…
oliverbarnes
  • 2,111
  • 1
  • 20
  • 31
4
votes
2 answers

Ruby: how do I use assert_nothing_raised?

assert_nothing_raised do @board.make_move(0,0,Board::HUMAN) end and the docs say: Passes if block does not throw anything. Example: assert_nothing_thrown do [1, 2].uniq end my make_move method: def make_move(x, y, player) return…
NullVoxPopuli
  • 61,906
  • 73
  • 206
  • 352
4
votes
1 answer

How to generate a temporary file for use in a unit test?

The method to test allows adding a path to additional files the user adds which contain data. For example, the user might store a file called data.txt in the /workspace/data directory. And we want to add the path to this directory to an already…
tim_xyz
  • 11,573
  • 17
  • 52
  • 97
4
votes
2 answers

How assertion counts are calculated in test unit

Method 1:- test.rb class Test < Test::Unit::TestCase def test_sample assert_true(test) assert_equal(a,b) end end Result:- Finished in 38.329532529 seconds. 1 tests, 2 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0…
Galet
  • 5,853
  • 21
  • 82
  • 148
4
votes
2 answers

How to re-enable Test::Unit in Rails 4 after 'rails new app --skip-test-unit'

I used rails new app --skip-test-unit because initially, I thought I could add testing later. I developed a significant portion of my app. Now, I would like to add Test::Unit but I couldn't find any documentation on how to do it. Googling only lead…
SimplyTech
  • 41
  • 4
4
votes
1 answer

Rails 4.0 RuntimeError: @controller is nil: make sure you set it in your test's setup method

When I run controller (or functional) tests, Rails 4.0 fails to auto-instantiate a controller instance (@controller) even though the same tests ran fine in Rails 3.2. Any suggestions about how to begin solving this issue? Sample output: $ ruby…
user2069311
  • 134
  • 1
  • 12
4
votes
2 answers

How do I inherit abstract unit tests in Ruby?

I have two unit tests that should share a lot of common tests with slightly different setup methods. If I write something like class Abstract < Test::Unit::TestCase def setup @field = create end def test_1 ... end end class…
Graeme Moss
  • 7,995
  • 4
  • 29
  • 42
4
votes
1 answer

Testing routes with host constraints via assert_routing in Rails

I have a route which I'm using constraints to check the host and then a route which is essentially the same but without the host restriction (these are really namespaces but to make things simple this example will do): match "/(:page_key)" =>…
DEfusion
  • 5,533
  • 5
  • 44
  • 60
4
votes
1 answer

What am I doing wrong with my rakefile?

This is the only thing in my rakefile. Rake::TestTask.new do |t| t.libs << "test" t.test_files = FileList['test/test*.rb'] t.verbose = true end When I run rake the output I get is uninitialized constant Rake::TestTask What am I doing…
Zach
  • 885
  • 2
  • 8
  • 27
4
votes
3 answers

Undefined method 'should' when using Capybara with Cucumber

I am trying to use both Capybara and Cucumber in my Rails application. So, that's what i did: Installed gems needed and added them to the Gemfile Ran the rails generate capybara:install --cucumber Created a feature and its steps definitions for…
shybovycha
  • 11,556
  • 6
  • 52
  • 82
3
votes
2 answers

Can I test nested resources without providing an explicit foreign key?

I'm trying to fix my functional tests for a nested resource. My config/routes.rb file looks like this: Shop360::Application.routes.draw do resources :libraries do resources :library_imports end end Nesting the library_imports resources…
Mike E
  • 5,493
  • 1
  • 14
  • 15
3
votes
1 answer

How can I speed up Rails unit tests involving image upload/resizing?

My app does a lot with images. I use paperclip to attach them to models. I have tons of tests (Test::Unit) that involve creating images, these run pretty slowly. I use FactoryGirl to create models in my tests. This is how I create image…
Nathan Manousos
  • 13,328
  • 2
  • 27
  • 37
3
votes
3 answers

What are the major advantages of rspec over test::unit, if any?

It seems everyone is using rspec these days, yet rails still comes bundled with test::unit by default. Are there any major advantages of rspec over test unit? It's hard to get straight info on this subject...
pixelearth
  • 13,674
  • 10
  • 62
  • 110