Sha256: a9db38d6f36f9ca2a2c104b5c154093a81a1fc0b0a1771f43c2dc79f383f2c5f

Contents?: true

Size: 1.09 KB

Versions: 3

Compression:

Stored size: 1.09 KB

Contents

module ElabsMatchers
  module Matchers
    module Rspec
      module Orm
        ##
        #
        # Asserts if an assigned value persistes in the database.
        #
        # @param [Symbol] attribute name      The name of the attibute to check if it persisted or not
        # @param [Object] value               The value to persist to the attribute
        #
        # Example:
        # post.should persist(:title, "Blog post")

        RSpec::Matchers.define :persist do |attribute, value|
          match do |actual|
            actual.send(:"#{attribute}=", value)
            actual.save!
            actual = actual.class.find(actual.id)
            @final_value = actual.send(attribute)
            @final_value == value
          end
          failure_message_for_should { |actual| "Expected #{attribute} to be persisted and retain its value of #{value.inspect} but the value was #{@final_value.inspect}" }
          failure_message_for_should_not { |actual| "Expected #{attribute} not to be persisted and retain its value of #{value.inspect} but it did." }
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
elabs_matchers-0.0.3 lib/elabs_matchers/matchers/rspec/orm.rb
elabs_matchers-0.0.2 lib/elabs_matchers/matchers/rspec/orm.rb
elabs_matchers-0.0.1 lib/elabs_matchers/matchers/rspec/orm.rb