Undefined method '+' for rspec. What does it mean?

I click on the wall because I'm terribly confused about what this rspec error message means. I am testing if there is a value to a work of art. Here are snippets of my rspec:

let(:valid_art_piece){ { date_of_creation: DateTime.parse('2012-3-13'), 
placement_date_of_sale: DateTime.parse('2014-8-13'), cost: 250, medium: 'sculpture', 
availability: true } }

it 'requires a cost' do
  art_piece = ArtPiece.new(valid_art_piece.merge(cost: ''))
  expect(art_piece).to_not be_valid
  expect(art_piece.errors[:cost].to include "can't be blank")
end

error message:

1) ArtPiece requires a cost
 Failure/Error: expect(art_piece.errors[:cost].to include "can't be blank")
 NoMethodError:
   undefined method `+' for #<RSpec::Matchers::BuiltIn::Include:0x000001050f4cd0>
 # ./spec/models/artist_piece_spec.rb:30:in `block (2 levels) in <top (required)>'

As far as I know, this should not have failed, and I do not know why his failure. My schema.rb has the field as null false, and my model validates it using the numeric: true parameter.

class ArtPiece < ActiveRecord::Base
  validates_presence_of :date_of_creation
  validates_presence_of :placement_date_of_sale
  validates :cost, numericality: true
  validates_presence_of :medium
  validates_presence_of :availability
end

I do not know what the problem is. Some help?

+4
source share
1 answer

This is a syntax error. You missed the brackets before .toand before "can't be blank":

This line should look like this:

(art_piece.errors [: cost] ). ( " " )

, include, match_array

it 'requires a cost' do
  art_piece = ArtPiece.new(valid_art_piece.merge(cost: ''))
  expect(art_piece).to_not be_valid
  expect(art_piece.errors[:cost]).to match_array (["can't be blank"])
end

PS: .

:

context "art_piece" do
  subject { ArtPiece.new(valid_art_piece.merge(cost: '')) }

  it 'should_not be valid' do
     expect(subject).to_not be_valid
  end

  it 'requires a cost' do
    expect(subject.errors[:cost]).to match_array (["can't be blank"])
  end
end

, :)

+3

Source: https://habr.com/ru/post/1535201/


All Articles