Module: RSpecLets::Helper
- Defined in:
- lib/rspec-lets/helper.rb
Instance Method Summary collapse
Instance Method Details
#help(hash) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/rspec-lets/helper.rb', line 36 def help(hash) hash.each do |var, value| define_method var do |*args| instance_exec(*args, &value) end end end |
#lets(hash) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rspec-lets/helper.rb', line 9 def lets(hash) hash.each do |keys, value| Array.wrap(keys).each_with_index do |key, index| define_method key do @assignments ||= {} if value.arity == 1 @assignments[key] ||= instance_exec(index, &value) elsif value.arity == 2 @assignments[key] ||= instance_exec(index, key, &value) else @assignments[key] ||= instance_exec(&value) end end end end end |
#lets!(hash) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/rspec-lets/helper.rb', line 26 def lets!(hash) lets(hash) hash.each do |keys, value| Array.wrap(keys).each do |key| before { __send__(key) } end end end |