Sha256: 2ae82a7ec6c7d1d9675cc5ca20adcfb79072d34b5442509d44b4e25e331343ca

Contents?: true

Size: 1.64 KB

Versions: 2

Compression:

Stored size: 1.64 KB

Contents

require 'spec_helper'

describe AktionTestRails::Matchers::FactoryGirl::ValidFactoryMatcher do
  let(:matcher_class) { AktionTestRails::Matchers::FactoryGirl::ValidFactoryMatcher }

  after(:each) do
    FactoryGirl.factories.clear
  end

  it "accepts a valid factory" do
    define_model :user, :name => :string
    FactoryGirl.define do
      factory :user do
        name "Name"
      end
    end

    User.new.should have_a_valid_factory(:user)
  end

  context "when the factory does not exist" do
    before(:each) { define_model :user }

    it "does not accept the factory" do
      User.new.should_not have_a_valid_factory(:user)
    end

    it "says that the factory does not exist" do
      matcher = matcher_class.new(:user).tap{|m| m.matches?(User.new)}
      expected_message = <<-ERROR
Expected :user to be a valid factory.
  No factory by the name :user found
      ERROR
      matcher.failure_message.should == expected_message.strip
    end
  end

  context 'when the factory has validation errors' do
    before(:each) do
      define_model :user, :name => :string do
        validates_presence_of :name
      end
      FactoryGirl.define do
        factory :user do
          name nil
        end
      end
    end

    it "does not accept the factory" do
      User.new.should_not have_a_valid_factory(:user)
    end

    it "should detail validation errors with the factory" do
      matcher = matcher_class.new(:user).tap{|m| m.matches?(User.new)}
      expected_message = <<-ERROR
Expected :user to be a valid factory.
  Failed Validations:
    Name can't be blank
      ERROR
      matcher.failure_message.should == expected_message.strip
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
aktion_test_rails-0.1.1 spec/matchers/factory_girl/have_a_valid_factory_spec.rb
aktion_test_rails-0.1.0 spec/matchers/factory_girl/have_a_valid_factory_spec.rb