Sha256: eb96bf7ceeee6ae8ade8fb381982729dc78674aa73073bd2ff5b9ce7e9b8c419
Contents?: true
Size: 1.26 KB
Versions: 22
Compression:
Stored size: 1.26 KB
Contents
module RSpec module Rails module Matchers # @private class BeValid < RSpec::Matchers::BuiltIn::Be def initialize(*args) @args = args end def matches?(actual) @actual = actual actual.valid?(*@args) end def failure_message message = "expected #{actual.inspect} to be valid" if actual.respond_to?(:errors) errors = if actual.errors.respond_to?(:full_messages) actual.errors.full_messages else actual.errors end message << ", but got errors: #{errors.map(&:to_s).join(', ')}" end message end def failure_message_when_negated "expected #{actual.inspect} not to be valid" end end # @api public # 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 # expect(thing).to be_valid def be_valid(*args) BeValid.new(*args) end end end end
Version data entries
22 entries across 22 versions & 3 rubygems
Version | Path |
---|---|
rspec-rails-3.4.1 | lib/rspec/rails/matchers/be_valid.rb |
rspec-rails-3.4.0 | lib/rspec/rails/matchers/be_valid.rb |