ruby on rails 3 - How to DRY (these) RSpec tests using custom matcher -
ruby on rails 3 - How to DRY (these) RSpec tests using custom matcher -
i have next tests, candidates little dry treatment:
describe league context 'attributes validation' before(:each) @league = league.new end 'should invalid without short_name' @league.attributes = valid_league_attributes.except(:short_name) @league.should_not be_valid @league.should have(1).error_on(:short_name) @league.errors[:short_name].should == ["can't blank"] @league.short_name = 'nfl' @league.should be_valid end 'should invalid without long_name' @league.attributes = valid_league_attributes.except(:long_name) @league.should_not be_valid @league.should have(2).error_on(:long_name) @league.errors[:long_name].should == ["can't blank", 'is not included in list'] @league.long_name = 'national football game league' @league.should be_valid end end end
is possible create more dry using custom matchers or other utility?
it possible, wouldn't recommend it. these 2 tests sufficiently different writing method wrap them introduces more complexity seems justified, , create troubleshooting harder if 1 of 2 tests should ever fail.
ruby-on-rails-3 refactoring rspec2 dry
Comments
Post a Comment