Forum: Ruby on Rails Starting unit testing with Rake?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
59ea1b450935b9d70abfec4186b7a4d5?d=identicon&s=25 Jeff Coleman (progressions)
on 2007-01-27 02:35
(Received via mailing list)
I feel silly for asking this, but how do I start unit testing with
Rake?

I'm just getting started setting up unit tests and learning about it,
but my googling hasn't turned up any straightforward "getting started"
tutorials for running my unit tests with Rake.

I've set up a few simple unit tests to start with and I'm not sure how
to actually run them.  I see reference to just running "rake" or "rake
test:units" but those don't seem to run my tests.  What more do I need
to do?

Thanks in advance,
Jeff
Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2007-01-27 03:13
(Received via mailing list)
progressions wrote:

> I've set up a few simple unit tests to start with and I'm not sure how
> to actually run them.  I see reference to just running "rake" or "rake
> test:units" but those don't seem to run my tests.  What more do I need
> to do?

Post some code; you might have the test declared wrong.

rake alone will run rake test

Where are your unit tests? Are they in the test/*/ folders where the
rake test task expects them?

Would this run them?

   ruby test/unit/my_model_test.rb

The Agile Web Development with Rails book laid all this out, if I
recall correctly. But that was a long, long time ago in Rails-time.
Last month, I think...

--
  Phlip
  http://c2.com/cgi/wiki?ZeekLand  <-- NOT a blog!!
59ea1b450935b9d70abfec4186b7a4d5?d=identicon&s=25 Jeff Coleman (progressions)
on 2007-01-27 04:45
(Received via mailing list)
On Jan 26, 8:13 pm, Phlip <phlip2...@gmail.com> wrote:
> progressions wrote:
> > I've set up a few simple unit tests to start with and I'm not sure how
> > to actually run them.  I see reference to just running "rake" or "rake
> > test:units" but those don't seem to run my tests.  What more do I need
> > to do?Post some code; you might have the test declared wrong.
>
> rake alone will run rake test
>
> Where are your unit tests? Are they in the test/*/ folders where the
> rake test task expects them?

I haven't done much of anything to the tests.  They're right where they
should.  I'm trying to run test/unit/comic_test.rb (from the model
"comic") and it does nothing.

> Would this run them?
>
>    ruby test/unit/my_model_test.rb

This doesn't do anything:

C:\rails\comics\trunk>ruby test/unit/comic_test.rb

C:\rails\comics\trunk>ruby test/unit/comic_test.rb

C:\rails\comics\trunk>

...I tried putting a "puts" statement in the comic_test.rb file to
verify that it would run at all, and it does.  But the testing engine
doesn't seem to get invoked at all.

> The Agile Web Development with Rails book laid all this out, if I
> recall correctly. But that was a long, long time ago in Rails-time.
> Last month, I think...

I'm definitely planning on getting the second edition when I can, but I
don't have it yet.

> --
>   Phlip
>  http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!

Thanks for the help.

Jeff
Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2007-01-27 05:17
(Received via mailing list)
progressions wrote:

> This doesn't do anything:
>
> C:\rails\comics\trunk>ruby test/unit/comic_test.rb
>
> C:\rails\comics\trunk>ruby test/unit/comic_test.rb

Start with the obvious stuff. Your 'puter is turned on, and 'ruby -v'
prints
Ruby's version, right?

Next, the first 5 lines of your test should look like this:

require File.dirname(__FILE__) + '/../test_helper'

class ChatTest < Test::Rails::TestCase

  def test_something
    assert false
  end

Tests work by inheriting a class that registers each of its children in
a
test runner. You might try 'Test::Unit' or 'Test::Rails' there - I seem
to
recall the 'Rails' might be from one of my plugins.

If that doesn't work, write a new source file with only this in it:

require 'test/unit'

class TestAnything < Test::Unit::TestCase  #  "it has come to this"
--Poo...
    def test_anything
        assert false
    end
end

If you can't get that working, post to the Ruby newsgroup, and work your
way
back to Rails!

--
  Phlip
  http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
59ea1b450935b9d70abfec4186b7a4d5?d=identicon&s=25 Jeff Coleman (progressions)
on 2007-01-27 05:58
(Received via mailing list)
Hm.  I'm guessing this line I put in my environment.rb might have
something to do with it?

 Test::Unit.run = true

:)  Was advised to put that in because it was running tests on my
production server and forgot about it til now.  Sorry about that!

Jeff
This topic is locked and can not be replied to.