Sha256: 9bad268776c62f1885764e15b5e6ed8a82a131260a5421f9309661fcfd31c773

Contents?: true

Size: 1.33 KB

Versions: 3

Compression:

Stored size: 1.33 KB

Contents

require 'active_support/core_ext/module/aliasing'
require 'rspec/matchers/have'

module RSpec::Rails::Matchers
  module HaveExtensions
    extend ActiveSupport::Concern

    # @api private
    #
    # Enhances the failure message for `should have(n)` matchers
    def failure_message_for_should_with_errors_on_extensions
      return "expected #{relativities[@relativity]}#{@expected} errors on :#{@args[0]}, got #{@actual}" if @collection_name == :errors_on
      return "expected #{relativities[@relativity]}#{@expected} error on :#{@args[0]}, got #{@actual}"  if @collection_name == :error_on
      return failure_message_for_should_without_errors_on_extensions
    end

    # @api private
    #
    # Enhances the description for `should have(n)` matchers
    def description_with_errors_on_extensions
      return "have #{relativities[@relativity]}#{@expected} errors on :#{@args[0]}" if @collection_name == :errors_on
      return "have #{relativities[@relativity]}#{@expected} error on :#{@args[0]}"  if @collection_name == :error_on
      return description_without_errors_on_extensions
    end

    included do
      alias_method_chain :failure_message_for_should, :errors_on_extensions
      alias_method_chain :description, :errors_on_extensions
    end
  end
end

RSpec::Matchers::Have.class_eval do
  include RSpec::Rails::Matchers::HaveExtensions
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rspec-rails-2.8.1 lib/rspec/rails/matchers/have_extension.rb
rspec-rails-2.8.0 lib/rspec/rails/matchers/have_extension.rb
rspec-rails-2.8.0.rc2 lib/rspec/rails/matchers/have_extension.rb