I'm not sure if it can be done, but I am trying to test a case where I take an array of values and use stdlib's delete to remove one value before iterating over it. The class will fail if the removed value is present. That all works fine except I am trying to write an rspec for it. Nothing I have found seems to have a way I can figure out to do this.
class my_class {
$var1 = ['a','b','c']
$var2 = delete($var1, 'b') ==> Now ['a','c']
$var2.each |$var3| {
if $var3 == 'b' {
fail("Found b")
}
}
}
I am trying to mock / stub is before testing do $var2 = ['a','b','c'] to override the calculated $var2 from the delete function.
What am I missing here?
I tried let(:vars) {{ var2: ['a','b','c'] }}, which didn't work.
Did a similar thing with a mock on
my_class.new, but the value remained as calculated by the class.
Is it even possible to stub a local variable to the class / module to force a failure condition?
Thanks!