Guest User

Untitled

a guest
Jan 20th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. # Model
  2. expect(@user).to have_attributes(name: "Jim")
  3. expect(@user).to respond_to(:name)
  4. expect(@user.valid?).to be_truthy
  5.  
  6. # hash
  7. expect(@user.attributes).to include(:a, :b)
  8.  
  9. # erorrs
  10. book.errors.add(:name, :blank, message: "cannot be nil")
  11. expect(book.errors.blank?).to be_falsy
  12. expect(book.errors.full_messages).to eq(["Name cannot be nil"])
  13.  
  14. # spec/decorators
  15. let(:delegated_book) { FactoryBot.build_stubbed(:book).decorate }
  16.  
  17.  
  18. # should a matchers
  19. gem 'shoulda-matchers', '~> 3.1'
  20. # add to rails_helper.rb
  21. require 'shoulda/matchers'
  22.  
  23. Shoulda::Matchers.configure do |config|
  24. config.integrate do |with|
  25. with.test_framework :rspec
  26. with.library :rails
  27. end
  28. end
  29.  
  30. it { is_expected.to validate_presence_of(:code_name) }
  31. it { is_expected.to validate_numericality_of(:length_min) }
  32. it { is_expected.to allow_value('111').for(:length_max) }
  33. it { is_expected.to_not allow_value("1111").for(:length_min) }
Add Comment
Please, Sign In to add comment