Skip to content

Instantly share code, notes, and snippets.

@h-lame
Forked from rlivsey/dynamic spec
Created February 2, 2010 15:29

Revisions

  1. h-lame revised this gist Feb 2, 2010. 1 changed file with 26 additions and 14 deletions.
    40 changes: 26 additions & 14 deletions dynamic spec
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,26 @@
    [ :title,
    :first_name, :last_name,
    :country_id, :address1,
    :address3, :postcode,
    :username, :email,
    :password, :password_confirmation,
    :currency_id,
    :security_question_id1,
    :security_question_answer1].each do |field|
    it "should fail if #{field} is missing" do
    @account.send(:"#{field}=", nil)
    @account.should_not be_valid_for_create
    end
    end

    # 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

  2. @rlivsey rlivsey created this gist Feb 2, 2010.
    14 changes: 14 additions & 0 deletions dynamic spec
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    [ :title,
    :first_name, :last_name,
    :country_id, :address1,
    :address3, :postcode,
    :username, :email,
    :password, :password_confirmation,
    :currency_id,
    :security_question_id1,
    :security_question_answer1].each do |field|
    it "should fail if #{field} is missing" do
    @account.send(:"#{field}=", nil)
    @account.should_not be_valid_for_create
    end
    end
    Empty file added gistfile2.txt
    Empty file.