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
end
end
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
end
end
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?