我整天都在苦苦挣扎!
在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 |
| julien@gmail.com | password |
| bob@hotmail.com | password |
And I have 2 or more user records
When I go to the login_url
And I fill in "user_session_email" with "julien@gmail.com"
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 时,字段被填写,按下按钮,我被重定向到主页,就像它应该,但问题是我没有登录,也没有看到任何flash消息(应该说登录)
如果我尝试使用错误的密码登录,我会被重定向到登录页面...
我不知道这个问题来自哪里,我试图使用包括Authlogic :: TestCase 和 require“authlogic / test_case”,但没有他们正在工作。
是cookie,authlogic,factory_girl还是黄瓜问题,我真的不知道。
如果有人有想法,请随时给我留言!
干杯, 于连
答案 0 :(得分:1)
行, 找到了答案, 您必须将默认主机(设置为www.example.com)设置为您的域。
Capybara.default_host = "www.website.local"
Capybara.server_port = 3000