Created
October 21, 2011 17:27
-
-
Save karthiks/1304419 to your computer and use it in GitHub Desktop.
leveraging Subject in RSpec - 4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe Address do | |
describe "#validations" do | |
#The line below can be omited if we were to not use Factory and use Address.new and innermost 'describe' block is Address implicitly. | |
subject { Factory.build :address } | |
%w(:city :state :country).each do |attr| | |
it "must have a #{attr}" do | |
subject.send("#{attr}=",nil) | |
should_not be_valid #should is called on a subject by default. Thus this line uses implicit subject :address marked above | |
subject.errors.on(attr).should_not be_nil | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment