view_test 0.9.0

[ANN] view_test 0.9.0

view_test is a similar implementation of rspec's controller and view specs for test/unit.

It allows you to migrate existing tests one test at a time to create simpler functional tests by extracting out all of the view assertions into their own view_test.

Check it out at http://www.continuousthinking.com/tags/view_test

The goal of view_test is to allow people who are using test/unit to achieve a better level of testing.

Zach Dennis http://www.continuousthinking.com

Forgot to point out the right subclass for controllers. The original post has been updated on http://www.continuousthinking.com/tags/view_test

Functional tests need to subclass Rails::ControllerTest::TestCase View tests need to subclass Rails::ViewTest::TestCase

Zach

Have you looked at Test::Rails in ZenTest? I think rSpec got several of its ideas for view testing from there.

http://zentest.rubyforge.org/ZenTest/classes/Test/Rails.html http://zentest.rubyforge.org/ZenTest/classes/Test/Rails/ControllerTestCase.html http://zentest.rubyforge.org/ZenTest/classes/Test/Rails/ViewTestCase.html

I do like your expect_render. May I steal it?

zdennis wrote:

[ANN] view_test 0.9.0

It allows you to migrate existing tests one test at a time to create simpler functional tests by extracting out all of the view assertions into their own view_test.

Check it out athttp://www.continuousthinking.com/tags/view_test

Does it peacefully coexist with form_test_helper?

I'm naturally incapable of excluding pilot error, but I suspect that ZenTest's ViewTestCase and form_test_helper collude to produce a nasty error. I will reproduce it on request...

> [ANN] view_test 0.9.0

> view_test is a similar implementation of rspec's controller and view > specs for test/unit.

> It allows you to migrate existing tests one test at a time to create > simpler functional tests > by extracting out all of the view assertions into their own view_test.

> Check it out athttp://www.continuousthinking.com/tags/view_test

> The goal of view_test is to allow people who are using test/unit to > achieve a better level of > testing.

Have you looked at Test::Rails in ZenTest? I think rSpec got several of its ideas for view testing from there.

A while back I checked it out, I think I need to give it a better look.

http://zentest.rubyforge.org/ZenTest/classes/Test/Rails.htmlhttp://zentest.rubyforge.org/ZenTest/classes/Test/Rails/ ControllerTestCase.htmlhttp://zentest.rubyforge.org/ZenTest/classes/Test/Rails/ ViewTestCase.html

I do like your expect_render. May I steal it?

Absolutey, stealeth away!

Zach

zdennis wrote:

> [ANN] view_test 0.9.0

> It allows you to migrate existing tests one test at a time to create > simpler functional tests > by extracting out all of the view assertions into their own view_test. > > Check it out athttp://www.continuousthinking.com/tags/view_test

Does it peacefully coexist with form_test_helper?

Here's the ZenTest + form_test_helper code that fails:

class ForumViewTest < Test::Rails::ViewTestCase   self.use_transactional_fixtures = mysql_tests? # true   fixtures :users, :rings

  def test_host_ring     login_as :BunBun     render :action => 'index'

    submit_form 'host_ring_form' do |post|       assert_equal users(:BunBun).id, post['user[id]'].value.to_i       post['ring_name'] = 'progidy'     end   end ...

The failure message complains about @session being both deprecated and already set. It appears below my sig.

The only overt @session assignment I can find in our beloved maze of metaprogrammed Rails code and plugins is up in ZenTest, but if I change that to 'session' the error persists. I can then add a 'p @session' to anywhere in my test case, and it returns nil.

So should I switch to view_test?

Did you file a bug? I don't see one in the tracker.

> Here's the ZenTest + form_test_helper code that fails:

Did you file a bug? I don't see one in the tracker.

Will do. I didn't yet because form_test_helper could need the bug report...

> [ANN] view_test 0.9.0 > > view_test is a similar implementation of rspec's controller and view > specs for test/unit. > > It allows you to migrate existing tests one test at a time to create > simpler functional tests > by extracting out all of the view assertions into their own view_test. > > Check it out at http://www.continuousthinking.com/tags/view_test > > The goal of view_test is to allow people who are using test/unit to > achieve a better level of > testing.

Have you looked at Test::Rails in ZenTest? I think rSpec got several of its ideas for view testing from there.

Eric - it definitely did. Initially RSpec's Rails plugin wrapped ZenTest, but there were some things that I wanted to do differently so I took what was needed and broke the dependency. You and Ryan are credited in the license: http://rspec.rubyforge.org/license.html

For view tests yes. For functional/controller tests no because the views are no longer rendered here.

Zach http://www.continuousthinking.com

zdennis wrote:

Forgot to point out the right subclass for controllers. The original post has been updated on http://www.continuousthinking.com/tags/view_test

Functional tests need to subclass Rails::ControllerTest::TestCase View tests need to subclass Rails::ViewTest::TestCase

Does anyone have a reason for this error message?

  rake aborted!   uninitialized constant Mocha::ParameterMatchers

We have sufficient mocha:

$ gem list | grep -i mocha mocha (0.5.4, 0.5.1)

I will add a require to our test case and keep going...

If you think this might be a Mocha bug (which it may well be), can you send some more details to the mocha mailing list (http://rubyforge.org/mailman/listinfo/mocha-developer ) and we’ll look into it for you.

Thanks.