开发者

Using Cucumber with a Static database

开发者 https://www.devze.com 2023-01-26 03:40 出处:网络
I am trying to run Cucumber tests against a database that is already populated with data. It\'s basically a copy of our production database.

I am trying to run Cucumber tests against a database that is already populated with data. It's basically a copy of our production database.

For some reason I have some tests failing which seemingly is coming from the fact that it can't find the data. Any idea on how to make this work and why it wouldn't like "pre-seeded" databases?

Our data is far too complex to try to recreate via factories/fixtures. There's just no way.

Here's an example:

Scenario: a tech logs in                                       开发者_JS百科                                      
  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" 

The step:

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

Maybe its my steps and has nothing to do with the database, but I can't understand why it doesn't fail on the And user with id 2328 exists step when I give it a bad number.

I have seen this but it doesn't seem to affect the flow.

Lastly, here is the actual login method (believe me, I know how awful this login check is, simply checking we have permissions to the database):

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

Every time I run, I get:

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'
0

精彩评论

暂无评论...
验证码 换一张
取 消