Verify database records in functional testing
Function testing, in a certain way, is verifying the data (retrieved or stored at the database) through the user interface layer. Sometimes, it might be easier to verify database records directly, some SQL skills are required though. RWebSpec provides an easy way to do so, in a easy 3 steps. # Connect to the database # Choose the table # Use easy syntax or SQL to do verification
story "Check Mysql database" do connect_to_database mysql_db(:host : "localhost", :database : "lavabuild_local", :user : "root", :password : ""), true load_table("projects") # now can use Project.xxx for easy-to-user datbase query on this table Project.count.should == 1 # record count Project.first.name.should == "BuildMonitor" Project.last.name.should == "BuildMonitor" Project.exists?(:name : "BuildMonitor") endCheck out the _verify_database_spec.rb_ in demo project.