Whatever snarky comment you may have about the name, the seat61 website is just about the best resource on the web for European rail travel.
You can't really travel "at will" in Spain, all long distance and even some regional trains are reservation compulsory added to that the service on many lines can be very sparse
first option is the RENFE pass, not really a pass, just a pre-selected number of journeys that can be booked as you please through their website.
Travel by train in Spain with great discounts. Do you want to know more about the Renfe Spain Pass?
www.renfe.com
option two is interrail, valid on RENFE and most local trains, global or one country versions, some trains can now be booked through the interrail website although this can be prone to outages.
Or you can just book singles for long distance and use local tickets/passes for cities/commuter (Cercanías) networks, some of which stretch quite long distances (on distinctly urban stock).