子域,使用黄瓜或水豚和 rspec 进行测试

发布于 2024-12-03 09:09:26 字数 903 浏览 2 评论 0原文

我的项目的部分开发已经完成。我们的 公司要求我为开发的代码编写cucumber测试用例 以及今后的发展。 路由文件有两个子域:admin 和hosts.Devise 也是 被使用。

现在我安装了黄瓜并编写了第一个场景 第一个故事,当非注册用户登陆主页时,进入 有效的电子邮件并被重定向到下一页..该页面没有 密码字段。

Scenario: Non registered user lands on beta home page. 
Given: I am on the homepage 
When: I enter valid email with "[email protected]". 
Then: I should be redirected to request invitation page. 

问题出在我的路由文件中,

constraints :subdomain => ADMIN_SUBDOMAIN do 
  .... 
  root :to => admin#index 
end 
constraints :subdomain => HOST do 
  ... 
  root :to => home#index. 
end 

现在我如何指定 path.rb 文件来查找 root_path 该特定子域。 子域约束之外没有写入 root_path。 这是我第一次进行测试。 我真的很坚持这一点。非常感谢任何帮助。

我刚刚从某人那里得知这可以使用水豚来实现。如果是这样,请您提供一些想法。

Some part of the development of my project has been done.Our
company asks me to write cucumber test cases for the developed code
and for the henceforth development as well.
The routes file have two subdomains for admin and hosts.Devise is also
being used.

Now i installed cucumber and have written the first scenario for the
first story when the non registerd user lands on the home page,enters
a valid email and gets redirected to the next page..the page has no
password field.

Scenario: Non registered user lands on beta home page. 
Given: I am on the homepage 
When: I enter valid email with "[email protected]". 
Then: I should be redirected to request invitation page. 

The problem is in my routes file, I have,

constraints :subdomain => ADMIN_SUBDOMAIN do 
  .... 
  root :to => admin#index 
end 
constraints :subdomain => HOST do 
  ... 
  root :to => home#index. 
end 

Now how do i specify the path.rb file to look for the root_path in
that specific subdomain.
Theres no root_path written outside the subdomain constraints.
This is my first time with testing.
I am really stuck onto this.Any help is deeply appreciated.

I just got to know from somebody that this can be implemented using capybara.If so ,could you please give a little idea about it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

森林散布 2024-12-10 09:09:26

事实证明这很简单。Capybara 提供了一个 default_host 方法。
所以我只需要提到,

When I visit subomain sub

然后 webstep


Given /^I visit subdomain (.*)$/ do |site_domain|

  site_domain = "http://sub.example.com" if site_domain == "admin"

  Capybara.default_host = site_domain
  visit "/"
end

Update:

default_host 不应该被使用,因为它在文档中没有提到。
相反,尝试在访问中使用绝对路径。

Given /^I visit subdomain (.*)$/ do |site_domain|

  site_domain = "http://sub.example.com" if site_domain == "admin"
  visit site_domain
end

Turned out it was pretty simple.Capybara provides a default_host method.
So I just needed to mention,

When I visit subomain sub

And then the webstep


Given /^I visit subdomain (.*)$/ do |site_domain|

  site_domain = "http://sub.example.com" if site_domain == "admin"

  Capybara.default_host = site_domain
  visit "/"
end

Update:

default_host is not supposed to be used as it is not mentioned in the docs.
Instead try using absolute path in visit.

Given /^I visit subdomain (.*)$/ do |site_domain|

  site_domain = "http://sub.example.com" if site_domain == "admin"
  visit site_domain
end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文