Skip to content

Instantly share code, notes, and snippets.

@somethvictory
Created July 28, 2017 04:38
Show Gist options
  • Save somethvictory/da64b5dbc8c2f2eec4adb33df5877b39 to your computer and use it in GitHub Desktop.
Save somethvictory/da64b5dbc8c2f2eec4adb33df5877b39 to your computer and use it in GitHub Desktop.
Organise your spec by grouping them under different describe context, associations, validations, callbacks, etc...
require 'rails_helper'
RSpec.describe Url, 'Associations', type: :model do
it { is_expected.to belong_to(:user) }
it { is_expected.to have_many(:logs) }
end
RSpec.describe Url, 'Validations', type: :model do
it { is_expected.to validate_presence_of(:original_name) }
it { is_expected.to validate_uniqueness_of(:original_name) }
it { is_expected.to allow_value('http://example.com').for(:original_name) }
it { is_expected.to allow_value('https://example.com').for(:original_name) }
it { is_expected.not_to allow_value('example.com').for(:original_name) }
it { is_expected.not_to allow_value('http://example').for(:original_name) }
it { is_expected.not_to allow_value('example').for(:original_name) }
it 'sets short name before save' do
@url = FactoryGirl.build(:url, short_name: '')
@url.save
expect(@url.short_name).not_to be nil
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment