specky/snippets/rspec.snippets
author Mahlon E. Smith <mahlon@laika.com>
Wed, 12 Sep 2012 10:45:25 -0700
branchvim-stuff
changeset 27 595320486f69
parent 19 763cef799c74
permissions -rw-r--r--
Update copyright, small comment style fix.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
     1
#
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
     2
# specky: snippet file for rspec, to be used with the quite excellent
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
     3
# 'snipmate' Vim plugin by Michael Sanders <msanders42+vim@gmail.com>.
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
     4
# http://www.vim.org/scripts/script.php?script_id=2540
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
     5
#
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
     6
# $Id$
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
     7
#
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
     8
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
     9
snippet .and and_raise()
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    10
	.and_raise( ${1:exception}.new("${2:message}") )
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    11
snippet .and and_return { }
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    12
	.and_return { ${1} }
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    13
snippet .and and_return()
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    14
	.and_return( ${1:value} )
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    15
snippet .and and_throw()
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    16
	.and_throw( ${1:sym} )
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    17
snippet .and and_yield()
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    18
	.and_yield( ${1:values} )
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    19
snippet .at at_least()
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    20
	.at_least( ${1:n} ).times
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    21
snippet .at at_most()
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    22
	.at_most( ${1:n} ).times
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    23
snippet .on
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    24
	.once
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    25
snippet .tw
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    26
	.twice
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    27
snippet .any
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    28
	.any_number_of_times
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    29
snippet des Describe subject
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    30
	describe "${1:subject}" do
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    31
		${2}
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    32
	end
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    33
snippet des Describe Type
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    34
	describe ${1:Type} do
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    35
		${2}
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    36
	end
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    37
snippet des Describe Type, description
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    38
	describe ${1:Type}, "${2:description}" do
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    39
		${3}
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    40
	end
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    41
snippet des Describe a shared group
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    42
	describe "${1:A Shared Thing}", :shared => true do
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    43
		${2}
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    44
	end
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    45
snippet it it block
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    46
	it "${1:should do something}" do
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    47
		${2}
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    48
	end
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    49
snippet it it (pending)
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    50
	it "${1:does something}"${2}
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    51
snippet .ex
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    52
	.exactly( ${1:n} ).times
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    53
snippet .w
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    54
	.with( ${1:args} )${2}
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    55
snippet con
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    56
	context "${1:context}" do
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    57
		${2}
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    58
	end
19
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    59
# this is the 'old' mock syntax (rspec 1.x)
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    60
# use 'double' for rspec 2.x
5
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    61
snippet mock
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    62
	${1:var} = mock( "${2:mock_name}"${3:, :null_object => true} )
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    63
	${4}
19
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    64
snippet dou
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    65
	${1:var} = double( "${2:double_name}" )${3:.as_null_object}
763cef799c74 Specky: support rspec 2.x by default.
Mahlon E. Smith <mahlon@martini.nu>
parents: 12
diff changeset
    66
	${4}
