开发者

What is the best way to use Rspec to test parsing from a file?

开发者 https://www.devze.com 2023-02-20 11:16 出处:网络
Right now I am doing my testing by creating a controller for passing in the name of the file, parsing the file in the开发者_如何学Python model and adding the necessary information added as a row in my

Right now I am doing my testing by creating a controller for passing in the name of the file, parsing the file in the开发者_如何学Python model and adding the necessary information added as a row in my database, which is then displayed on a page. I am then comparing the fields on the page to what the fields should be.

But this seems messy since the controller and display page were created only for the purposes of these tests. Is there a way to just feed the file name into a method in my model, and then run the usual tests against the database info itself?


I think it would be easier to answer this if we had a code sample (of the controller and model) to see why this shouldn't be handled in the standard rspec idiom.

Without knowing about your controller or model, I can at least say this: Yes, you can do that. The basic procedure to follow is to create your test file (if you need to), feed the name/path in to the test using a standard variable (yes, most likely hard coded, though it depends on how extensive you're planning to be), then test it against your database in whatever your standard way to do such things is.

0

精彩评论

暂无评论...
验证码 换一张
取 消