我有一个Cucumber场景,其中包含以下步骤:
context
这是这些操作的测试日志:
def create_admin
@admin ||= FactoryGirl.create(:admin)
end
def sign_in
visit '/admins/sign_in'
fill_in "Email", with: @admin.email
fill_in "Password", with: @admin.password
save_and_open_page
click_button "Sign in"
end
### Given ###
Given /^I exist as an admin$/ do
create_admin
end
### WHEN ###
When /^I sign in with valid credentials$/ do
sign_in
end
### THEN ###
Then /^I see a Sign out link$/ do
page.should have_link "Sign out"
end
我完全感到困惑的是,点击登录按钮似乎会触发GET请求。 由于这在开发中正常工作:
Started GET "/admins/sign_in" for 127.0.0.1 at 2017-08-23 11:10:14 +0200
Processing by Devise::SessionsController#new as HTML
Rendering devise/sessions/new.html.erb within layouts/application
Rendered devise/shared/_links.html.erb (1.0ms)
Rendered devise/sessions/new.html.erb within layouts/application (130.1ms)
Completed 200 OK in 361ms (Views: 348.5ms | ActiveRecord: 0.0ms)
Started GET "/admins/sign_in?admin[email]=admin%40ca.coml&admin[password]=[FILTERED]&admin[remember_me]=0&commit=Sign+in" for 127.0.0.1 at 2017-08-23 11:10:14 +0200
Processing by Devise::SessionsController#new as HTML
Parameters: {"admin"=>{"email"=>"admin@ca.com", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Sign in"}
Rendering devise/sessions/new.html.erb within layouts/application
Rendered devise/shared/_links.html.erb (0.3ms)
Rendered devise/sessions/new.html.erb within layouts/application (3.2ms)
Completed 200 OK in 10ms (Views: 6.6ms | ActiveRecord: 0.0ms)
我哪里出错了?
答案 0 :(得分:0)
我猜测你正在使用' rack_test'驱动程序(而不是运行实际浏览器的JS驱动程序之一),并且要么没有“capybara / rails”。它告诉' rack_test'驱动程序查找data-method
属性并使用它来设置POST与GET,或者您的表单被编写为需要JS。
如果这两种情况都不是,请发布表单的HTML