Shoulda: How would I use an instance variable outside of a setup or should block?
Posted
by TheDeeno
on Stack Overflow
See other posts from Stack Overflow
or by TheDeeno
Published on 2010-04-20T01:10:15Z
Indexed on
2010/04/20
1:13 UTC
Read the original article
Hit count: 408
I'm trying to do something like the following:
@special_attributes = Model.new.methods.select # a special subset
@special_attributes.each do |attribute|
context "A model with #{attribute}"
setup do
@model = Model.new
end
should "have some special characteristic"
assert @model.method(attribute).call
end
end
end
However, @special_attributes is out of scope when running the unit tests, leaving me with a nil object on line 2. I can't figure out where to define it to bring it in scope. Any thoughts?
© Stack Overflow or respective owner