ruby on rails - Model spec is failing due to order of declarations -
ruby on rails - Model spec is failing due to order of declarations -
i'm running ruby 2.0.0 & rails 4.0.2
i have model looks like:
class activity < activerecord::base has_many :beneficiaries, -> {includes([:beneficiary_type, :gender])} def number_of_beneficiaries(gender, type) number = 0 beneficiaries.each |b| number = b.quantity if b.gender.name == gender && b.beneficiary_type.name == type end number end end
the spec model fails looks like:
require 'spec_helper' describe activity "return number of beneficiaries gender , type" beneficiary_1 = beneficiary.new(:quantity => 15, :gender => gender.find_by_name('hombres'), :beneficiary_type => beneficiarytype.find_by_name('adultos')) beneficiary_2 = beneficiary.new(:quantity => 10, :gender => gender.find_by_name('mujeres'), :beneficiary_type => beneficiarytype.find_by_name('niƱos')) activity = activity.new activity.beneficiaries << beneficiary_1 activity.beneficiaries << beneficiary_2 expect(activity.number_of_beneficiaries('hombres', 'adultos')).to eq 15 end end
that gives me.
1) activity homecoming number of beneficiaries gender , type failure/error: expect(activity.number_of_beneficiaries('hombres', 'adultos')).to eq 15
expected: 15 got: 10 (compared using ==) # ./spec/models/activity_spec.rb:30:in `block (2 levels) in <top (required)>'
the weird part if invert order in assign beneficiaries passes test.
if test expected number of beneficiaries, correctly answers 2.
ruby-on-rails ruby methods rspec rspec-rails
Comments
Post a Comment