Sha256: 7da44bc709fa7dc8ee91f426cd96271adb9e220324bcc60a5278ab083300809a

Contents?: true

Size: 1.13 KB

Versions: 14

Compression:

Stored size: 1.13 KB

Contents

require 'spec_helper'
require 'acceptance/acceptance_helper'

require 'factory_girl/syntax/sham'

describe "a factory using sham syntax" do
  before do
    define_model('User', :first_name => :string,
                         :last_name  => :string,
                         :email      => :string,
                         :username   => :string)

    Sham.name        { "Name" }
    Sham.email       { "somebody#{rand(5)}@example.com" }
    Sham.username("FOO") { |c| "User-#{c}" }

    FactoryGirl.define do
      factory :user do
        first_name { Sham.name }
        last_name  { Sham.name }
        email      { Sham.email }
        username   { Sham.username }
      end
    end
  end

  describe "after making an instance" do
    before do
      @instance = FactoryGirl.create(:user, :last_name => 'Rye')
    end

    it "should support a sham called 'name'" do
      @instance.first_name.should == 'Name'
    end

    it "should support shams with starting values" do
      @instance.username.should == 'User-FOO'
    end

    it "should use the sham for the email" do
      @instance.email.should =~ /somebody\d@example.com/
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
factory_girl-2.0.4 spec/acceptance/syntax/sham_spec.rb
factory_girl-2.0.3 spec/acceptance/syntax/sham_spec.rb
factory_girl-2.0.2 spec/acceptance/syntax/sham_spec.rb
factory_girl-2.0.1 spec/acceptance/syntax/sham_spec.rb
factory_girl-2.0.0.rc4 spec/acceptance/syntax/sham_spec.rb
factory_girl-2.0.0.rc3 spec/acceptance/syntax/sham_spec.rb
factory_girl-2.0.0.rc2 spec/acceptance/syntax/sham_spec.rb
factory_girl-2.0.0.rc1 spec/acceptance/syntax/sham_spec.rb
factory_girl-2.0.0.beta5 spec/acceptance/syntax/sham_spec.rb
factory_girl-2.0.0.beta4 spec/acceptance/syntax/sham_spec.rb
factory_girl-2.0.0.beta3 spec/acceptance/syntax/sham_spec.rb
factory_girl_kibiz0r-2.0.0.beta3 spec/acceptance/syntax/sham_spec.rb
factory_girl_kibiz0r-2.0.0.beta2 spec/acceptance/syntax/sham_spec.rb
factory_girl-2.0.0.beta2 spec/acceptance/syntax/sham_spec.rb