Forum: Ruby on Rails Reusing functional tests with rails 4

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.
A00673345921ae8c2e5570d1bd48b2e2?d=identicon&s=25 J. mp (lerias)
on 2013-07-19 13:44
(Received via mailing list)
With rails 4, I have this test for one controller:

class Merchant::RegistrationsControllerTest < ActionController::TestCase
  test "should create new registration" do
    user = FactoryGirl.build(:merchant_user)
    #rest of the test using user as input for the controler
   end

  test "should not create new registration" do
    user = FactoryGirl.build(:merchant_user)
    #rest of the test using user as input for the controler
  endend

And this other test for other controller:

class FrontStore::RegistrationsControllerTest <
ActionController::TestCase
  test "should create new registration" do
    user = FactoryGirl.build(:front_store_user)
    #rest of the test using user as input for the controler
   end

  test "should not create new registration" do
    user = FactoryGirl.build(:front_store_user)
    #rest of the test using user as input for the controler
  endend

As you can see, Is violation of the DRY principle, because my tests are
the
same, but using a different fixture.

As a note, both controllers inherits from the
ApplicationRegistrationsController, that implements all the behaviour to
both Merchant::RegistrationsController and
FrontStore::RegistrationsController.

I want to run both test for each of the role (Merchant or FrontStore)
but
not repeating the test code.

My question is, how best design the test so they are reusable in this
case?
280b78a61a968391b7e07e912be102a8?d=identicon&s=25 Robert Walker (robert4723)
on 2013-07-19 14:47
J. mp wrote in post #1115983:
> I want to run both test for each of the role (Merchant or FrontStore)
> but
> not repeating the test code.
>
> My question is, how best design the test so they are reusable in this
> case?

IMHO you shouldn't. Test code should be DAMP not DRY:

http://stackoverflow.com/questions/6453235/what-do...
This topic is locked and can not be replied to.