Sha256: 1e733c206e5bdcac8f33aaf100b18e9818e3fc7aec81e15d8953368436f20693

Contents?: true

Size: 1.37 KB

Versions: 28

Compression:

Stored size: 1.37 KB

Contents

require 'spec_helper'

describe FactoryGirl::Callback do
  it "has a name" do
    FactoryGirl::Callback.new(:after_create, lambda {}).name.should == :after_create
  end

  it "converts strings to symbols" do
    FactoryGirl::Callback.new("after_create", lambda {}).name.should == :after_create
  end

  it "runs its block with no parameters" do
    ran_with = nil
    FactoryGirl::Callback.new(:after_create, lambda { ran_with = [] }).run(:one, :two)
    ran_with.should == []
  end

  it "runs its block with one parameter" do
    ran_with = nil
    FactoryGirl::Callback.new(:after_create, lambda { |one| ran_with = [one] }).run(:one, :two)
    ran_with.should == [:one]
  end

  it "runs its block with two parameters" do
    ran_with = nil
    FactoryGirl::Callback.new(:after_create, lambda { |one, two| ran_with = [one, two] }).run(:one, :two)
    ran_with.should == [:one, :two]
  end

  it "allows valid callback names to be assigned" do
    FactoryGirl::Callback::VALID_NAMES.each do |callback_name|
      expect { FactoryGirl::Callback.new(callback_name, lambda {}) }.
        to_not raise_error(FactoryGirl::InvalidCallbackNameError)
    end
  end

  it "raises if an invalid callback name is assigned" do
    expect { FactoryGirl::Callback.new(:magic_fairies, lambda {}) }.
      to raise_error(FactoryGirl::InvalidCallbackNameError, /magic_fairies is not a valid callback name/)
  end
end

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
challah-0.6.1 vendor/bundle/gems/factory_girl-2.5.1/spec/factory_girl/callback_spec.rb
challah-0.6.0 vendor/bundle/gems/factory_girl-2.5.1/spec/factory_girl/callback_spec.rb
challah-0.5.4 vendor/bundle/gems/factory_girl-2.5.1/spec/factory_girl/callback_spec.rb
challah-0.5.3 vendor/bundle/gems/factory_girl-2.5.1/spec/factory_girl/callback_spec.rb
challah-0.5.2 vendor/bundle/gems/factory_girl-2.5.1/spec/factory_girl/callback_spec.rb
challah-0.5.0 vendor/bundle/gems/factory_girl-2.5.1/spec/factory_girl/callback_spec.rb
factory_girl-2.6.0 spec/factory_girl/callback_spec.rb
factory_girl-2.5.2 spec/factory_girl/callback_spec.rb
challah-0.4.1 vendor/bundle/gems/factory_girl-2.5.1/spec/factory_girl/callback_spec.rb
challah-0.4.0 vendor/bundle/gems/factory_girl-2.5.1/spec/factory_girl/callback_spec.rb
challah-0.3.5 vendor/bundle/gems/factory_girl-2.5.1/spec/factory_girl/callback_spec.rb
challah-0.3.4 vendor/bundle/gems/factory_girl-2.5.1/spec/factory_girl/callback_spec.rb
challah-0.3.3 vendor/bundle/gems/factory_girl-2.5.1/spec/factory_girl/callback_spec.rb
challah-0.3.2 vendor/bundle/gems/factory_girl-2.5.1/spec/factory_girl/callback_spec.rb
challah-0.3.1 vendor/bundle/gems/factory_girl-2.5.1/spec/factory_girl/callback_spec.rb
factory_girl-2.5.1 spec/factory_girl/callback_spec.rb
challah-0.3.0 vendor/bundle/gems/factory_girl-2.5.0/spec/factory_girl/callback_spec.rb
challah-0.2.1 vendor/bundle/gems/factory_girl-2.5.0/spec/factory_girl/callback_spec.rb
challah-0.2.0 vendor/bundle/gems/factory_girl-2.5.0/spec/factory_girl/callback_spec.rb
factory_girl-2.5.0 spec/factory_girl/callback_spec.rb