Skip to content

Commit

Permalink
adds failure_message_when_negated to have_secure_password_matcher (#1593
Browse files Browse the repository at this point in the history
)

Co-authored-by: Matheus Dutra Lima <kutomore@gmail.com>
  • Loading branch information
amalrik and Kutomore committed Dec 23, 2023
1 parent 4de31c5 commit a373661
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Expand Up @@ -47,6 +47,8 @@ class HaveSecurePasswordMatcher
did_not_authenticate_correct_password: 'expected %{subject} to'\
' authenticate the correct %{attribute}',
method_not_found: 'expected %{subject} to respond to %{methods}',
should_not_have_secure_password: 'expected %{subject} to'\
' not %{description}!',
}.freeze

def initialize(attribute)
Expand All @@ -69,6 +71,11 @@ def matches?(subject)
failure.nil?
end

def failure_message_when_negated
MESSAGES[:should_not_have_secure_password] %
{ subject: @subject.class, description: description }
end

protected

attr_reader :subject
Expand Down
Expand Up @@ -33,5 +33,18 @@
no_digest_column = define_model(:example) { has_secure_password :reset_password }
expect(no_digest_column.new).not_to have_secure_password :reset_password
end

it 'rejects with an appropriate failure message' do
working_model = define_model(:example, reset_password_digest: :string) { has_secure_password :reset_password }
assertion = lambda do
expect(working_model.new).not_to have_secure_password :reset_password
end

message = <<-MESSAGE
expected Example to not have a secure password, defined on reset_password attribute!
MESSAGE

expect(&assertion).to fail_with_message(message)
end
end
end

0 comments on commit a373661

Please sign in to comment.