<commit_before>require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))

require 'factory_girl/syntax/generate'

describe "a factory using generate syntax" do
  before do
    Factory.define :user do |factory|
      factory.first_name 'Bill'
      factory.last_name  'Nye'
      factory.email      '<EMAIL>'
    end
  end

  after do
    Factory.factories.clear
  end

  it "should not raise an error when generating an invalid instance" do
    lambda { User.generate(:first_name => nil) }.should_not raise_error
  end

  it "should raise an error when forcefully generating an invalid instance" do
    lambda { User.generate!(:first_name => nil) }.should raise_error(ActiveRecord::RecordInvalid)
  end

  %w(generate generate! spawn).each do |method|
    it "should yield a generated instance when using #{method} with a block" do
      instance = nil
      User.send(method) {|instance| }
      instance.should be_kind_of(User)
    end

    describe "after generating an instance using #{method}" do
      before do
        @instance = User.send(method, :last_name => 'Rye')
      end

      it "should use attributes from the factory" do
        @instance.first_name.should == 'Bill'
      end

      it "should use attributes passed to generate" do<commit_msg>Plugging a leaky block scoped variable that Ruby 1.9 was more strict about<commit_after>require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))

require 'factory_girl/syntax/generate'

describe "a factory using generate syntax" do
  before do
    Factory.define :user do |factory|
      factory.first_name 'Bill'
      factory.last_name  'Nye'
      factory.email      '<EMAIL>'
    end
  end

  after do
    Factory.factories.clear
  end

  it "should not raise an error when generating an invalid instance" do
    lambda { User.generate(:first_name => nil) }.should_not raise_error
  end

  it "should raise an error when forcefully generating an invalid instance" do
    lambda { User.generate!(:first_name => nil) }.should raise_error(ActiveRecord::RecordInvalid)
  end

  %w(generate generate! spawn).each do |method|
    it "should yield a generated instance when using #{method} with a block" do
      saved_instance = nil
      User.send(method) {|instance| saved_instance = instance }
      saved_instance.should be_kind_of(User)
    end

    describe "after generating an instance using #{method}" do
      before do
        @instance = User.send(method, :last_name => 'Rye')
      end

      it "should use attributes from the factory" do
        @instance.first_name.should == 'Bill'
      end

      it "should use attributes passed to generate" do
{'fraction_non_alphanumeric': 0.09385474860335195, 'fraction_numerical': 0.0007448789571694599, 'mean_word_length': 3.2567353407290014, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5819217', 'n_tokens_mistral': 779, 'n_tokens_neox': 760, 'n_words': 263}