Last active
April 21, 2021 17:41
-
-
Save BLaurenB/af1494c35549f33cf26fda1efc5b5b82 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rails_helper' | |
RSpec.describe Model, type: :model do | |
describe 'Validations' do | |
it 'it is invalid without ___' do | |
expect(Model.new(some_attr: nil)).to_not be_valid | |
end | |
it 'it validates presence of some_attr' do | |
expect(Model.new(some_attr: nil)).to validate_presence_of(:some_attr) | |
end | |
end | |
xcontext "Class Methods" do | |
it "some class method here" do | |
#create some instances of Model | |
expected = "some anticipated result" | |
expect(Model.class_method()).to eq(expected) | |
end | |
end | |
xcontext "Instance Methods" do | |
it "some instance method here" do | |
instance = Model.create() #create an instance of Model | |
expected = "some anticipated result" | |
expect(instance.instance_method()).to eq(expected) | |
end | |
end | |
end | |
# Can also do it this way: | |
require 'rails_helper' | |
describe Customer do | |
describe "Validations" do | |
it {is_expected.to validate_presence_of(:first_name)} | |
it {is_expected.to validate_presence_of(:last_name)} | |
it {is_expected.to validate_presence_of(:created_at)} | |
it {is_expected.to validate_presence_of(:updated_at)} | |
end | |
describe "Relationships" do | |
it {is_expected.to have_many(:invoices)} | |
it {is_expected.to have_many(:merchants).through(:invoices)} | |
end | |
end | |
----------------- | |
(for testing anything else like a service or query...) | |
require 'rails_helper' | |
RSpec.describe MakeProjectResourcesService do | |
describe 'Methods' do | |
it 'does stuff' do | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment