我正在尝试针对已填充数据的数据库运行Cucumber测试。它基本上是我们的生产数据库的副本。
出于某种原因,我有一些测试失败,似乎是因为它无法找到数据。关于如何使这项工作以及它为什么不喜欢“预播种”数据库的任何想法?
我们的数据过于复杂,无法通过工厂/灯具重新创建。没有办法。
以下是一个例子:
Scenario: a tech logs in
Given I am on the login page
And user with id 2328 exists
When I login as "user" with password "password"
Then I should be on the dashboard page
And I should see "Logged in as: USER"
步骤:
Given /^user with id (\d+) exists$/ do |id|
Employee.exists? id
end
When /^I login as "([^\"]*)" with password "([^\"]*)"$/ do |username, password|
visit login_url
fill_in "username", with: username
fill_in "pwd", with: password
click_button "Login"
end
也许是我的步骤并且与数据库无关,但我无法理解为什么当我给它一个错误的数字时它在And user with id 2328 exists
步骤上没有失败。
我见过this,但似乎没有影响流量。
最后,这是实际的登录方法(相信我,我知道这个登录检查有多糟糕,只需检查我们对数据库的权限):
def login
if request.post?
# get database config for env
configs = ActiveRecord::Base.configurations[Rails.env]
begin
# attempt to connect to the db
plsql = plsql_connect(params[:username], params[:pwd])
# if no exception, get the employee ID and location
session[:employee_id] = plsql.hes.installer_web_pkg.get_employee_pk.to_i
session[:employee_location] = plsql.hes.installer_web_pkg.fn_get_truck_location(session[:employee_id]).to_i
# logout
plsql.logoff
# dashboard time!
redirect_to dashboard_url(session[:employee_id].to_i)
rescue Exception => err
# could not connect, fail!!
flash.now[:notice] = "Username/password not valid (or locked out of account). Try again or contact the HelpDesk."
render :action => "login"
end
end
end
每次跑步,我都会:
expected: "/dashboard",
got: "/login" (using ==) (RSpec::Expectations::ExpectationNotMetError)
./features/step_definitions/web_steps.rb:198:in `/^(?:|I )should be on (.+)$/'
features/tech_queue.feature:11:in `Then I should be on the dashboard page'