Last Updated: February 25, 2016
·
814
· fs

Check the last inserted record with Cucumber

When testing complex forms interactions it may be useful checking that fields are written correctly into the db.

With ActiveRecord, create a database.yml as usual and map the classes:

require 'active_record'
require 'mysql2'

dbconfig = YAML::load(File.open('database.yml'))
ActiveRecord::Base.establish_connection(dbconfig)

class Domain < ActiveRecord::Base
end

Now you can access data and test if the field registrar has been written in the last insertion:

Then /^the last inserted domain must be valid$/ do
  registrar = Domain.last.registrar
  registrar.should_not eq(nil)
end