Mocha expects method
Posted
by
Masha
on Stack Overflow
See other posts from Stack Overflow
or by Masha
Published on 2012-11-09T22:57:27Z
Indexed on
2012/11/09
22:59 UTC
Read the original article
Hit count: 221
So my situation is: I have a 2 modules that have the same structure like that:
module Module1
class Config
def fee_rate
2
end
end
end
So, say, Module2 would have class Config with the method fee_rate, just with a different value (those are actually implemented in a rails engine, but it shouldn't matter)
and then my model can use either Module1 or Module2 to get the fee rate value like that:
def config
@config ||= "#{module_name.titleize}::Config".constantize.new
@config
end
def get_value
config.get_fee * some_other_value
end
What I'm trying to test is if get_fee function was called on the correct class:
"#{model.module_name.titleize}::Config".constantize.any_instance.expects(:get_fee).at_least_once
model.get_value
and on the line when I call get_value I get the following error - undefined method `*' for nil:NilClass. I'm completely lost now, so I'd appreciate any help and ideas.
© Stack Overflow or respective owner