I am trying to learn how to use the Rspec shared partition function, and I get a warning when I run my tests:
WARNING: Shared example group 'required attributes' has been previously defined at: /Users/me/app/spec/support/shared_examples/required_attributes_spec.rb:1 ...and you are now defining it at: /Users/me/app/spec/support/shared_examples/required_attributes_spec.rb:1 The new definition will overwrite the original one. ....
I read that I think this is documentation on this issue here , but itβs hard for me to figure it out / see the takeaway for my case,
Here is my general example:
# spec/support/shared_examples/required_attributes_spec.rb shared_examples_for 'required attributes' do |arr| arr.each do |meth| it "is invalid without #{meth}" do subject.send("#{meth}=", nil) subject.valid? expect(subject.errors[meth]).to eq(["can't be blank"]) end end end
I am trying to use this in the User and Company models. Here's what it looks like:
# spec/models/user_spec.rb require 'rails_helper' describe User do subject { build(:user) } include_examples 'required attributes', [:name] end
Following the recommendations in the Rspec docs I linked to above, I tried changing the include_examples to it_behaves_like , but that didn't help. I also fully commented on company_spec.rb , so only one example used a common example, and I still get a warning.
Can someone help me see what is happening here and what should I do in this case to avoid the warning?
source share