Skip to content

Commit f774e02

Browse files
authored
feat(ruby): add rspec snippets (#501)
1 parent c2f5ce1 commit f774e02

File tree

2 files changed

+364
-0
lines changed

2 files changed

+364
-0
lines changed

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@
140140
"language": "rails",
141141
"path": "./snippets/frameworks/rails.json"
142142
},
143+
{
144+
"language": "rspec",
145+
"path": "./snippets/ruby/rspec.json"
146+
},
143147
{
144148
"language": "rust",
145149
"path": "./snippets/rust/rust.json"

snippets/ruby/rspec.json

Lines changed: 360 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,360 @@
1+
{
2+
"rspec_spec_skeleton": {
3+
"prefix": "rspec",
4+
"body": "# frozen_string_literal: true\n\nrequire 'spec_helper'\nrequire 'rails_helper'\n\nRSpec.describe ${1:${TM_DIRECTORY/(?:(?:\\~?\\/.*\\/)|_)([A-Za-z0-9]+)?/${1:/capitalize}/g}}::${2:${TM_FILENAME_BASE/(?:^|_)([A-Za-z0-9]+)(?:_spec)?/${1:/capitalize}/g}} do\n $0\nend\n",
5+
"description": "RSpec test skeleton"
6+
},
7+
8+
"rspec_describe": {
9+
"prefix": "des",
10+
"body": "describe '${1:}' do\n ${2:}$0\nend\n",
11+
"description": "RSpec describe case"
12+
},
13+
14+
"rspec_context": {
15+
"prefix": "con",
16+
"body": "context 'when ${1:some case}' do\n ${2:}$0\nend\n",
17+
"description": "RSpec context case"
18+
},
19+
20+
"rspec_let": {
21+
"prefix": "let",
22+
"body": "let(:${1:object}) { $0 }",
23+
"description": "Use `let` to define memoized helper method"
24+
},
25+
26+
"rspec_let!": {
27+
"prefix": "letb",
28+
"body": "let!(:${1:object}) { $0 }",
29+
"description": [
30+
"Use `let!` to define a memoized",
31+
"helper method that is called",
32+
"in a `before` hook"
33+
]
34+
},
35+
36+
"rspec_it": {
37+
"prefix": "it",
38+
"body": "it '${1:has some behaviour}' do\n ${2:}$0\nend\n",
39+
"description": "example"
40+
},
41+
42+
"rspec_pending": {
43+
"prefix": "pending",
44+
"body": "pending${1: '${2:reason}'}",
45+
"description": "pending example"
46+
},
47+
48+
"rspec_shared_example": {
49+
"prefix": "sharex",
50+
"body": "RSpec.shared_examples '${1:some example}' do ${3:|${2:parameter}|}\n ${4:$0}\nend\n",
51+
"description": "RSpec shared example declaration"
52+
},
53+
54+
"rspec_behaves_like": {
55+
"prefix": "itbl",
56+
"body": "it_behaves_like ${2:'$1'}$0",
57+
"description": "RSpec shared example usage"
58+
},
59+
60+
"rspec_expect_do": {
61+
"prefix": "expdo",
62+
"body": "expect do\n ${1:action}\nend.to ${2:matcher}$0",
63+
"description": "expect do ... end.to something"
64+
},
65+
"rspec_expect": {
66+
"prefix": "exp",
67+
"body": "expect(${1:subject}).to ${2:matcher}$0",
68+
"description": "expect(subject).to something"
69+
},
70+
71+
"rspec_expect_block": {
72+
"prefix": "expto",
73+
"body": "expect {${2: ${1:expression} }}.to ${3:matcher}",
74+
"description": "expect with block"
75+
},
76+
77+
"rspec_expect_be": {
78+
"prefix": "expbe",
79+
"body": "expect(${1:subject}).to be$0",
80+
"description": [
81+
"Scenarios:",
82+
"be matcher"
83+
]
84+
},
85+
86+
"rspec_expect_be_": {
87+
"prefix": "expbpm",
88+
"body": "expect(${1:subject}).to be_${2|truthy,falsey,nil|}$0",
89+
"description": [
90+
"Scenarios:",
91+
"be_truthy matcher",
92+
"be_falsey matcher",
93+
"be_nil matcher"
94+
]
95+
},
96+
97+
"rspec_expect_eq": {
98+
"prefix": "expeq",
99+
"body": "expect(${1:subject}).to eq(${2:value})$0",
100+
"description": [
101+
"Equality matcher",
102+
"compare using eq (==)"
103+
]
104+
},
105+
106+
"rspec_expect_eql": {
107+
"prefix": "expeql",
108+
"body": "expect(${1:subject}).to eql(${2:value})$0",
109+
"description": [
110+
"Equality matcher",
111+
"compare using eql (eql?)"
112+
]
113+
},
114+
115+
"rspec_expect_equal": {
116+
"prefix": "expequal",
117+
"body": "expect(${1:subject}).to equal(${2:value})$0",
118+
"description": [
119+
"Equality matcher",
120+
"compare using equal (equal?)"
121+
]
122+
},
123+
124+
"rspec_expect_all": {
125+
"prefix": "expall",
126+
"body": "expect(${1:enumerable}).to all( ${2:matcher} )$0",
127+
"description": [
128+
"Used to specify that a collection's",
129+
"objects all pass an expected",
130+
"matcher. This works on any",
131+
"enumerable object."
132+
]
133+
},
134+
135+
"rspec_expect_include": {
136+
"prefix": "expinclude",
137+
"body": "expect(${1:subject}).to include(${2:element})$0",
138+
"description": [
139+
"Use the include matcher to specify",
140+
"that a collection includes one or",
141+
"more expected objects.",
142+
"This works on any object that ",
143+
"responds to #include? ",
144+
"Scenarios: Array, String, Hash"
145+
]
146+
},
147+
148+
"rspec_expect_match": {
149+
"prefix": "expmatch",
150+
"body": "expect(${1:subject}).to match(/${2:regexp}/)$0",
151+
"description": [
152+
"The match matcher calls #match on",
153+
"the object, passing if #match",
154+
"returns a truthy (not false or nil)",
155+
"value.",
156+
"Scenarios: String, Regexp"
157+
]
158+
},
159+
160+
"rspec_expect_contain_exactly": {
161+
"prefix": "expcte",
162+
"body": "expect(${1:array}).to contain_exactly(${2:elements})$0",
163+
"description": [
164+
"Provides a way to test arrays",
165+
"against each other in a way that",
166+
"disregards differences in the",
167+
"ordering between the actual and",
168+
"expected array"
169+
]
170+
},
171+
172+
"rspec_expect_exist": {
173+
"prefix": "expexist",
174+
"body": "expect(${1:subject}).to exist$0",
175+
"description": [
176+
"The exist matcher is used to specify",
177+
"that something exists",
178+
"(#exist? or #exists?)"
179+
]
180+
},
181+
182+
"rspec_expect_end_with": {
183+
"prefix": "expenw",
184+
"body": "expect(${1:subject}).to end_with(${2:value})$0",
185+
"description": [
186+
"Used to specify that a string or",
187+
"array ends with the expected",
188+
"characters or elements",
189+
"Scenarios: Array, String"
190+
]
191+
},
192+
193+
"rspec_expect_start_with": {
194+
"prefix": "expstw",
195+
"body": "expect(${1:subject}).to start_with(${2:value})$0",
196+
"description": [
197+
"Used to specify that a string or",
198+
"array starts with the expected",
199+
"characters or elements",
200+
"Scenarios: Array, String"
201+
]
202+
},
203+
204+
"rspec_expect_have_attributes": {
205+
"prefix": "exphat",
206+
"body": "expect(${1:subject}).to have_attributes(${2:hash})$0",
207+
"description": [
208+
"Used to specify that an object's",
209+
"attributes match the expected",
210+
"attributes"
211+
]
212+
},
213+
214+
"rspec_expect_raise": {
215+
"prefix": "expraise",
216+
"body": "expect { ${1:action} }.to raise_error(${2:Error})$0",
217+
"description": [
218+
"Used to specify that a block of code",
219+
"raises an error.",
220+
"Scenarios",
221+
"expect any error",
222+
"expect specific error",
223+
"match message with a string",
224+
"match message with a regexp",
225+
"matching message with `with_message`",
226+
"match class + message with string",
227+
"match class + message with regexp",
228+
"set expectations on error object passed to block",
229+
"expect no error at all"
230+
]
231+
},
232+
233+
234+
"rspec_expect_satisfy": {
235+
"prefix": "expsat",
236+
"body": "expect(${1:subject}).to satisfy { |${2:obj}| ${3:expression} }$0",
237+
"description": [
238+
"The satisfy matcher is extremely",
239+
"flexible and can handle almost",
240+
"anything you want to specify.",
241+
"It passes if the block you provide",
242+
"returns true"
243+
]
244+
},
245+
246+
"rspec_expect_be_a_kind_of": {
247+
"prefix": "expbko",
248+
"body": "expect(${1:subject}).to be_a_kind_of(${2:klass})$0",
249+
"description": [
250+
"Type matcher",
251+
"Returns true if type is in obj's",
252+
"class hierarchy or is a module and",
253+
"is included in a class in obj's ",
254+
"class hierarchy."
255+
]
256+
},
257+
258+
"rspec_expect_be_an_instance_of": {
259+
"prefix": "expbio",
260+
"body": "expect(${1:subject}).to be_an_instance_of(${2:klass})$0",
261+
"description": [
262+
"Type matcher",
263+
"Returns true if and only if type if obj's class"
264+
]
265+
},
266+
267+
"rspec_expect_respond_to": {
268+
"prefix": "exprt",
269+
"body": "expect(${1:subject}).to respond_to(:${2:method})$0",
270+
"description": [
271+
"Use the respond_to matcher to",
272+
"specify details of an object's",
273+
"interface. ",
274+
"Scenarios:",
275+
"basic usage",
276+
"specify arguments",
277+
"specify arguments range",
278+
"specify unlimited arguments",
279+
"specify keywords",
280+
"specify any keywords",
281+
"specify required keywords"
282+
]
283+
},
284+
285+
"rspec_before": {
286+
"prefix": "bef",
287+
"body": "before(${1|:all,:each,:suite,:context,:example|}) do\n ${2:}$0\nend\n",
288+
"description": [
289+
"Before hook",
290+
"Runs once before all of the examples",
291+
"in a group"
292+
]
293+
},
294+
295+
"rspec_after": {
296+
"prefix": "aft",
297+
"body": "after(${1|:all,:each,:suite,:context,:example|}) do\n ${2:}$0\nend\n",
298+
"description": [
299+
"After hook",
300+
"Runs once after all of the examples",
301+
"in a group"
302+
]
303+
},
304+
305+
"rspec_around": {
306+
"prefix": "aro",
307+
"body": "around(:${1:example}) do\n ${2:}$0\nend\n",
308+
"description": [
309+
"Around hook",
310+
"Lets you define code that should be",
311+
"executed before and after the",
312+
"example",
313+
"Context hooks are NOT wrapped by",
314+
"the `around` hook"
315+
]
316+
},
317+
318+
"rspec_is_expected": {
319+
"prefix": "itie",
320+
"body": "it { is_expected.to ${1:matcher} }$0",
321+
"description": [
322+
"RSpec supports a one-liner syntax",
323+
"for setting an expectation on the",
324+
"subject"
325+
]
326+
},
327+
328+
"rspec_subject": {
329+
"prefix": "subject",
330+
"body": "subject(:${1:subject}) { ${2:} }$0",
331+
"description": [
332+
"Explicit subject",
333+
"Defines a memoized helper method"
334+
]
335+
},
336+
337+
"rspec_described_class": {
338+
"prefix": "subjectcls",
339+
"body": "subject(:${1:subject}) { ${2:${TM_DIRECTORY/(?:(?:\\~?\\/.*\\/)|_)([A-Za-z0-9]+)?/${1:/capitalize}/g}}::${3:${TM_FILENAME_BASE/(?:^|_)([A-Za-z0-9]+)(?:_spec)?/${1:/capitalize}/g}}.new }$0",
340+
"description": "subject(:subject) { described_class.new }"
341+
},
342+
343+
"rspec_allow": {
344+
"prefix": "allrec",
345+
"body": "allow(${1:collaborator}).to receive(:${2:message})${3:.with(${4:args})}${5:.and_return(${6:result})}$0",
346+
"description": "Method stub that returns values"
347+
},
348+
349+
"rspec_expect_receive": {
350+
"prefix": "exprecw",
351+
"body": "expect(${1:collaborator}).to receive(:${2:message})${3:.with(${4:args})}$0",
352+
"description": [
353+
"Expecting messages",
354+
"Use to expect a message on a test",
355+
"double. Unfulfilled message ",
356+
"expectations trigger failures when",
357+
"the example completes."
358+
]
359+
}
360+
}

0 commit comments

Comments
 (0)