Railsでsubdomain指定時のcucumberテスト方法
routes.rbで以下の用に設定している時、
namespace :api, path: '', constraints: { subdomain: 'api' } do end
features/support/paths.rbに以下のように定義して。
def hosted_domain(options = {}) path = options[:path] || '/' subdomain = options[:subdomain] || 'api' url = "http://#{subdomain}.localhost" + path url end
step_definitionsでurl指定時にhosted_domainを用いる用にすればOK
When(/^access$/) do |path| url = hosted_domain path: path request url, {method: :get} end