Sha256: b1dbe1a61e90f2a0fe5e24e8446723bace40130a38179e49305bc933f18389dc
Contents?: true
Size: 1.94 KB
Versions: 3
Compression:
Stored size: 1.94 KB
Contents
# encoding: utf-8 require 'spec_helper' require 'attr_enumerable' describe AttrEnumerable do context :select_attr do class AttrEnumerablePerson attr_reader :name, :age def initialize(name, age) @name, @age = name, age end end class AttrEnumerablePersons attr_reader :attr_enumerable_persons include AttrEnumerable def initialize(attr_enumerable_persons = []) @attr_enumerable_persons = attr_enumerable_persons end def <<(person) @attr_enumerable_persons << attr_enumerable_persons end end cases = [ { case_no: 1, case_title: 'name case', klass: AttrEnumerablePersons.new( [ AttrEnumerablePerson.new('tanaka', 84), AttrEnumerablePerson.new('tanaka', 20), AttrEnumerablePerson.new('suzuki', 20) ] ), method: :select_name, block: proc { |v|v == 'tanaka' }, expected: ['tanaka', 'tanaka'], }, { case_no: 2, case_title: 'age case', klass: AttrEnumerablePersons.new( [ AttrEnumerablePerson.new('tanaka', 84), AttrEnumerablePerson.new('tanaka', 20), AttrEnumerablePerson.new('suzuki', 20) ] ), method: :select_age, block: proc { |v|v == 20 }, expected: [20, 20], } ] cases.each do |c| it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do begin case_before c # -- given -- # nothing ary = c[:klass] # -- when -- actual = ary.send(c[:method], &c[:block]) # -- then -- expect(actual).to match_array(c[:expected]) ensure case_after c end end def case_before(c) # implement each case before end def case_after(c) # implement each case after end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
tbpgr_utils-0.0.150 | spec/attr_enumerable/select_attr_spec.rb |
tbpgr_utils-0.0.149 | spec/attr_enumerable/select_attr_spec.rb |
tbpgr_utils-0.0.148 | spec/attr_enumerable/select_attr_spec.rb |