Rails3 +黄瓜 + Factory_girl_rails +真实逻辑问题
我一整天都在为此苦苦挣扎!
在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,
找到了答案,
您必须为您的域设置默认主机(设置为 www.example.com)。
OK,
found the answer,
you have to setup the default host (which is set to www.example.com) to your domain.