[rspec-users] dynamic specs

David Green justnothing at tiscali.co.uk
Fri Jun 15 07:34:27 EDT 2007


I'd like to test that my model attributes are properly protected against mass
assignment, something like:

it "should NOT update :balance on mass assignment" do
  @account.attributes = {:balance => 1000}
  @account.balance.should_not == 1000
end

instead of doing each attribute manually however, I'd like to automate it so
I can pass a list of attributes which CAN be assigned that way and let the
code figure out what should be protected. Here's what I have so far :

http://pastie.caboo.se/70685

the problem is, I can't figure out how to make "protected attributes"
reusable. I'd like to be able to pass it a different class name and list of
allowed attributes at run time, but AFAIK, shared behaviours can't be sent
parameters. I tried using instance variables, which I initialize in 'mass
assignments' before() method, but they're only available to the actual spec
(lines 6-8), not the code that generates the dynamic specs (lines 3-9)

can anyone think how I might get round this? 

thanks
dave


-- 
View this message in context: http://www.nabble.com/dynamic-specs-tf3927280.html#a11137640
Sent from the rspec-users mailing list archive at Nabble.com.



More information about the rspec-users mailing list