5
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    67
snippet st
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    68
	stub!( :${1:expectation} ).with( ${2:args} ).and_return( ${3} )
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    69
snippet bef Before each test
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    70
	before( :each ) do
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    71
		${1}
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    72
	end
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    73
snippet bef Before all tests
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    74
	before( :all ) do
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    75
		${1}
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    76
	end
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    77
snippet aft After each test
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    78
	after( :each ) do
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    79
		${1}
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    80
	end
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    81
snippet aft After all tests
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    82
	after( :all ) do
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    83
		${1}
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    84
	end
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    85
snippet sh=
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    86
	${1:target}.should == ${2:value}
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    87
	${3}
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    88
snippet shn=
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    89
	${1:target}.should_not == ${2:value}
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    90
	${3}
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    91
snippet she
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    92
	${1:target}.should equal( ${2:value} )
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    93
	${3}
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    94
snippet shne
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    95
	${1:target}.should_not equal( ${2:value} )
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    96
	${3}
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    97
snippet shm Should contain
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    98
	${1:target}.should =~ /${2:regexp}/
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
    99
	${3}
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   100
snippet shnm 
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   101
	${1:target}.should_not =~ /${2:regexp}/
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   102
	${3}
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   103
snippet shm Should match
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   104
	${1:target}.should match( /${2:regexp}/ )${3}
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   105
snippet shb
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   106
	${1:target}.should be( ${2:result} )
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   107
	${3}
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   108
snippet shnb
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   109
	${1:target}.should_not be( ${2:result} )
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   110
	${3}
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   111
snippet shbko
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   112
	${1:target}.should be_a_kind_of( ${2:klass} )
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   113
	${3}
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   114
snippet shnbko
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   115
	${1:target}.should_not be_a_kind_of( ${2:klass} )
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   116
	${3}
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   117
snippet shbio
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   118
	${1:target}.should be_instance_of( ${2:klass} )
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   119
	${3}
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   120
snippet shnbio
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   121
	${1:target}.should_not be_instance_of( ${2:klass} )
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   122
	${3}
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   123
snippet shbc
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   124
	${1:target}.should be_close( ${2:result}, ${3:tolerance} )
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   125
	${4}
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   126
snippet shnbc
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   127
	${1:target}.should_not be_close( ${2:result}, ${3:tolerance} )
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   128
	${4}
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   129
snippet shh
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   130
	${1:target}.should have( ${2:num} ).${3:things}
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   131
	${4}
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   132
snippet shhal
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   133
	${1:target}.should have_at_least( ${2:num} ).${3:things}
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   134
	${4}
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   135
snippet shham
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   136
	${1:target}.should have_at_most( ${2:num} ).${3:things}
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   137
	${4}
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   138
snippet shbp
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   139
	${1:target}.should ${2:be_${3:predicate}} ${4}
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   140
snippet shnbp
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   141
	${1:target}.should_not ${2:be_${3:predicate}} ${4}
9
0d8306685c5c Add support for 1.2.6 to, to_not, and expect keywords.
mahlon
parents: 5
diff changeset
   142
snippet exre
12
a9f1ce3766d1 raise_error -> raise_exception
Mahlon E. Smith <mahlon@martini.nu>
parents: 9
diff changeset
   143
	expect { ${1} }.to raise_exception( ${2:ErrorClass}, /${3:message match}/i )
9
0d8306685c5c Add support for 1.2.6 to, to_not, and expect keywords.
mahlon
parents: 5
diff changeset
   144
	${4}
0d8306685c5c Add support for 1.2.6 to, to_not, and expect keywords.
mahlon
parents: 5
diff changeset
   145
snippet exnre
12
a9f1ce3766d1 raise_error -> raise_exception
Mahlon E. Smith <mahlon@martini.nu>
parents: 9
diff changeset
   146
	expect { ${1} }.to_not raise_exception( ${2:ErrorClass} )
9
0d8306685c5c Add support for 1.2.6 to, to_not, and expect keywords.
mahlon
parents: 5
diff changeset
   147
	${3}
5
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   148
snippet shre
12
a9f1ce3766d1 raise_error -> raise_exception
Mahlon E. Smith <mahlon@martini.nu>
parents: 9
diff changeset
   149
	lambda { ${1} }.should raise_exception( ${2:ErrorClass}, /${3:message match}/i )
5
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   150
	${4}
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   151
snippet shnre
12
a9f1ce3766d1 raise_error -> raise_exception
Mahlon E. Smith <mahlon@martini.nu>
parents: 9
diff changeset
   152
	lambda { ${1} }.should_not raise_exception( ${2:ErrorClass} )
5
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   153
	${3}
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   154
snippet shr
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   155
	${1:mock}.should_receive( :${2:message} )${3}
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   156
snippet shnr
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   157
	${1:mock}.should_not_receive( :${2:message} )${3}
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   158
snippet shrt
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   159
	${1:target}.should respond_to( :${2:sym} )
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   160
snippet shnrt
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   161
	${1:target}.should_not respond_to( :${2:sym} )
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   162
snippet shbl
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   163
	it_should_behave_like "${1:shared behavior}"
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   164
	${2}
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   165
snippet sim
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   166
	def ${1:matcher_method}( expected )
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   167
		simple_matcher do |given, matcher|
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   168
			matcher.description = "${2:verb} with #{expected.inspect}"
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   169
			matcher.failure_message = "expected #{given.inspect} to $2 with #{expected.inspect}"
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   170
			matcher.negative_failure_message = "expected #{given.inspect} not to $2 with #{expected.inspect}"
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   171
			given.${3:...checks something and returns a boolean}
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   172
		end
3346aa8d5364 Add snippets and rspec syntax highlights.
mahlon
parents:
diff changeset
   173
	end