ruby on rails - url helpers not using host name in Capybara feature test -
in spec use asseturlhelper:
include actionview::helpers::asseturlhelper so can test page should display absolute url 1 of files. thought asset_url should trick:
asset_url(img.img_file(:medium)) unfortunately while spec runs has no host name, e.g.
(byebug) asset_url("blurg.jpg") "/images/blurg.jpg" ... not if specify host name option:
(byebug) asset_url("blurg.jpg", host: "myhost.com") "/images/blurg.jpg" at least second case odd in contradicts comment in source:
# if :host options set, overwrites global # +config.action_controller.asset_host+ setting. # # ... # # asset_url "application.js" # => http://example.com/assets/application.js # asset_url "application.js", host: "http://cdn.example.com" # => http://cdn.example.com/assets/application.js this has lead bug going unspotted until now. test thinks there no difference between relative file path view outputs (wrongly) , absolute url should there:
myhost.com/images/blurg.jpg #what expect test check /images/blurg.jpg #what test checks the contents of view not matter. know how fix it. want know case , future reference, why helper not behave expect in test, , how fix the test.
a feature spec doesn't have necessary rails framework loaded in order calculate host. i'm little surprised providing :host option doesn't work, not hugely because there's lot of smarts inside rails concerning urls referring routing, resolving lots of things, , trying smart.
if switch on controller spec, you'll find proper context stubbed enough asset_url works advertised (without :host option).
Comments
Post a Comment