Skip to content

Instantly share code, notes, and snippets.

@karthiks
Created October 21, 2011 17:27
Show Gist options
  • Save karthiks/1304419 to your computer and use it in GitHub Desktop.
Save karthiks/1304419 to your computer and use it in GitHub Desktop.
leveraging Subject in RSpec - 4
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