Sha256: 601c787718eff1d623fcd6e995bb7a576d6d4e626e3cdf4d2b4c68ddf02ab324
Contents?: true
Size: 1.44 KB
Versions: 1
Compression:
Stored size: 1.44 KB
Contents
module AktionTestRails module Matchers module FactoryGirl module Validation def have_valid_factory(factory_name) Matcher.new(factory_name) end class Matcher < AktionTest::Matchers::Base def initialize(factory_name) @factory_name = factory_name end def description "has a valid factory named :#{@factory_name}" end protected def expectation ":#{@factory_name} to be a valid factory." end def problems_for_should message = "\n" if factory_exists? if @record.errors.full_messages.any? message << "Failed Validations:\n" @record.errors.full_messages.each do |error| message << " #{error}\n" end end else message << "No factory by the name :#{@factory_name} found\n" end message.chomp end def problems_for_should_not end def perform_match! factory_exists? && factory_creates_valid_record? end def factory_exists? ::FactoryGirl.factories.registered?(@factory_name) end def factory_creates_valid_record? @record = ::FactoryGirl.build(@factory_name) @record.valid? end end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
aktion_test_rails-0.3.0 | lib/aktion_test_rails/matchers/factory_girl/validation.rb |