spec/models/question_spec.rb in spree-faq-2.1.0 vs spec/models/question_spec.rb in spree-faq-2.1.1

- old
+ new

@@ -1,53 +1,52 @@ -require 'spec_helper' +RSpec.describe Spree::Question, type: :model do -describe Spree::Question do - let!(:question_category) { create(:question_category) } let(:question) { create(:question, question_category_id: question_category.id) } subject { question } - context 'factory' do - it 'is valid' do - expect(build(:question)).to be_valid - end + it 'factory is valid' do + expect(build(:question)).to be_valid end context 'instance attributes' do - it 'create a new instance given valid attributes' do + it 'creates a new instance given valid attributes' do described_class.create!(question: 'Question 1', answer: 'Answer 1', question_category: create(:question_category)) end end context 'relation' do - it { should belong_to(:question_category) } + it { is_expected.to belong_to(:question_category) } - it 'belong to a category' do + it 'belongs to a category' do expect(subject.question_category).not_to be_nil end end context 'validation' do - it { should validate_presence_of(:question_category_id) } - it { should validate_presence_of(:question) } - it { should validate_presence_of(:answer) } + it { is_expected.to validate_presence_of(:question_category_id) } + it { is_expected.to validate_presence_of(:question) } + it { is_expected.to validate_presence_of(:answer) } - it 'require a category' do + it 'requires a category' do invalid_question = build(:question, question_category: nil) - expect(invalid_question).to have(1).error_on(:question_category_id) + expect(invalid_question.valid?).to be_falsey + expect(invalid_question.errors[:question_category_id].size).to be(1) end - it 'require a question' do + it 'requires a question' do invalid_question = build(:question, question: nil) - expect(invalid_question).to have(1).error_on(:question) + expect(invalid_question.valid?).to be_falsey + expect(invalid_question.errors[:question].size).to be(1) end - it 'require a answer' do + it 'requires a answer' do invalid_question = build(:question, answer: nil) - expect(invalid_question).to have(1).error_on(:answer) + expect(invalid_question.valid?).to be_falsey + expect(invalid_question.errors[:answer].size).to be(1) end end context 'acts as list' do