Skip to content

Instantly share code, notes, and snippets.

@Epigene
Last active December 10, 2019 08:06
Show Gist options
  • Save Epigene/ed576c629aae697929bc1a968f979106 to your computer and use it in GitHub Desktop.
Save Epigene/ed576c629aae697929bc1a968f979106 to your computer and use it in GitHub Desktop.
Gene's snippets for VSC, 2019-12-10
{
"service_spec template": {
"prefix": "service_spec",
"body": [
"RSpec.describe $0TODO, :service do",
" let(:options) do",
" {}",
" end",
"",
" describe \"#call\", :implicit_subject do",
" it \"returns TODO\" do",
" expect(0).to eq(1)",
" end",
" end",
"end",
]
},
"scope spec template": {
"prefix": "scope_spec",
"body": [
"describe \".SCOPE_NAME\" do",
" subject(:collection) { described_class.unscoped.SCOPE_NAME }",
"",
" context \"when instantiating actual records\", :slow do",
" let!(:match) { create(:FACTORY, :TRAIT) }",
" let!(:counter) { create(:FACTORY) }",
"",
" it \"collects TODO records\" do",
" expect(collection.pluck(:id)).to contain_exactly(match.id)",
" end",
" end",
"",
" context \"when only verifying scope's SQL\" do",
" subject { super().to_sql.squish }",
"",
" let(:sql) do",
" \"TODO SQL\"",
" end"
"",
" it { is_expected.to include(sql) } ",
" end",
"end"
],
},
"instance_name": {
"prefix": ":in",
"body": [
"instance_name: :"
],
},
"params: params": {
"prefix": "pp",
"body": [
"params: params"
],
},
"let(:service)": {
"prefix": "ls",
"body": [
"let(:service)"
],
},
"headers: headers": {
"prefix": "hh",
"body": [
"headers: headers"
],
},
"line disable/enable": {
"prefix": "copper",
"body": [
"# rubocop:disable Metrics/LineLength",
"# rubocop:enable Metrics/LineLength"
],
},
"implicit subject": {
"prefix": ":is",
"body": [
":implicit_subject"
],
},
"return unless ": {
"prefix": "ru",
"body": [
"return unless "
],
},
"private_class_method": {
"prefix": "pcm",
"body": [
"private_class_method "
],
},
"stub branch config": {
"prefix": "sbc",
"body": [
"stub_branch_config(branch: $0, country: $0)"
],
},
"unscoped app access": {
"prefix": "aul",
"body": [
"Application.unscoped.last"
],
},
"factory association line": {
"prefix": "assoc",
"body": [
"association(",
" :author,",
" factory: :user, :content_creator, first_name: \"Lev\",",
" strategy: :build # custom strategy",
")
],
},
"aggregate failure it block": {
"prefix": "agg",
"body": [
"it \"has these $0\", :aggregate_failures do",
"",
"end",
],
},
"BEN block": {
"prefix": "ben",
"body": [
"BEN.new(",
" exception: exception, custom_params: {test: true}",
").call"
],
},
"debug driver line": {
"prefix": "cho",
"body": [
"driver: :chrome",
],
},
"spring rspec line": {
"prefix": "sr",
"body": [
"# spring rspec $0",
],
},
"service let": {
"prefix": "se",
"body": [
"let(:service)",
],
},
"frozen string literal pragma": {
"prefix": "frozen",
"body": [
"# frozen_string_literal: true",
],
},
"transient block": {
"prefix": "tt",
"body": [
"transient do",
"",
"end",
],
},
"described class": {
"prefix": "dc",
"body": [
"described_class"
],
},
"described instance": {
"prefix": "di",
"body": [
"described_instance"
],
},
"cache block": {
"prefix": "cache",
"body": [
"Rails.cache.fetch(:some_key, expires_in: 24.hours) do",
" $0code_that_produces_the_value_if_it_is_absent",
"end"
],
},
"memoization using defined?": {
"prefix": "memo",
"body": [
"return @?? if defined?(@??)",
"$0"
],
},
"DB transaction block": {
"prefix": "t_b",
"body": [
"ActiveRecord::Base.transaction do",
"$0",
"end"
],
},
"begin-rescue block": {
"prefix": "begin",
"body": [
"begin",
" $0",
"rescue",
" ",
"end"
],
},
"after block": {
"prefix": "after",
"body": [
"after do",
" $0",
"end"
],
},
"before block": {
"prefix": "before",
"body": [
"before do",
" $0",
"end"
],
},
"before oneliner block": {
"prefix": "before_",
"body": [
"before { $0 }",
],
},
"scope definition": {
"prefix": "sco",
"body": [
"scope :named, -> (argument) { where(attribute: argument) }"
],
},
"sequence line": {
"prefix": "sequence",
"body": [
"sequence(:email, 1) { |n| \"person\#{n}@example.com\" }"
],
},
"instance_double": {
"prefix": "id",
"body": [
"instance_double(",
" \"$0\", method: nil",
")"
],
},
"describe block": {
"prefix": "desc",
"body": [
"describe \"#$0\" do",
" subject(:) { }",
" ",
" context \"when \" do",
" ",
" it \"returns TODO\" do",
" expect(0).to eq(1)",
" end",
" end",
"end"
],
},
"context block": {
"prefix": "cont",
"body": [
"context \"when $0\" do",
" it \" \" do",
" expect(0).to eq(1)",
" end",
"end"
],
},
"it block": {
"prefix": "it",
"body": [
"xit \"returns TODO$0\" do",
" expect(0).to eq(1)",
"end"
],
},
"controller render expectation lines": {
"prefix": "ecr",
"body": [
"expect(controller).to receive(:render).with(",
"$0",
").once"
],
},
"is_expected it block": {
"prefix": "it_",
"body": [
"it { is_expected.to eq($0) }",
],
},
"expect block": {
"prefix": "ex", "expect",
"body": [
"expect($0).to match(1)"
],
},
"expect receive block": {
"prefix": "exrec",
"body": [
"expect(0).to(",
" receive(:).with().and_return()",
")"
],
},
"let": {
"prefix": "let",
"body": [
"let(:$0) do",
" ",
"end"
],
},
"let!": {
"prefix": "let!",
"body": [
"let!(:$0) do",
" ",
"end"
],
},
"curly let": {
"prefix": "let_",
"body": [
"let(:$0) { }",
],
},
"curly let!": {
"prefix": "let!_",
"body": [
"let!(:$0) { }",
],
},
"FactoryBot create": {
"prefix": "Fac",
"body": [
"create(:$0)"
],
},
"FactoryBot build_stubbed": {
"prefix": "bs",
"body": [
"build_stubbed(:$0)"
],
},
"change block": {
"prefix": "change",
"body": [
"change{ $0 }.from().to()"
],
},
"contain_exactly": {
"prefix": "ce",
"body": [
"contain_exactly($0)"
],
},
"change block, full": {
"prefix": "exchange",
"body": [
"expect{ }.to(",
" change{ $1 }.from().to()",
")"
],
},
"gsub": {
"prefix": "gsub",
"body": [
"gsub(%r'$0', '')"
],
},
"each": {
"prefix": "each",
"body": [
"each do |$0|",
" ",
"end"
],
},
"within": {
"prefix": "within",
"body": [
"within(\"$0\") do",
" ",
"end"
],
},
"do": {
"prefix": "do",
"body": [
"do |$0|",
" ",
"end"
],
},
"delegate": {
"prefix": "delegate",
"body": [
"delegate :gifts, to: :friend, allow_nil: true, prefix: false"
],
},
"trait block": {
"prefix": "trait",
"body": [
"trait :$0 do",
" ",
"end"
],
},
"short trait block": {
"prefix": "trait_",
"body": [
"trait(:$0) {}"
],
},
"timecop block": {
"prefix": "cop",
"body": [
"Timecop.freeze(\"2018-01-10 12:00\") do",
" $0",
"end"
],
},
"time lock block": {
"prefix": "lock",
"body": [
"before { Timecop.freeze(\"2018-08-15 12:00\") }",
"after { Timecop.return }"
],
},
"included block": {
"prefix": "included",
"body": [
"included do",
" $0",
"end"
],
},
"allow block": {
"prefix": "allow",
"body": [
"allow($0).to receive(:).and_return()"
],
},
"receive block": {
"prefix": "rec", "receive",
"body": [
"receive(:$0).with().once.and_return()"
],
},
"error spec block": {
"prefix": "err",
"body": [
"expect{}.to raise_error(",
" RuntimeError, %r'message'",
")"
],
},
"works without errors spec": {
"prefix": "wwe",
"body": [
"it \"works without errors\" do",
" expect_call.to_not raise_error",
"end"
],
},
"enum block": {
"prefix": "enum",
"body": [
"enum some_type: {first: 0, second: 1}",
],
},
"retryable block": {
"prefix": "retry",
"body": [
"var = nil",
"Retryable.retryable(tries: 3, on: [ArgumentError, TimeoutError]) do",
" var = Model.where().first_or_create!",
"end"
],
},
"method types block": {
"prefix": "mtypes",
"body": [
"#== Class Getters ==",
"#== Class Changers ==",
"#== Instance Getters ==",
"#== Instance Changers =="
],
},
"controller subject": {
"prefix": "mr",
"body": [
"subject(:make_request) { get :some_action, params: params }",
],
},
"general subject": {
"prefix": "sj",
"body": [
"subject(:$0) { }",
],
},
"before all setup and teardown": {
"prefix": "ball",
"body": [
"before(:all) do",
"",
"end",
"",
"after(:all) { DatabaseCleaner.clean_with(:truncation) }",
],
},
"any instance mock": {
"prefix": "any_in_of",
"body": [
"allow_any_instance_of().to(",
" receive().and_return()",
")"
],
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment