Sha256: fd95b2200c8f3743eff0dc3a6bb288aff490bc176d126b8d4751a2ef7d264d85

Contents?: true

Size: 976 Bytes

Versions: 12

Compression:

Stored size: 976 Bytes

Contents

module RSpec::Rails::Matchers
  class BeValid < RSpec::Matchers::BuiltIn::Be
    def initialize(*args)
      @args = args
    end

    # @api private
    def matches?(actual)
      @actual = actual
      actual.valid?(*@args)
    end

    # @api private
    def failure_message_for_should
      message = "expected #{actual.inspect} to be valid"
      if actual.respond_to?(:errors)
        message << ", but got errors: #{actual.errors.full_messages.join(', ')}"
      end

      message
    end

    # @api private
    def failure_message_for_should_not
      "expected #{actual.inspect} not to be valid"
    end
  end

  # Passes if the given model instance's `valid?` method is true, meaning all
  # of the `ActiveModel::Validations` passed and no errors exist. If a message
  # is not given, a default message is shown listing each error.
  #
  # @example
  #
  #     thing = Thing.new
  #     thing.should be_valid
  def be_valid(*args)
    BeValid.new(*args)
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/rspec-rails-2.13.0/lib/rspec/rails/matchers/be_valid.rb
rspec-rails-2.99.0 lib/rspec/rails/matchers/be_valid.rb
rspec-rails-2.99.0.rc1 lib/rspec/rails/matchers/be_valid.rb
rspec-rails-2.14.2 lib/rspec/rails/matchers/be_valid.rb
rspec-rails-2.99.0.beta2 lib/rspec/rails/matchers/be_valid.rb
rspec-rails-2.14.1 lib/rspec/rails/matchers/be_valid.rb
rspec-rails-2.99.0.beta1 lib/rspec/rails/matchers/be_valid.rb
rspec-rails-2.14.0 lib/rspec/rails/matchers/be_valid.rb
rspec-rails-2.14.0.rc1 lib/rspec/rails/matchers/be_valid.rb
rspec-rails-2.13.2 lib/rspec/rails/matchers/be_valid.rb
rspec-rails-2.13.1 lib/rspec/rails/matchers/be_valid.rb
rspec-rails-2.13.0 lib/rspec/rails/matchers/be_valid.rb