Skip to content

Instantly share code, notes, and snippets.

@h-lame
Forked from rlivsey/dynamic spec
Created February 2, 2010 15:29
Show Gist options
  • Save h-lame/292743 to your computer and use it in GitHub Desktop.
Save h-lame/292743 to your computer and use it in GitHub Desktop.
# something like ...
# I think this goes in specs/support/whatever.rb
def it_should_be_invalid_without(*fields)
object_name = described_class.name.underscore
fields.each do |field|
it "should fail if #{field} is missing" do
instance_variable_get("@#{object_name}").send(:"#{field}=", nil)
instance_variable_get("@#{object_name}").should_not be_valid_for_create
end
end
end
# and you use this in your specs...
it_should_be_invalid_without :title,
:first_name, :last_name,
:country_id, :address1,
:address3, :postcode,
:username, :email,
:password, :password_confirmation,
:currency_id,
:security_question_id1,
:security_question_answer1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment