I have an action in my controller that loads up an instance variable with an instance of an object from an API I have no control over:
def index
@obj = MyObj.find(id: params[:id])
end
MyObj.find makes an API call and returns me what that API returns.
Now say I want to write a test for my view, but I can't use a test database since my app is dependant on that API. I can never count on the API returning me a testable object and some of the tests I want to try are dependant on the state of that object.
I would like to be able to, before rendering my view, create my own test @obj
manually and have my tests work on a view render informed by that @obj
.
Ideally it would be something like this:
before(:all) do
@obj = {attr1: "abc", attr2: 123}
driver.navigate.to("#{ENV['RAILS_HOST']}/my_view/123")
end
Which clearly doesn't work. Is there some way to do this?
Aucun commentaire:
Enregistrer un commentaire