English 中文(简体)
铁路、金刚、卡比巴拉、锡、波、域、次域和准域
原标题:Rails, Cucumber, Capybara, Selenium, Pow, domains, subdomains and javascript

TL:DR - 我怎样才能让黄瓜通过应用程序请求一页, 却假装请求来自“http://mysubdomain.mydomain.

好吧,这可能需要一段时间来解释, 但请忍耐我...

我是一个经验相对丰富的铁路,但只是最近才进入了完全的BDD/TDD。

黄瓜中的 Im 测试页面中有一些用于创建新嵌套天体的缩略图(非常相似于此 < a href=> http://railscasts.com/episodes/196-nested-model-form-register” rel=“nofollow” >RailsCast )。

问题在于我不仅有可变子域,我也有可变的 Domains (请相信我...)

因此,应用程序需要查询 < code> request. host 以找到 current_ domain current_subdomain ,然后才能将背景中的一切连接起来, 并且可以继续运行应用程序的右位 。

在背景步骤中使用 host! > 域名 Capybara.default_host=域名 技术,使所有测试都通过罚款。

然而,当我使用@javascript标签 来测试页面上的.js 的功能时, 我得到Firefox 的抓取焦点, 然后试图加载全部 url 。

现在还发生我正在运行 Pow, 并且让这些 URLs 连接到 dev 服务器上。 毫不奇怪, 它们并不像用户试图登录时那样工作, 它正在查看 dev DB 。 我在关闭 pow 服务器后尝试运行套房, 它只是超时了 。

当然这个标本的网络司机不应该实际访问 URL, 但只是运行应用程序本身 并假装主机是我告诉它的是什么?

我显然遗漏了一些东西——我怎么能让黄瓜在内部建立网页,但假装请求来自“http://mysubdomain.mydomain.dev”?

edit: Jason - 变量域诀窍与子域完全相同... 如果您可以查询 db 账户的 db 账户, 以 request.subdomains. first 为基础。 您可以通过 request. domain 查询一个域名。 您只需双倍检查一些东西, 如资本化等, 以尽量减少出现错误的 url 拆解东西的风险, 显然您需要确保在 db 首个域记录中存在...

- 哦,并隐藏 域名记录请求 谨慎地...

这意味着您可以使用相同的应用程序, 但使用不同的样式和着陆页等。 对客户基础广泛的 PaaS 应用程序有用 — 您可以重新命名它, 并把它作为解决某个群体问题的具体办法出售, 即使它下面的内脏是一样的 。

最佳回答

我试图做一些非常相似的事情。 我想添加一个额外的pow目录来测试, 然后使用 pow 指令来覆盖环境。 我认为这是在您的应用程序目录中的“.powenv ” 中完成的。 以下是一个快速修正的例子 :

echo export RAILS_ENV=cucumber > .powenv && touch tmp/restart.txt

但最好做一些动态的东西,这样在开始测试之前,你可以告诉 Pow env 运行什么, 当完成切换返回时, 也许甚至可以临时在不同的端口运行测试服务器。 Pow 是迄今为止我所知道的用于操作子域的唯一伟大的解决方案 。

" 强力 " : " 强力 " : " /强力 ",我现在在我的环境中工作,在我的 " 强力 " 档案中增加了以下内容: " 强力 ",支持/支持/env.rb

# Switch Pow to For Cucumber Tests
Capybara.default_driver = :selenium # Subdomain testing will only work with pow and selenium
pow_config = "#{Rails.root}/.powenv" # Dont change, this is the Config Files Location.
pow_config_stash = "#{Rails.root}/.powenv_original" # This is what the config will be stashed as during testing.

Before do

  # Set the default host
  Capybara.app_host = "http://www.resipsa.dev"

  # Stash the existing config
  File.rename(pow_config,pow_config_stash) if File.exists? pow_config

  # Write the new pow config
  f = File.new("#{Rails.root}/.powenv", "w")
  f.write "export RAILS_ENV=test"
  f.close

  # Touch tmp/restart.txt to force a restart
  FileUtils.touch "#{Rails.root}/tmp/restart.txt"

end

After do

  # Delete the temp config
  File.delete(pow_config)

  # Restore the Original Config
  File.rename(pow_config_stash,pow_config) if File.exists? pow_config_stash

  # Touch tmp/restart.txt to force a restart
  FileUtils.touch "#{Rails.root}/tmp/restart.txt"

end
问题回答

暂无回答




相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签