Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Model
- expect(@user).to have_attributes(name: "Jim")
- expect(@user).to respond_to(:name)
- expect(@user.valid?).to be_truthy
- # hash
- expect(@user.attributes).to include(:a, :b)
- # erorrs
- book.errors.add(:name, :blank, message: "cannot be nil")
- expect(book.errors.blank?).to be_falsy
- expect(book.errors.full_messages).to eq(["Name cannot be nil"])
- # spec/decorators
- let(:delegated_book) { FactoryBot.build_stubbed(:book).decorate }
- # should a matchers
- gem 'shoulda-matchers', '~> 3.1'
- # add to rails_helper.rb
- require 'shoulda/matchers'
- Shoulda::Matchers.configure do |config|
- config.integrate do |with|
- with.test_framework :rspec
- with.library :rails
- end
- end
- it { is_expected.to validate_presence_of(:code_name) }
- it { is_expected.to validate_numericality_of(:length_min) }
- it { is_expected.to allow_value('111').for(:length_max) }
- it { is_expected.to_not allow_value("1111").for(:length_min) }
Add Comment
Please, Sign In to add comment