Forum: Ruby on Rails Reusing functional tests with rails 4

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...
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.