ruby on rails 3 - Best way to modify factory attributes for multiple tests? -


trying test routing rspec , factories. best way modify existing factory multiple times inside spec test?

require "spec_helper"  describe gamecontroller   describe "routing"      game = factorygirl.create(:game)      "routes #show"       get("/game/1").should route_to("game#show", :id => "1")     end      "routes #show"       # need modify 1 param of factory.. how best this?       get("/game/1").should route_to("game#show", :id => "1")     end    end end 

you have 2 options. if you're modifying single param between test, might easiest like:

before(:each)   game = factorygirl.create(:game) end  "does something"   get("/game/1").should route_to("game#show", :id => "1") end  "does else"   game.update_attributes(:param => "value")   get("/game/1").should route_to("game#show", :id => "1") end 

otherwise, set factory girl sequence , fresh factorygirl.create in each spec.


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -