shoulda-matchers are not matching

279 Views Asked by At

I am creating a TextMessage model to manage communications. I am using shoulda-matchers' for testing

my model

class TextMessage < ApplicationRecord
  validates :message, presence: true
end

Now my test

RSpec.describe TextMessage, type: :model do
  subject { FactoryBot.create(:text_message) }
  it { is_expected.to validate_presence_of :message }
end

I am able to run FactoryBot.create(:text_message) on the console to create a text message without any problems. But when I run my test sweet I get this error

TextMessage
  is expected to validate that :message cannot be empty/falsy (FAILED - 1)

Failures:

  1) TextMessage is expected to validate that :message cannot be empty/falsy
     Failure/Error: self.message = message.gsub("\u0000", '')

     NoMethodError:
       undefined method `gsub' for nil:NilClass
0

There are 0 best solutions below