Mark's Blog About Search Activity

DRYing up RSpec

Today I had the need to run the same set of tests with just one or two variable changes, specifically testing our RESTful routes with a different platform key (web, api, mobile). It didn’t feel right to make this a shared example (“it behaves like…”). I came across this blog post and found the suggestion under “Constructing RSpec examples programmatically” to be exactly what I need

describe myController, :type => :controller do
  [:api, :mobile, :web].each do |platform|

...
end
If you liked this post, you can share it with your followers or follow me on Twitter!
comments powered by Disqus