出于某种原因,我有一些测试失败,这似乎是因为它找不到数据。有什么办法让这个工作,为什么它不喜欢“预种子”数据库?
我们的数据太复杂,无法通过工厂/固定装置重新创建。只是没办法。
下面是一个例子:
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'