Newbie help

I am having a problem with using the test-unit gem

I get a NoMethodError when I simply do

require ‘test/unit/assertions’
#I’ve also used just require ‘test/unit’

def test
assert_equal(true, true)
end

test

Sorry for such a simple question

I’m now reading that I have to be using ActiveRecord to use test-unit?
Is that correct?

Se Ed wrote:

I’m now reading that I have to be using ActiveRecord to use test-unit?
Is that correct?

I don’t think it is correct…but you probably want to be using RSpec
anyway. It’s a much friendlier test framework.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

On Jan 22, 2010, at 1:46 PM, Se Ed wrote:

test

Sorry for such a simple question

You should be creating a subclass of Test::Unit::TestCase in your file
and defining tests within that.

in a file named my_test.rb (just convention, call it fred.rb if you

like)

require ‘test/unit’

class MyTest < Test::Unit::TestCase

def test_starting_simple
assert_equal(true, true)
end

end
END

Then run that file with “ruby ./my_test.rb” to get:

$ ruby ./my_test.rb
Loaded suite ./my_test
Started
.
Finished in 0.000476 seconds.

1 tests, 1 assertions, 0 failures, 0 errors

That should get you going.

-Rob

Rob B. http://agileconsultingllc.com
[email protected]

At 2010-01-22 01:46PM, “Se Ed” wrote:

I am having a problem with using the test-unit gem

I get a NoMethodError when I simply do

require ‘test/unit/assertions’
#I’ve also used just require ‘test/unit’

def test
assert_equal(true, true)
end

The Test::Unit::Assertions module defines instance methods, so you have
to mix that module in to some object or class.

You can do this:

include Test::Unit::Assertions
def test
  assert_equal(true, true)
end

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs