Rails3 +黄瓜 + Factory_girl_rails +真实逻辑问题

发布于 2024-10-26 19:48:20 字数 1897 浏览 1 评论 0原文

我一整天都在为此苦苦挣扎!

在 GemFile 中,我有:

group :test do
    gem 'database_cleaner'
    gem 'cucumber-rails'
    gem 'cucumber'
    gem 'rspec-rails'
    gem 'spork'
    gem 'launchy'
    gem 'capybara' 
    gem 'factory_girl_rails'
end

在我的 login.feature 中,我有:

Feature: Login on my web site
  In order manage my account details
  As a security enthusiast
  I want to be able, to login and logout and view the superadmin button only when authorized

  Scenario: Check if login is working
    Given the following user records
      | email            | password |
      | [email protected] | password |
      | [email protected]  | password |
    And I have 2 or more user records
    When I go to the login_url
    And I fill in "user_session_email" with "[email protected]"
    And I fill in "user_session_password" with "password"
    And I press "Login"
    Then show me the page
    Then I should see "Logged in."

最后在我的 logins_steps.rb 文件中:

Given /^the following user records$/ do |table|
  table.hashes.each do |hash|
    u = Factory(:user, hash)
  end
end

当我手动操作时,一切都运行良好,但是当我运行 rake cucumber 时,字段已填写,按钮被按下,我被重定向到主页,就像它应该的那样,但问题是我没有登录,也没有看到任何闪存消息(应该说已登录)

如果我尝试使用错误的密码登录,我确实被重定向到登录页面...

我不知道这个问题从何而来,我尝试使用 include Authlogic::TestCase需要“authlogic/test_case”,但它们都不起作用。

是cookie、authlogic、factory_girl还是cucumber的问题,我真的不知道。

如果大家有什么想法,欢迎给我留言!

干杯, 朱利安

I've been struggling with this all day long!

In the GemFile, I have:

group :test do
    gem 'database_cleaner'
    gem 'cucumber-rails'
    gem 'cucumber'
    gem 'rspec-rails'
    gem 'spork'
    gem 'launchy'
    gem 'capybara' 
    gem 'factory_girl_rails'
end

In my login.feature I have:

Feature: Login on my web site
  In order manage my account details
  As a security enthusiast
  I want to be able, to login and logout and view the superadmin button only when authorized

  Scenario: Check if login is working
    Given the following user records
      | email            | password |
      | [email protected] | password |
      | [email protected]  | password |
    And I have 2 or more user records
    When I go to the login_url
    And I fill in "user_session_email" with "[email protected]"
    And I fill in "user_session_password" with "password"
    And I press "Login"
    Then show me the page
    Then I should see "Logged in."

And Finally in my logins_steps.rb file:

Given /^the following user records$/ do |table|
  table.hashes.each do |hash|
    u = Factory(:user, hash)
  end
end

Everything is working well when I do it by hand, but when I run rake cucumber, The fields are filled out, the button is pressed and I'm redirected to the home page like it should, but the problem is that I'm not logged in, nor do I see any flash message (it should say logged in)

If I try to login with a wrong password, I do get redirected to the login page ...

I have no idea where this issue comes from, I've tried to play around with the include Authlogic::TestCase and require "authlogic/test_case" but none of them are working.

Is it a cookie, authlogic, factory_girl or cucumber issue, I really have no clue.

If any one has an idea, please feel free to leave me a message!

Cheers,
Julien

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

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

发布评论

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

评论(1

月朦胧 2024-11-02 19:48:20

好的,
找到了答案,
您必须为您的域设置默认主机(设置为 www.example.com)。

Capybara.default_host = "www.website.local"
Capybara.server_port = 3000

OK,
found the answer,
you have to setup the default host (which is set to www.example.com) to your domain.

Capybara.default_host = "www.website.local"
Capybara.server_port = 3000
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文