Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add more snippets and split testunit from ruby.snippets

  • Loading branch information...
commit b6d531a7e144d0bd210b3185b4f708dffc3601a9 1 parent 1ebd6e7
@kaichen authored
View
2  eruby-rails_view.snippets
@@ -43,7 +43,7 @@ snippet =jsit
snippet =sslt
<%= stylesheet_link_tag "${1:stylesheet_filename}" %>
-snippet it
+snippet imaget
<%= image_tag "${1:image_path}" %>
snippet lt
<%= link_to '${1:caption}', ${2:path} %>
View
1  ruby-factory_girl.snippets
@@ -33,3 +33,4 @@ snippet Fw
Factory(:${1:factory}, :${2})
snippet Fbw
Factory.build(:${1:factory}, :${2})
+
View
3  ruby-rails.snippets
@@ -6,7 +6,8 @@ snippet logd
logger.debug { "${1:message}" }${2}
snippet logw
logger.warn { "${1:message}" }${2}
-snippet logd
+snippet loge
logger.error { "${1:message}" }${2}
snippet logf
logger.fatal { "${1:message}" }${2}
+
View
1  ruby-rails_controller.snippets
@@ -8,3 +8,4 @@ snippet wants
wants.${1:js|json|xml|html}${2}
snippet flash
flash[:${1:notice}] = "${2}"
+
View
1  ruby-rails_model.snippets
@@ -37,3 +37,4 @@ snippet vlength
validates_length_of :${1:attribute}, ${2}
snippet vnumeric
validates_numericality_of :${1:attribute}
+
View
25 ruby-rspec.snippets
@@ -1,6 +1,8 @@
# rspec
snippet spechelper
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')${1}
+
+# describe
snippet des
describe ${1:description}" do
${2}
@@ -26,14 +28,18 @@ snippet desd
end
end
-snippet before
+
+# before & after
+snippet before-
before(:${1:each}) do
${2}
end
-snippet after
+snippet after-
after(:${1:each}) do
${2}
end
+
+# it should
snippet it
it "should ${1:description}" do
${2}
@@ -46,14 +52,6 @@ snippet itshbe
it "should ${1:description}" do
${2:model}.should be_${3}
end
-snippet atsh
- it "should ${1:description}" do
- ${2:model}.${3:attr}.should ${4}
- end
-snippet atshbe
- it "should ${1:description}" do
- ${2:model}.${3:attr}.should be_${4}
- end
# matchers
snippet sheq
@@ -61,10 +59,3 @@ snippet sheq
snippet shbe
${1:target}.should be_${2:result}
-# rspec-rails
-snippet itres
- it { response.should be_${1} }
-snippet itrend
- it { response.should render_template(:${1}) }
-snippet itred
- it { response.should redirect_to(${1}) }
View
9 ruby-rspec_rails.snippets
@@ -0,0 +1,9 @@
+# Rspec Rails
+
+snippet itres
+ it { response.should be_${1} }
+snippet itrend
+ it { response.should render_template(:${1}) }
+snippet itred
+ it { response.should redirect_to(${1}) }
+
View
58 ruby-rspec_shoulda.snippets
@@ -0,0 +1,58 @@
+# Shoulda macros for Rspec
+
+# association
+snippet itshbt shoulda macros for rspec: should_belong_to
+ it { should_belong_to :${1:association} }
+snippet itshhabtm shoulda macros for rspec: should_have_and_belong_to_many
+ it { should_have_and_belong_to_many :${1:association} }
+snippet itshhm shoulda macros for rspec: should_have_many
+ it { should_have_many :${1:association} }
+snippet itshho shoulda macros for rspec: should_have_one
+ it { should_have_one :${1:association} }
+
+# assign_to
+snippet itshat
+ it { should assign_to(:${1:model}) }
+snippet itshnat
+ it { should_not assign_to(:${1:model}) }
+snippet itshatwk
+ it { should assign_to(:${1:model}).with_kind_of(${2:klass}) }
+snippet itshatw
+ it { should assign_to(:${1:model}).with(@${2}) }
+
+# filter_param
+snippet itshfp
+ it { should filter_param(:${1:field}) }
+
+# layout
+snippet itshrwl
+ it { should render_with_layout }
+snippet itshnrwl
+ it { should_not render_with_layout }
+
+# respond
+snippet itshrepw
+ it { should respond_with(:${1:success|redirect|missing|error}) }
+snippet itshrepwc
+ it { should respond_with_content_type(:${1:xml|csv|atom|yaml|text}) }
+
+# route
+snippet itshroute
+ it { should route(:${1:method}, "/${2:path}").to(:action => :${3:action}) }
+
+# session
+snippet itshsets
+ it { should set_session(:${1:message}) }
+snippet itshsetst
+ it { should set_session(:${1:key}).to(${2:value}) }
+snippet itshnsets
+ it { should_not set_session(:${1:key}) }
+
+# flash
+snippet itshsetfl
+ it { should set_the_flash }
+snippet itshsetflt
+ it { should set_the_flash.to(/${1:message}/i) }
+snippet itshnsetfl
+ it { should_not set_the_flash }
+
View
48 ruby-rspec_shoulda_controller.snippets
@@ -0,0 +1,48 @@
+# Shoulda macros for Rspec
+
+# assign_to
+snippet itshat
+ it { should assign_to(:${1:model}) }
+snippet itshnat
+ it { should_not assign_to(:${1:model}) }
+snippet itshatwk
+ it { should assign_to(:${1:model}).with_kind_of(${2:klass}) }
+snippet itshatw
+ it { should assign_to(:${1:model}).with(@${2}) }
+
+# filter_param
+snippet itshfp
+ it { should filter_param(:${1:field}) }
+
+# layout
+snippet itshrwl
+ it { should render_with_layout }
+snippet itshnrwl
+ it { should_not render_with_layout }
+
+# respond
+snippet itshrepw
+ it { should respond_with(:${1:success|redirect|missing|error}) }
+snippet itshrepwc
+ it { should respond_with_content_type(:${1:xml|csv|atom|yaml|text}) }
+
+# route
+snippet itshroute
+ it { should route(:${1:method}, "/${2:path}").to(:action => :${3:action}) }
+
+# session
+snippet itshsets
+ it { should set_session(:${1:message}) }
+snippet itshsetst
+ it { should set_session(:${1:key}).to(${2:value}) }
+snippet itshnsets
+ it { should_not set_session(:${1:key}) }
+
+# flash
+snippet itshsetfl
+ it { should set_the_flash }
+snippet itshsetflt
+ it { should set_the_flash.to(/${1:message}/i) }
+snippet itshnsetfl
+ it { should_not set_the_flash }
+
View
12 ruby-rspec_shoulda_model.snippets
@@ -0,0 +1,12 @@
+# Shoulda macros for Rspec
+
+# association
+snippet itshbt shoulda macros for rspec: should_belong_to
+ it { should_belong_to :${1:association} }
+snippet itshhabtm shoulda macros for rspec: should_have_and_belong_to_many
+ it { should_have_and_belong_to_many :${1:association} }
+snippet itshhm shoulda macros for rspec: should_have_many
+ it { should_have_many :${1:association} }
+snippet itshho shoulda macros for rspec: should_have_one
+ it { should_have_one :${1:association} }
+
View
2  ruby-shoulda.snippets
@@ -1,7 +1,7 @@
# Shoulda
# macros
-snippet shc
+snippet shc shoulda macros should_change
should_change "${1:expression}"
snippet shcb
should_change "${1:expression}", :by => ${2:by}
View
56 ruby-testunit.snippets
@@ -0,0 +1,56 @@
+# TestUnit
+
+snippet tc
+ require \"test/unit\"
+
+ require \"${1:library_file_name}\"
+
+ class Test${2:$1} < Test::Unit::TestCase
+ def test_${3:case_name}
+ ${4}
+ end
+ end
+snippet ts
+ require \"test/unit\"
+
+ require \"tc_${1:test_case_file}\"
+ require \"tc_${2:test_case_file}\"${3}
+snippet as
+ assert(${1:test}, \"${2:Failure message.}\")${3}
+snippet ase
+ assert_equal(${1:expected}, ${2:actual})${3}
+snippet asne
+ assert_not_equal(${1:unexpected}, ${2:actual})${3}
+snippet asid
+ assert_in_delta(${1:expected_float}, ${2:actual_float}, ${3:2 ** -20})${4}
+snippet asio
+ assert_instance_of(${1:ExpectedClass}, ${2:actual_instance})${3}
+snippet asko
+ assert_kind_of(${1:ExpectedKind}, ${2:actual_instance})${3}
+snippet asn
+ assert_nil(${1:instance})${2}
+snippet asnn
+ assert_not_nil(${1:instance})${2}
+snippet asm
+ assert_match(/${1:expected_pattern}/, ${2:actual_string})${3}
+snippet asnm
+ assert_no_match(/${1:unexpected_pattern}/, ${2:actual_string})${3}
+snippet aso
+ assert_operator(${1:left}, :${2:operator}, ${3:right})${4}
+snippet asr
+ assert_raise(${1:Exception}) { ${2} }
+snippet asnr
+ assert_nothing_raised(${1:Exception}) { ${2} }
+snippet asrt
+ assert_respond_to(${1:object}, :${2:method})${3}
+snippet ass assert_same(..)
+ assert_same(${1:expected}, ${2:actual})${3}
+snippet ass assert_send(..)
+ assert_send([${1:object}, :${2:message}, ${3:args}])${4}
+snippet asns
+ assert_not_same(${1:unexpected}, ${2:actual})${3}
+snippet ast
+ assert_throws(:${1:expected}) { ${2} }
+snippet asnt
+ assert_nothing_thrown { ${1} }
+
View
367 ruby.snippets
@@ -0,0 +1,367 @@
+# #!/usr/bin/ruby
+snippet #!
+ #!/usr/bin/ruby
+
+# New Block
+snippet =b
+ =begin rdoc
+ ${1}
+ =end
+snippet y
+ :yields: ${1:arguments}
+snippet rb
+ #!/usr/bin/env ruby -wKU
+
+snippet req
+ require "${1}"${2}
+snippet #
+ # =>
+snippet end
+ __END__
+snippet case
+ case ${1:object}
+ when ${2:condition}
+ ${3}
+ end
+snippet when
+ when ${1:condition}
+ ${2}
+snippet def
+ def ${1:method_name}
+ ${2}
+ end
+snippet deft
+ def test_${1:case_name}
+ ${2}
+ end
+snippet if
+ if ${1:condition}
+ ${2}
+ end
+snippet ife
+ if ${1:condition}
+ ${2}
+ else
+ ${3}
+ end
+snippet elsif
+ elsif ${1:condition}
+ ${2}
+snippet unless
+ unless ${1:condition}
+ ${2}
+ end
+snippet while
+ while ${1:condition}
+ ${2}
+ end
+snippet until
+ until ${1:condition}
+ ${2}
+ end
+
+# Class and Module
+snippet cla class .. end
+ class ${1:`substitute(Filename(), '^.', '\u&', '')`}
+ ${2}
+ end
+snippet cla class .. initialize .. end
+ class ${1:`substitute(Filename(), '^.', '\u&', '')`}
+ def initialize(${2:args})
+ ${3}
+ end
+
+
+ end
+snippet cla class .. < ParentClass .. initialize .. end
+ class ${1:`substitute(Filename(), '^.', '\u&', '')`} < ${2:ParentClass}
+ def initialize(${3:args})
+ ${4}
+ end
+
+
+ end
+snippet cla ClassName = Struct .. do .. end
+ ${1:`substitute(Filename(), '^.', '\u&', '')`} = Struct.new(:${2:attr_names}) do
+ def ${3:method_name}
+ ${4}
+ end
+
+
+ end
+snippet cla class BlankSlate .. initialize .. end
+ class ${1:BlankSlate}
+ instance_methods.each { |meth| undef_method(meth) unless meth =~ /\A__/ }
+snippet cla class << self .. end
+ class << ${1:self}
+ ${2}
+ end
+# class .. < DelegateClass .. initialize .. end
+snippet cla-
+ class ${1:`substitute(Filename(), '^.', '\u&', '')`} < DelegateClass(${2:ParentClass})
+ def initialize(${3:args})
+ super(${4:del_obj})
+
+ ${5}
+ end
+
+
+ end
+snippet mod module .. end
+ module ${1:`substitute(Filename(), '^.', '\u&', '')`}
+ ${2}
+ end
+snippet mod module .. module_function .. end
+ module ${1:`substitute(Filename(), '^.', '\u&', '')`}
+ module_function
+
+ ${2}
+ end
+snippet mod module .. ClassMethods .. end
+ module ${1:`substitute(Filename(), '^.', '\u&', '')`}
+ module ClassMethods
+ ${2}
+ end
+
+
+# attr_reader
+snippet r
+ attr_reader :${1:attr_names}
+# attr_writer
+snippet w
+ attr_writer :${1:attr_names}
+# attr_accessor
+snippet rw
+ attr_accessor :${1:attr_names}
+
+# include Enumerable
+snippet Enum
+ include Enumerable
+
+ def each(&block)
+ ${1}
+ end
+# include Comparable
+snippet Comp
+ include Comparable
+
+ def <=>(other)
+ ${1}
+ end
+# extend Forwardable
+snippet Forw-
+ extend Forwardable
+
+# def self
+snippet defs
+ def self.${1:class_method_name}
+ ${2}
+ end
+# def method_missing
+snippet defmm
+ def method_missing(meth, *args, &blk)
+ ${1}
+ end
+snippet defd
+ def_delegator :${1:@del_obj}, :${2:del_meth}, :${3:new_name}
+snippet defds
+ def_delegators :${1:@del_obj}, :${2:del_methods}
+snippet am
+ alias_method :${1:new_name}, :${2:old_name}
+
+snippet app
+ if __FILE__ == $PROGRAM_NAME
+ ${1}
+ end
+# usage_if()
+snippet usai
+ if ARGV.${1}
+ abort \"Usage: #{$PROGRAM_NAME} ${2:ARGS_GO_HERE}\"${3}
+ end
+# usage_unless()
+snippet usau
+ unless ARGV.${1}
+ abort \"Usage: #{$PROGRAM_NAME} ${2:ARGS_GO_HERE}\"${3}
+ end
+
+snippet array
+ Array.new(${1:10}) { |${2:i}| ${3} }
+snippet hash
+ Hash.new { |${1:hash}, ${2:key}| $1[$2] = ${3} }
+snippet file File.foreach() { |line| .. }
+ File.foreach(${1:"path/to/file"}) { |${2:line}| ${3} }
+snippet file File.read()
+ File.read(${1:"path/to/file"})${2}
+snippet Dir Dir.global() { |file| .. }
+ Dir.glob(${1:"dir/glob/*"}) { |${2:file}| ${3} }
+snippet Dir Dir[''..'']
+ Dir[${1:"glob/**/*.rb"}]${2}
+snippet dir
+ Filename.dirname(__FILE__)
+snippet deli
+ delete_if { |${1:e}| ${2} }
+snippet fil
+ fill(${1:range}) { |${2:i}| ${3} }
+# flatten_once()
+snippet flao
+ inject(Array.new) { |${1:arr}, ${2:a}| $1.push(*$2)}${3}
+snippet zip
+ zip(${1:enums}) { |${2:row}| ${3} }
+# downto(0) { |n| .. }
+snippet dow
+ downto(${1:0}) { |${2:n}| ${3} }
+snippet ste
+ step(${1:2}) { |${2:n}| ${3} }
+snippet tim
+ times { |${1:n}| ${2} }
+snippet upt
+ upto(${1:1.0/0.0}) { |${2:n}| ${3} }
+snippet loo
+ loop { ${1} }
+snippet ea
+ each { |${1:e}| ${2} }
+snippet eab
+ each_byte { |${1:byte}| ${2} }
+snippet eac- each_char { |chr| .. }
+ each_char { |${1:chr}| ${2} }
+snippet eac- each_cons(..) { |group| .. }
+ each_cons(${1:2}) { |${2:group}| ${3} }
+snippet eai
+ each_index { |${1:i}| ${2} }
+snippet eak
+ each_key { |${1:key}| ${2} }
+snippet eal
+ each_line { |${1:line}| ${2} }
+snippet eap
+ each_pair { |${1:name}, ${2:val}| ${3} }
+snippet eas-
+ each_slice(${1:2}) { |${2:group}| ${3} }
+snippet eav
+ each_value { |${1:val}| ${2} }
+snippet eawi
+ each_with_index { |${1:e}, ${2:i}| ${3} }
+snippet reve
+ reverse_each { |${1:e}| ${2} }
+snippet inj
+ inject(${1:init}) { |${2:mem}, ${3:var}| ${4} }
+snippet map
+ map { |${1:e}| ${2} }
+snippet mapwi-
+ enum_with_index.map { |${1:e}, ${2:i}| ${3} }
+snippet sor
+ sort { |a, b| ${1} }
+snippet sorb
+ sort_by { |${1:e}| ${2} }
+snippet ran
+ sort_by { rand }
+snippet all
+ all? { |${1:e}| ${2} }
+snippet any
+ any? { |${1:e}| ${2} }
+snippet cl
+ classify { |${1:e}| ${2} }
+snippet col
+ collect { |${1:e}| ${2} }
+snippet det
+ detect { |${1:e}| ${2} }
+snippet fet
+ fetch(${1:name}) { |${2:key}| ${3} }
+snippet fin
+ find { |${1:e}| ${2} }
+snippet fina
+ find_all { |${1:e}| ${2} }
+snippet gre
+ grep(${1:/pattern/}) { |${2:match}| ${3} }
+snippet sub
+ ${1:g}sub(${2:/pattern/}) { |${3:match}| ${4} }
+snippet sca
+ scan(${1:/pattern/}) { |${2:match}| ${3} }
+snippet max
+ max { |a, b|, ${1} }
+snippet min
+ min { |a, b|, ${1} }
+snippet par
+ partition { |${1:e}|, ${2} }
+snippet rej
+ reject { |${1:e}|, ${2} }
+snippet sel
+ select { |${1:e}|, ${2} }
+snippet lam
+ lambda { |${1:args}| ${2} }
+snippet do
+ do |${1:variable}|
+ ${2}
+ end
+snippet :
+ :${1:key} => ${2:"value"}${3}
+snippet ope
+ open(${1:"path/or/url/or/pipe"}, "${2:w}") { |${3:io}| ${4} }
+# path_from_here()
+snippet patfh
+ File.join(File.dirname(__FILE__), *%2[${1:rel path here}])${2}
+# unix_filter {}
+snippet unif
+ ARGF.each_line${1} do |${2:line}|
+ ${3}
+ end
+# option_parse {}
+snippet optp
+ require \"optparse\"
+
+ options = {${1:default => \"args\"}}
+
+ ARGV.options do |opts|
+ opts.banner = \"Usage: #{File.basename($PROGRAM_NAME)}
+snippet opt
+ opts.on( \"-${1:o}\", \"--${2:long-option-name}\", ${3:String},
+ \"${4:Option description.}\") do |${5:opt}|
+ ${6}
+ end
+
+snippet fl
+ flunk("${1:Failure message.}")${2}
+# Benchmark.bmbm do .. end
+snippet bm-
+ TESTS = ${1:10_000}
+ Benchmark.bmbm do |results|
+ ${2}
+ end
+snippet rep
+ results.report("${1:name}:") { TESTS.times { ${2} }}
+# Marshal.dump(.., file)
+snippet Md
+ File.open(${1:"path/to/file.dump"}, "wb") { |${2:file}| Marshal.dump(${3:obj}, $2) }${4}
+# Mashal.load(obj)
+snippet Ml
+ File.open(${1:"path/to/file.dump"}, "rb") { |${2:file}| Marshal.load($2) }${3}
+# deep_copy(..)
+snippet deec
+ Marshal.load(Marshal.dump(${1:obj_to_copy}))${2}
+snippet Pn-
+ PStore.new(${1:"file_name.pstore"})${2}
+snippet tra
+ transaction(${1:true}) { ${2} }
+# xmlread(..)
+snippet xml-
+ REXML::Document.new(File.read(${1:"path/to/file"}))${2}
+# xpath(..) { .. }
+snippet xpa
+ elements.each(${1:\"//Xpath\"}) do |${2:node}|
+ ${3}
+ end
+# class_from_name()
+snippet clafn
+ split("::").inject(Object) { |par, const| par.const_get(const) }
+# singleton_class()
+snippet sinc
+ class << self; self end
+snippet nam
+ namespace :${1:`Filename()`} do
+ ${2}
+ end
+snippet tas
+ desc \"${1:Task description\}\"
+ task :${2:task_name => [:dependent, :tasks]} do
+ ${3}
+ end
+
Please sign in to comment.
Something went wrong with that request. Please try again.