Testing Rails Controllers and Middleware- Functional vs. Integration testing? -
background
i have legacy rails 3.2 app i'm converting homegrown testing solution rails 1 (currently minitest). app json api single endpoint, testing simple @ point. build (relatively complex) json payload , make assertions against response.
what i've done far
the old testing solution fire http requests on wire (using http gem) @ separately-running instance of server. ran through entire stack, including middleware stack, hitting actiondispatch::paramsparser makes params hash available controllers.
i converted tests subclasses of actioncontroller::testcase single rails instance (the test instance) running. removed http gem use actioncontroller::testcase#post method send json payload. that's things fell apart
the problem
it seems rails integration tests exercise middleware stack, while functional tests more unit tests controller. thus, behind actioncontroller::testcase#post #paramify_values method, looks it's mocking out params hash logic that's like logic in paramsparser has differences. importantly, when try send float in params hash, gets converted string. paramsparser correctly put float in params. bunch of math in controller, math doesn't work when you're getting passed (incorrectly) string, instead of number.
my question(s)
- is there way run
actioncontroller::testcaserails middleware stack handling things? - am using wrong tool, , should instead using
actiondispatch::integrationtest? examples on rails guidesactiondispatch::integrationtestthey're made user workflows, more akin cucumber/capybara scripts firing single requests.
continuing dive rails source, it's clear using functional test wrong thing here. integration tests should using if middleware stack important.
i believe this rails bug touches on same sort of issues i'm encountering, has gone stale, don't know resolution there there might be. , has been resolved rails 5, not rails 4.
Comments
Post a Comment