Rails rspec set subdomain

后端 未结 4 1010
暗喜
暗喜 2020-12-01 04:07

I am using rSpec for testing my application. In my application controller I have a method like so:

def set_current_account
  @current_account ||= Account.fi         


        
4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-01 04:49

    • Rspec - 3.6.0
    • Capybara - 2.15.1

    Chris Peters' answer worked for me for Request specs, but for Feature specs, I had to make the following changes:

    rails_helper:

    Capybara.app_host = 'http://lvh.me'
    Capybara.always_include_port = true
    

    feature_subdomain_helpers:

    module FeatureSubdomainHelpers
        def within_subdomain(subdomain)
            before { Capybara.app_host = "http://#{subdomain}.lvh.me" }
            after  { Capybara.app_host = "http://lvh.me" }
            yield
        end
    end
    

提交回复
热议问题